blob: 89f75cd2ed012f8db9a55fe81879499e30e07858 [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
425} // std
426
427*/
428
429#include <__config>
430#include <iosfwd>
431#include <cstring>
Howard Hinnantadff4892010-05-24 17:49:41 +0000432#include <cstdio> // For EOF.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000433#include <cwchar>
434#include <algorithm>
435#include <iterator>
436#include <utility>
437#include <memory>
438#include <stdexcept>
439#include <type_traits>
440#include <initializer_list>
441#include <__functional_base>
442#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
443#include <cstdint>
444#endif
445#if defined(_LIBCPP_NO_EXCEPTIONS) || defined(_LIBCPP_DEBUG)
446#include <cassert>
447#endif
448
Howard Hinnant66c6f972011-11-29 16:45:27 +0000449#include <__undef_min_max>
450
Howard Hinnant08e17472011-10-17 20:05:10 +0000451#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000452#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000453#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000454
455_LIBCPP_BEGIN_NAMESPACE_STD
456
457// fpos
458
459template <class _StateT>
Howard Hinnant83eade62013-03-06 23:30:19 +0000460class _LIBCPP_TYPE_VIS fpos
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000461{
462private:
463 _StateT __st_;
464 streamoff __off_;
465public:
466 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
467
468 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
469
470 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
471 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
472
473 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
474 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
475 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
476 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
477};
478
479template <class _StateT>
480inline _LIBCPP_INLINE_VISIBILITY
481streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
482 {return streamoff(__x) - streamoff(__y);}
483
484template <class _StateT>
485inline _LIBCPP_INLINE_VISIBILITY
486bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
487 {return streamoff(__x) == streamoff(__y);}
488
489template <class _StateT>
490inline _LIBCPP_INLINE_VISIBILITY
491bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
492 {return streamoff(__x) != streamoff(__y);}
493
494// char_traits
495
496template <class _CharT>
Howard Hinnant83eade62013-03-06 23:30:19 +0000497struct _LIBCPP_TYPE_VIS char_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000498{
499 typedef _CharT char_type;
500 typedef int int_type;
501 typedef streamoff off_type;
502 typedef streampos pos_type;
503 typedef mbstate_t state_type;
504
Howard Hinnanta6119a82011-05-29 19:57:12 +0000505 _LIBCPP_INLINE_VISIBILITY
506 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
507 {__c1 = __c2;}
508 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000509 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000510 {return __c1 == __c2;}
511 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000512 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000513 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000514
515 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
516 static size_t length(const char_type* __s);
517 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
518 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
519 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
520 static char_type* assign(char_type* __s, size_t __n, char_type __a);
521
Howard Hinnant03d71812012-07-20 19:09:12 +0000522 _LIBCPP_INLINE_VISIBILITY
523 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000524 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000525 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000526 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000527 {return char_type(__c);}
528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000529 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000530 {return int_type(__c);}
531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000532 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000533 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000534 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000535 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000536 {return int_type(EOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000537};
538
539template <class _CharT>
540int
541char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
542{
543 for (; __n; --__n, ++__s1, ++__s2)
544 {
545 if (lt(*__s1, *__s2))
546 return -1;
547 if (lt(*__s2, *__s1))
548 return 1;
549 }
550 return 0;
551}
552
553template <class _CharT>
554inline _LIBCPP_INLINE_VISIBILITY
555size_t
556char_traits<_CharT>::length(const char_type* __s)
557{
558 size_t __len = 0;
559 for (; !eq(*__s, char_type(0)); ++__s)
560 ++__len;
561 return __len;
562}
563
564template <class _CharT>
565inline _LIBCPP_INLINE_VISIBILITY
566const _CharT*
567char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a)
568{
569 for (; __n; --__n)
570 {
571 if (eq(*__s, __a))
572 return __s;
573 ++__s;
574 }
575 return 0;
576}
577
578template <class _CharT>
579_CharT*
580char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n)
581{
582 char_type* __r = __s1;
583 if (__s1 < __s2)
584 {
585 for (; __n; --__n, ++__s1, ++__s2)
586 assign(*__s1, *__s2);
587 }
588 else if (__s2 < __s1)
589 {
590 __s1 += __n;
591 __s2 += __n;
592 for (; __n; --__n)
593 assign(*--__s1, *--__s2);
594 }
595 return __r;
596}
597
598template <class _CharT>
599inline _LIBCPP_INLINE_VISIBILITY
600_CharT*
601char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
602{
603 char_type* __r = __s1;
604 for (; __n; --__n, ++__s1, ++__s2)
605 assign(*__s1, *__s2);
606 return __r;
607}
608
609template <class _CharT>
610inline _LIBCPP_INLINE_VISIBILITY
611_CharT*
612char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
613{
614 char_type* __r = __s;
615 for (; __n; --__n, ++__s)
616 assign(*__s, __a);
617 return __r;
618}
619
620// char_traits<char>
621
622template <>
Howard Hinnant83eade62013-03-06 23:30:19 +0000623struct _LIBCPP_TYPE_VIS char_traits<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000624{
625 typedef char char_type;
626 typedef int int_type;
627 typedef streamoff off_type;
628 typedef streampos pos_type;
629 typedef mbstate_t state_type;
630
Howard Hinnanta6119a82011-05-29 19:57:12 +0000631 _LIBCPP_INLINE_VISIBILITY
632 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
633 {__c1 = __c2;}
634 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000635 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000636 {return __c1 == __c2;}
637 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000638 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000639 {return (unsigned char)__c1 < (unsigned char)__c2;}
640
Howard Hinnanta6119a82011-05-29 19:57:12 +0000641 _LIBCPP_INLINE_VISIBILITY
642 static int compare(const char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000643 {return memcmp(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000644 _LIBCPP_INLINE_VISIBILITY
645 static size_t length(const char_type* __s) {return strlen(__s);}
646 _LIBCPP_INLINE_VISIBILITY
647 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000648 {return (const char_type*)memchr(__s, to_int_type(__a), __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000649 _LIBCPP_INLINE_VISIBILITY
650 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000651 {return (char_type*)memmove(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000652 _LIBCPP_INLINE_VISIBILITY
653 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000654 {return (char_type*)memcpy(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000655 _LIBCPP_INLINE_VISIBILITY
656 static char_type* assign(char_type* __s, size_t __n, char_type __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000657 {return (char_type*)memset(__s, to_int_type(__a), __n);}
658
Howard Hinnant03d71812012-07-20 19:09:12 +0000659 _LIBCPP_INLINE_VISIBILITY
660 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000661 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000662 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000663 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000664 {return char_type(__c);}
665 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000666 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000667 {return int_type((unsigned char)__c);}
668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000669 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000670 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000671 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000672 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000673 {return int_type(EOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000674};
675
676// char_traits<wchar_t>
677
678template <>
Howard Hinnant83eade62013-03-06 23:30:19 +0000679struct _LIBCPP_TYPE_VIS char_traits<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000680{
681 typedef wchar_t char_type;
682 typedef wint_t int_type;
683 typedef streamoff off_type;
684 typedef streampos pos_type;
685 typedef mbstate_t state_type;
686
Howard Hinnanta6119a82011-05-29 19:57:12 +0000687 _LIBCPP_INLINE_VISIBILITY
688 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
689 {__c1 = __c2;}
690 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000691 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000692 {return __c1 == __c2;}
693 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000694 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000695 {return __c1 < __c2;}
696
Howard Hinnanta6119a82011-05-29 19:57:12 +0000697 _LIBCPP_INLINE_VISIBILITY
698 static int compare(const char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000699 {return wmemcmp(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000700 _LIBCPP_INLINE_VISIBILITY
701 static size_t length(const char_type* __s)
702 {return wcslen(__s);}
703 _LIBCPP_INLINE_VISIBILITY
704 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000705 {return (const char_type*)wmemchr(__s, __a, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000706 _LIBCPP_INLINE_VISIBILITY
707 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000708 {return (char_type*)wmemmove(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000709 _LIBCPP_INLINE_VISIBILITY
710 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000711 {return (char_type*)wmemcpy(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000712 _LIBCPP_INLINE_VISIBILITY
713 static char_type* assign(char_type* __s, size_t __n, char_type __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000714 {return (char_type*)wmemset(__s, __a, __n);}
715
Howard Hinnanta6119a82011-05-29 19:57:12 +0000716 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000717 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000718 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000719 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000720 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000721 {return char_type(__c);}
722 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000723 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000724 {return int_type(__c);}
725 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000726 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000727 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000728 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000729 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000730 {return int_type(WEOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000731};
732
733#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
734
735template <>
Howard Hinnant83eade62013-03-06 23:30:19 +0000736struct _LIBCPP_TYPE_VIS char_traits<char16_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000737{
738 typedef char16_t char_type;
739 typedef uint_least16_t int_type;
740 typedef streamoff off_type;
741 typedef u16streampos pos_type;
742 typedef mbstate_t state_type;
743
Howard Hinnanta6119a82011-05-29 19:57:12 +0000744 _LIBCPP_INLINE_VISIBILITY
745 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
746 {__c1 = __c2;}
747 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000748 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000749 {return __c1 == __c2;}
750 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000751 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000752 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000753
754 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
755 static size_t length(const char_type* __s);
756 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
757 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
758 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
759 static char_type* assign(char_type* __s, size_t __n, char_type __a);
760
Howard Hinnanta6119a82011-05-29 19:57:12 +0000761 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000762 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000763 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000764 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000765 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000766 {return char_type(__c);}
767 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000768 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000769 {return int_type(__c);}
770 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000771 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000772 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000773 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000774 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000775 {return int_type(0xDFFF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000776};
777
778inline _LIBCPP_INLINE_VISIBILITY
779int
780char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
781{
782 for (; __n; --__n, ++__s1, ++__s2)
783 {
784 if (lt(*__s1, *__s2))
785 return -1;
786 if (lt(*__s2, *__s1))
787 return 1;
788 }
789 return 0;
790}
791
792inline _LIBCPP_INLINE_VISIBILITY
793size_t
794char_traits<char16_t>::length(const char_type* __s)
795{
796 size_t __len = 0;
797 for (; !eq(*__s, char_type(0)); ++__s)
798 ++__len;
799 return __len;
800}
801
802inline _LIBCPP_INLINE_VISIBILITY
803const char16_t*
804char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a)
805{
806 for (; __n; --__n)
807 {
808 if (eq(*__s, __a))
809 return __s;
810 ++__s;
811 }
812 return 0;
813}
814
815inline _LIBCPP_INLINE_VISIBILITY
816char16_t*
817char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
818{
819 char_type* __r = __s1;
820 if (__s1 < __s2)
821 {
822 for (; __n; --__n, ++__s1, ++__s2)
823 assign(*__s1, *__s2);
824 }
825 else if (__s2 < __s1)
826 {
827 __s1 += __n;
828 __s2 += __n;
829 for (; __n; --__n)
830 assign(*--__s1, *--__s2);
831 }
832 return __r;
833}
834
835inline _LIBCPP_INLINE_VISIBILITY
836char16_t*
837char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
838{
839 char_type* __r = __s1;
840 for (; __n; --__n, ++__s1, ++__s2)
841 assign(*__s1, *__s2);
842 return __r;
843}
844
845inline _LIBCPP_INLINE_VISIBILITY
846char16_t*
847char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a)
848{
849 char_type* __r = __s;
850 for (; __n; --__n, ++__s)
851 assign(*__s, __a);
852 return __r;
853}
854
855template <>
Howard Hinnant83eade62013-03-06 23:30:19 +0000856struct _LIBCPP_TYPE_VIS char_traits<char32_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000857{
858 typedef char32_t char_type;
859 typedef uint_least32_t int_type;
860 typedef streamoff off_type;
861 typedef u32streampos pos_type;
862 typedef mbstate_t state_type;
863
Howard Hinnanta6119a82011-05-29 19:57:12 +0000864 _LIBCPP_INLINE_VISIBILITY
865 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
866 {__c1 = __c2;}
867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000868 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000869 {return __c1 == __c2;}
870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000871 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000872 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000873
874 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
875 static size_t length(const char_type* __s);
876 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
877 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
878 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
879 static char_type* assign(char_type* __s, size_t __n, char_type __a);
880
Howard Hinnanta6119a82011-05-29 19:57:12 +0000881 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000882 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000883 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000884 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000885 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000886 {return char_type(__c);}
887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000888 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000889 {return int_type(__c);}
890 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000891 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000892 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000893 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000894 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000895 {return int_type(0xFFFFFFFF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000896};
897
898inline _LIBCPP_INLINE_VISIBILITY
899int
900char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
901{
902 for (; __n; --__n, ++__s1, ++__s2)
903 {
904 if (lt(*__s1, *__s2))
905 return -1;
906 if (lt(*__s2, *__s1))
907 return 1;
908 }
909 return 0;
910}
911
912inline _LIBCPP_INLINE_VISIBILITY
913size_t
914char_traits<char32_t>::length(const char_type* __s)
915{
916 size_t __len = 0;
917 for (; !eq(*__s, char_type(0)); ++__s)
918 ++__len;
919 return __len;
920}
921
922inline _LIBCPP_INLINE_VISIBILITY
923const char32_t*
924char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a)
925{
926 for (; __n; --__n)
927 {
928 if (eq(*__s, __a))
929 return __s;
930 ++__s;
931 }
932 return 0;
933}
934
935inline _LIBCPP_INLINE_VISIBILITY
936char32_t*
937char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
938{
939 char_type* __r = __s1;
940 if (__s1 < __s2)
941 {
942 for (; __n; --__n, ++__s1, ++__s2)
943 assign(*__s1, *__s2);
944 }
945 else if (__s2 < __s1)
946 {
947 __s1 += __n;
948 __s2 += __n;
949 for (; __n; --__n)
950 assign(*--__s1, *--__s2);
951 }
952 return __r;
953}
954
955inline _LIBCPP_INLINE_VISIBILITY
956char32_t*
957char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
958{
959 char_type* __r = __s1;
960 for (; __n; --__n, ++__s1, ++__s2)
961 assign(*__s1, *__s2);
962 return __r;
963}
964
965inline _LIBCPP_INLINE_VISIBILITY
966char32_t*
967char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a)
968{
969 char_type* __r = __s;
970 for (; __n; --__n, ++__s)
971 assign(*__s, __a);
972 return __r;
973}
974
Howard Hinnant324bb032010-08-22 00:02:43 +0000975#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000976
977// basic_string
978
979template<class _CharT, class _Traits, class _Allocator>
980basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000981operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
982 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000983
984template<class _CharT, class _Traits, class _Allocator>
985basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000986operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000987
988template<class _CharT, class _Traits, class _Allocator>
989basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000990operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000991
992template<class _CharT, class _Traits, class _Allocator>
993basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000994operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000995
996template<class _CharT, class _Traits, class _Allocator>
997basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000998operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000999
1000template <bool>
1001class __basic_string_common
1002{
1003protected:
1004 void __throw_length_error() const;
1005 void __throw_out_of_range() const;
1006};
1007
1008template <bool __b>
1009void
1010__basic_string_common<__b>::__throw_length_error() const
1011{
1012#ifndef _LIBCPP_NO_EXCEPTIONS
1013 throw length_error("basic_string");
1014#else
1015 assert(!"basic_string length_error");
1016#endif
1017}
1018
1019template <bool __b>
1020void
1021__basic_string_common<__b>::__throw_out_of_range() const
1022{
1023#ifndef _LIBCPP_NO_EXCEPTIONS
1024 throw out_of_range("basic_string");
1025#else
1026 assert(!"basic_string out_of_range");
1027#endif
1028}
1029
Howard Hinnant78b68282011-10-22 20:59:45 +00001030#ifdef _MSC_VER
1031#pragma warning( push )
1032#pragma warning( disable: 4231 )
1033#endif // _MSC_VER
Howard Hinnantff926772012-11-06 21:08:48 +00001034_LIBCPP_EXTERN_TEMPLATE(class __basic_string_common<true>)
Howard Hinnant78b68282011-10-22 20:59:45 +00001035#ifdef _MSC_VER
1036#pragma warning( pop )
1037#endif // _MSC_VER
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001038
Howard Hinnant15467182013-04-30 21:44:48 +00001039#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1040
1041template <class _CharT, size_t = sizeof(_CharT)>
1042struct __padding
1043{
1044 unsigned char __xx[sizeof(_CharT)-1];
1045};
1046
1047template <class _CharT>
1048struct __padding<_CharT, 1>
1049{
1050};
1051
1052#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1053
Howard Hinnant324bb032010-08-22 00:02:43 +00001054template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant83eade62013-03-06 23:30:19 +00001055class _LIBCPP_TYPE_VIS basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001056 : private __basic_string_common<true>
1057{
1058public:
1059 typedef basic_string __self;
1060 typedef _Traits traits_type;
1061 typedef typename traits_type::char_type value_type;
1062 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001063 typedef allocator_traits<allocator_type> __alloc_traits;
1064 typedef typename __alloc_traits::size_type size_type;
1065 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001066 typedef value_type& reference;
1067 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001068 typedef typename __alloc_traits::pointer pointer;
1069 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001070#ifdef _LIBCPP_DEBUG
1071 typedef __debug_iter<basic_string, pointer> iterator;
1072 typedef __debug_iter<basic_string, const_pointer> const_iterator;
1073
1074 friend class __debug_iter<basic_string, pointer>;
1075 friend class __debug_iter<basic_string, const_pointer>;
1076#elif defined(_LIBCPP_RAW_ITERATORS)
1077 typedef pointer iterator;
1078 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001079#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001080 typedef __wrap_iter<pointer> iterator;
1081 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001082#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001083 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1084 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001085
1086private:
Howard Hinnant15467182013-04-30 21:44:48 +00001087
1088#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1089
1090 struct __long
1091 {
1092 pointer __data_;
1093 size_type __size_;
1094 size_type __cap_;
1095 };
1096
1097#if _LIBCPP_BIG_ENDIAN
1098 enum {__short_mask = 0x01};
1099 enum {__long_mask = 0x1ul};
1100#else // _LIBCPP_BIG_ENDIAN
1101 enum {__short_mask = 0x80};
1102 enum {__long_mask = ~(size_type(~0) >> 1)};
1103#endif // _LIBCPP_BIG_ENDIAN
1104
1105 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1106 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1107
1108 struct __short
1109 {
1110 value_type __data_[__min_cap];
1111 struct
1112 : __padding<value_type>
1113 {
1114 unsigned char __size_;
1115 };
1116 };
1117
1118#else
1119
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001120 struct __long
1121 {
1122 size_type __cap_;
1123 size_type __size_;
1124 pointer __data_;
1125 };
1126
1127#if _LIBCPP_BIG_ENDIAN
1128 enum {__short_mask = 0x80};
1129 enum {__long_mask = ~(size_type(~0) >> 1)};
Howard Hinnant324bb032010-08-22 00:02:43 +00001130#else // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001131 enum {__short_mask = 0x01};
Howard Hinnantec3773c2011-12-01 20:21:04 +00001132 enum {__long_mask = 0x1ul};
Howard Hinnant324bb032010-08-22 00:02:43 +00001133#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001134
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001135 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1136 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1137
1138 struct __short
1139 {
1140 union
1141 {
1142 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59 +00001143 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001144 };
1145 value_type __data_[__min_cap];
1146 };
1147
Howard Hinnant15467182013-04-30 21:44:48 +00001148#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1149
Howard Hinnant9c0df142012-10-30 19:06:59 +00001150 union __lx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001151
Howard Hinnant9c0df142012-10-30 19:06:59 +00001152 enum {__n_words = sizeof(__lx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001153
1154 struct __raw
1155 {
1156 size_type __words[__n_words];
1157 };
1158
1159 struct __rep
1160 {
1161 union
1162 {
1163 __long __l;
1164 __short __s;
1165 __raw __r;
1166 };
1167 };
1168
1169 __compressed_pair<__rep, allocator_type> __r_;
1170
1171#ifdef _LIBCPP_DEBUG
1172
1173 pair<iterator*, const_iterator*> __iterator_list_;
1174
1175 _LIBCPP_INLINE_VISIBILITY iterator*& __get_iterator_list(iterator*) {return __iterator_list_.first;}
1176 _LIBCPP_INLINE_VISIBILITY const_iterator*& __get_iterator_list(const_iterator*) {return __iterator_list_.second;}
1177
1178#endif // _LIBCPP_DEBUG
1179
1180public:
1181 static const size_type npos = -1;
1182
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001183 _LIBCPP_INLINE_VISIBILITY basic_string()
1184 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001185 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001186 basic_string(const basic_string& __str);
1187 basic_string(const basic_string& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001188#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9f193f22011-01-26 00:06:59 +00001189 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001190 basic_string(basic_string&& __str)
1191 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant9f193f22011-01-26 00:06:59 +00001192 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001193 basic_string(basic_string&& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001194#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001195 _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001196 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001197 basic_string(const value_type* __s, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001198 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001199 basic_string(const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001200 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001201 basic_string(const value_type* __s, size_type __n, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001202 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001203 basic_string(size_type __n, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001204 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001205 basic_string(size_type __n, value_type __c, const allocator_type& __a);
1206 basic_string(const basic_string& __str, size_type __pos, size_type __n = npos,
1207 const allocator_type& __a = allocator_type());
1208 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001209 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001210 basic_string(_InputIterator __first, _InputIterator __last);
1211 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001212 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001213 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001214#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001215 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001216 basic_string(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001217 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001218 basic_string(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001219#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001220
1221 ~basic_string();
1222
Howard Hinnante32b5e22010-11-17 17:55:08 +00001223 basic_string& operator=(const basic_string& __str);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001224#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001225 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001226 basic_string& operator=(basic_string&& __str)
1227 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
1228 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001229#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001230 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001231 basic_string& operator=(value_type __c);
Howard Hinnante3e32912011-08-12 21:56:02 +00001232#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001233 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001234 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001235#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001236
1237#ifndef _LIBCPP_DEBUG
Howard Hinnanta6119a82011-05-29 19:57:12 +00001238 _LIBCPP_INLINE_VISIBILITY
1239 iterator begin() _NOEXCEPT
1240 {return iterator(__get_pointer());}
1241 _LIBCPP_INLINE_VISIBILITY
1242 const_iterator begin() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001243 {return const_iterator(__get_pointer());}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001244 _LIBCPP_INLINE_VISIBILITY
1245 iterator end() _NOEXCEPT
1246 {return iterator(__get_pointer() + size());}
1247 _LIBCPP_INLINE_VISIBILITY
1248 const_iterator end() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001249 {return const_iterator(__get_pointer() + size());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001250#else // _LIBCPP_DEBUG
1251 _LIBCPP_INLINE_VISIBILITY iterator begin() {return iterator(this, __get_pointer());}
1252 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const {return const_iterator(this, data());}
1253 _LIBCPP_INLINE_VISIBILITY iterator end() {return iterator(this, __get_pointer() + size());}
1254 _LIBCPP_INLINE_VISIBILITY const_iterator end() const {return const_iterator(this, data() + size());}
1255#endif // _LIBCPP_DEBUG
Howard Hinnanta6119a82011-05-29 19:57:12 +00001256 _LIBCPP_INLINE_VISIBILITY
1257 reverse_iterator rbegin() _NOEXCEPT
1258 {return reverse_iterator(end());}
1259 _LIBCPP_INLINE_VISIBILITY
1260 const_reverse_iterator rbegin() const _NOEXCEPT
1261 {return const_reverse_iterator(end());}
1262 _LIBCPP_INLINE_VISIBILITY
1263 reverse_iterator rend() _NOEXCEPT
1264 {return reverse_iterator(begin());}
1265 _LIBCPP_INLINE_VISIBILITY
1266 const_reverse_iterator rend() const _NOEXCEPT
1267 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001268
Howard Hinnanta6119a82011-05-29 19:57:12 +00001269 _LIBCPP_INLINE_VISIBILITY
1270 const_iterator cbegin() const _NOEXCEPT
1271 {return begin();}
1272 _LIBCPP_INLINE_VISIBILITY
1273 const_iterator cend() const _NOEXCEPT
1274 {return end();}
1275 _LIBCPP_INLINE_VISIBILITY
1276 const_reverse_iterator crbegin() const _NOEXCEPT
1277 {return rbegin();}
1278 _LIBCPP_INLINE_VISIBILITY
1279 const_reverse_iterator crend() const _NOEXCEPT
1280 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001281
Howard Hinnanta6119a82011-05-29 19:57:12 +00001282 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001283 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001284 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
1285 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
1286 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001287 {return (__is_long() ? __get_long_cap() : __min_cap) - 1;}
1288
1289 void resize(size_type __n, value_type __c);
1290 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
1291
1292 void reserve(size_type res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001293 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001294 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001295 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001296 void clear() _NOEXCEPT;
1297 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001298
1299 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const;
1300 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos);
1301
1302 const_reference at(size_type __n) const;
1303 reference at(size_type __n);
1304
1305 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001306 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001307 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +00001308#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001309 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Howard Hinnante3e32912011-08-12 21:56:02 +00001310#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001311
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001312 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001313 basic_string& append(const basic_string& __str);
1314 basic_string& append(const basic_string& __str, size_type __pos, size_type __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001315 basic_string& append(const value_type* __s, size_type __n);
1316 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001317 basic_string& append(size_type __n, value_type __c);
1318 template<class _InputIterator>
1319 typename enable_if
1320 <
1321 __is_input_iterator <_InputIterator>::value &&
1322 !__is_forward_iterator<_InputIterator>::value,
1323 basic_string&
1324 >::type
1325 append(_InputIterator __first, _InputIterator __last);
1326 template<class _ForwardIterator>
1327 typename enable_if
1328 <
1329 __is_forward_iterator<_ForwardIterator>::value,
1330 basic_string&
1331 >::type
1332 append(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001333#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001334 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001335 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001336#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001337
1338 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001339 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001340 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001341 _LIBCPP_INLINE_VISIBILITY reference front();
1342 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
1343 _LIBCPP_INLINE_VISIBILITY reference back();
1344 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001345
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001346 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001347 basic_string& assign(const basic_string& __str);
Howard Hinnanta6119a82011-05-29 19:57:12 +00001348#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1349 _LIBCPP_INLINE_VISIBILITY
1350 basic_string& assign(basic_string&& str)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001351 {*this = _VSTD::move(str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001352#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001353 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001354 basic_string& assign(const value_type* __s, size_type __n);
1355 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001356 basic_string& assign(size_type __n, value_type __c);
1357 template<class _InputIterator>
1358 typename enable_if
1359 <
1360 __is_input_iterator <_InputIterator>::value &&
1361 !__is_forward_iterator<_InputIterator>::value,
1362 basic_string&
1363 >::type
1364 assign(_InputIterator __first, _InputIterator __last);
1365 template<class _ForwardIterator>
1366 typename enable_if
1367 <
1368 __is_forward_iterator<_ForwardIterator>::value,
1369 basic_string&
1370 >::type
1371 assign(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001372#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001373 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001374 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001375#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001376
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001377 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001378 basic_string& insert(size_type __pos1, const basic_string& __str);
1379 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001380 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1381 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001382 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1383 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001384 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001385 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1386 template<class _InputIterator>
1387 typename enable_if
1388 <
1389 __is_input_iterator <_InputIterator>::value &&
1390 !__is_forward_iterator<_InputIterator>::value,
1391 iterator
1392 >::type
1393 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1394 template<class _ForwardIterator>
1395 typename enable_if
1396 <
1397 __is_forward_iterator<_ForwardIterator>::value,
1398 iterator
1399 >::type
1400 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001401#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001402 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001403 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1404 {return insert(__pos, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001405#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001406
1407 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001408 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001409 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001410 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001411 iterator erase(const_iterator __first, const_iterator __last);
1412
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001413 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001414 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
1415 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001416 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1417 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001418 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001419 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001420 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001421 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001422 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001423 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001424 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001425 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001426 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001427 template<class _InputIterator>
1428 typename enable_if
1429 <
1430 __is_input_iterator<_InputIterator>::value,
1431 basic_string&
1432 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001433 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Howard Hinnante3e32912011-08-12 21:56:02 +00001434#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001435 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001436 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001437 {return replace(__i1, __i2, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001438#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001439
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001440 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001441 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001442 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1443
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001444 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001445 void swap(basic_string& __str)
1446 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1447 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001448
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001449 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001450 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001451 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001452 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001453
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001454 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001455 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001456
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001457 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001458 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001459 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001460 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001461 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001462 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001463
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001464 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001465 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001466 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001468 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001469 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001470
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001471 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001472 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001473 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001474 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001475 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001477 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001478
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001480 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001481 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001482 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001483 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001485 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001486
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001488 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001489 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 +00001490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001491 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001492 _LIBCPP_INLINE_VISIBILITY
1493 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1494
1495 _LIBCPP_INLINE_VISIBILITY
1496 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001497 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 +00001498 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001499 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001500 _LIBCPP_INLINE_VISIBILITY
1501 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1502
1503 _LIBCPP_INLINE_VISIBILITY
1504 int compare(const basic_string& __str) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001505 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001506 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
1507 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001508 int compare(const value_type* __s) const _NOEXCEPT;
1509 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1510 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001511
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001512 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:13 +00001513
1514 _LIBCPP_INLINE_VISIBILITY
1515 bool __is_long() const _NOEXCEPT
1516 {return bool(__r_.first().__s.__size_ & __short_mask);}
1517
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001518private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001519 _LIBCPP_INLINE_VISIBILITY
1520 allocator_type& __alloc() _NOEXCEPT
1521 {return __r_.second();}
1522 _LIBCPP_INLINE_VISIBILITY
1523 const allocator_type& __alloc() const _NOEXCEPT
1524 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001525
Howard Hinnant15467182013-04-30 21:44:48 +00001526#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1527
Howard Hinnanta6119a82011-05-29 19:57:12 +00001528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001529 void __set_short_size(size_type __s) _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001530# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001531 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:48 +00001532# else
1533 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1534# endif
1535
Howard Hinnanta6119a82011-05-29 19:57:12 +00001536 _LIBCPP_INLINE_VISIBILITY
1537 size_type __get_short_size() const _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001538# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001539 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:48 +00001540# else
1541 {return __r_.first().__s.__size_;}
1542# endif
1543
1544#else // _LIBCPP_ALTERNATE_STRING_LAYOUT
1545
1546 _LIBCPP_INLINE_VISIBILITY
1547 void __set_short_size(size_type __s) _NOEXCEPT
1548# if _LIBCPP_BIG_ENDIAN
1549 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1550# else
1551 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1552# endif
1553
1554 _LIBCPP_INLINE_VISIBILITY
1555 size_type __get_short_size() const _NOEXCEPT
1556# if _LIBCPP_BIG_ENDIAN
1557 {return __r_.first().__s.__size_;}
1558# else
1559 {return __r_.first().__s.__size_ >> 1;}
1560# endif
1561
1562#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1563
Howard Hinnanta6119a82011-05-29 19:57:12 +00001564 _LIBCPP_INLINE_VISIBILITY
1565 void __set_long_size(size_type __s) _NOEXCEPT
1566 {__r_.first().__l.__size_ = __s;}
1567 _LIBCPP_INLINE_VISIBILITY
1568 size_type __get_long_size() const _NOEXCEPT
1569 {return __r_.first().__l.__size_;}
1570 _LIBCPP_INLINE_VISIBILITY
1571 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001572 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1573
Howard Hinnanta6119a82011-05-29 19:57:12 +00001574 _LIBCPP_INLINE_VISIBILITY
1575 void __set_long_cap(size_type __s) _NOEXCEPT
1576 {__r_.first().__l.__cap_ = __long_mask | __s;}
1577 _LIBCPP_INLINE_VISIBILITY
1578 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001579 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001580
Howard Hinnanta6119a82011-05-29 19:57:12 +00001581 _LIBCPP_INLINE_VISIBILITY
1582 void __set_long_pointer(pointer __p) _NOEXCEPT
1583 {__r_.first().__l.__data_ = __p;}
1584 _LIBCPP_INLINE_VISIBILITY
1585 pointer __get_long_pointer() _NOEXCEPT
1586 {return __r_.first().__l.__data_;}
1587 _LIBCPP_INLINE_VISIBILITY
1588 const_pointer __get_long_pointer() const _NOEXCEPT
1589 {return __r_.first().__l.__data_;}
1590 _LIBCPP_INLINE_VISIBILITY
1591 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001592 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001593 _LIBCPP_INLINE_VISIBILITY
1594 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001595 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001596 _LIBCPP_INLINE_VISIBILITY
1597 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001598 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001599 _LIBCPP_INLINE_VISIBILITY
1600 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001601 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1602
Howard Hinnanta6119a82011-05-29 19:57:12 +00001603 _LIBCPP_INLINE_VISIBILITY
1604 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001605 {
1606 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1607 for (unsigned __i = 0; __i < __n_words; ++__i)
1608 __a[__i] = 0;
1609 }
1610
1611 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001612 _LIBCPP_INLINE_VISIBILITY
1613 size_type __align(size_type __s) _NOEXCEPT
1614 {return __s + (__a-1) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001615 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001616 static _LIBCPP_INLINE_VISIBILITY
1617 size_type __recommend(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001618 {return (__s < __min_cap ? __min_cap :
Howard Hinnanta6119a82011-05-29 19:57:12 +00001619 __align<sizeof(value_type) < __alignment ?
1620 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001621
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001622 void __init(const value_type* __s, size_type __sz, size_type __reserve);
1623 void __init(const value_type* __s, size_type __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001624 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001625
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001626 template <class _InputIterator>
1627 typename enable_if
1628 <
1629 __is_input_iterator <_InputIterator>::value &&
1630 !__is_forward_iterator<_InputIterator>::value,
1631 void
1632 >::type
1633 __init(_InputIterator __first, _InputIterator __last);
1634
1635 template <class _ForwardIterator>
1636 typename enable_if
1637 <
1638 __is_forward_iterator<_ForwardIterator>::value,
1639 void
1640 >::type
1641 __init(_ForwardIterator __first, _ForwardIterator __last);
1642
1643 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001644 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001645 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1646 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001647 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001648
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001649 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001650 void __erase_to_end(size_type __pos);
1651
Howard Hinnante32b5e22010-11-17 17:55:08 +00001652 _LIBCPP_INLINE_VISIBILITY
1653 void __copy_assign_alloc(const basic_string& __str)
1654 {__copy_assign_alloc(__str, integral_constant<bool,
1655 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1656
1657 _LIBCPP_INLINE_VISIBILITY
1658 void __copy_assign_alloc(const basic_string& __str, true_type)
1659 {
1660 if (__alloc() != __str.__alloc())
1661 {
1662 clear();
1663 shrink_to_fit();
1664 }
1665 __alloc() = __str.__alloc();
1666 }
1667
1668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001669 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001670 {}
1671
1672#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001673 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00001674 void __move_assign(basic_string& __str, false_type);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001675 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001676 void __move_assign(basic_string& __str, true_type)
1677 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001678#endif
1679
1680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001681 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001682 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001683 _NOEXCEPT_(
1684 !__alloc_traits::propagate_on_container_move_assignment::value ||
1685 is_nothrow_move_assignable<allocator_type>::value)
1686 {__move_assign_alloc(__str, integral_constant<bool,
1687 __alloc_traits::propagate_on_container_move_assignment::value>());}
1688
1689 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001690 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001691 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1692 {
1693 __alloc() = _VSTD::move(__c.__alloc());
1694 }
1695
1696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001697 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001698 _NOEXCEPT
1699 {}
1700
1701 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001702 static void __swap_alloc(allocator_type& __x, allocator_type& __y)
1703 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1704 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001705 {__swap_alloc(__x, __y, integral_constant<bool,
1706 __alloc_traits::propagate_on_container_swap::value>());}
1707
1708 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001709 static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
1710 _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001711 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001712 using _VSTD::swap;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001713 swap(__x, __y);
1714 }
1715 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001716 static void __swap_alloc(allocator_type&, allocator_type&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001717 {}
1718
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001719 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1720 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001721
1722 friend basic_string operator+<>(const basic_string&, const basic_string&);
1723 friend basic_string operator+<>(const value_type*, const basic_string&);
1724 friend basic_string operator+<>(value_type, const basic_string&);
1725 friend basic_string operator+<>(const basic_string&, const value_type*);
1726 friend basic_string operator+<>(const basic_string&, value_type);
1727};
1728
1729template <class _CharT, class _Traits, class _Allocator>
1730#ifndef _LIBCPP_DEBUG
1731_LIBCPP_INLINE_VISIBILITY inline
1732#endif
1733void
1734basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1735{
1736#ifdef _LIBCPP_DEBUG
1737 iterator::__remove_all(this);
1738 const_iterator::__remove_all(this);
Howard Hinnant324bb032010-08-22 00:02:43 +00001739#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001740}
1741
1742template <class _CharT, class _Traits, class _Allocator>
1743#ifndef _LIBCPP_DEBUG
1744_LIBCPP_INLINE_VISIBILITY inline
1745#endif
1746void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001747basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
1748#ifdef _LIBCPP_DEBUG
1749 __pos
1750#endif
1751 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001752{
1753#ifdef _LIBCPP_DEBUG
1754 const_iterator __beg = begin();
1755 if (__iterator_list_.first)
1756 {
1757 for (iterator* __p = __iterator_list_.first; __p;)
1758 {
1759 if (*__p - __beg > static_cast<difference_type>(__pos))
1760 {
1761 iterator* __n = __p;
1762 __p = __p->__next;
1763 __n->__remove_owner();
1764 }
1765 else
1766 __p = __p->__next;
1767 }
1768 }
1769 if (__iterator_list_.second)
1770 {
1771 for (const_iterator* __p = __iterator_list_.second; __p;)
1772 {
1773 if (*__p - __beg > static_cast<difference_type>(__pos))
1774 {
1775 const_iterator* __n = __p;
1776 __p = __p->__next;
1777 __n->__remove_owner();
1778 }
1779 else
1780 __p = __p->__next;
1781 }
1782 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001783#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001784}
1785
1786template <class _CharT, class _Traits, class _Allocator>
1787_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001788basic_string<_CharT, _Traits, _Allocator>::basic_string()
1789 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001790{
1791 __zero();
1792}
1793
1794template <class _CharT, class _Traits, class _Allocator>
1795_LIBCPP_INLINE_VISIBILITY inline
1796basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
1797 : __r_(__a)
1798{
1799 __zero();
1800}
1801
1802template <class _CharT, class _Traits, class _Allocator>
1803void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001804basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001805{
1806 if (__reserve > max_size())
1807 this->__throw_length_error();
1808 pointer __p;
1809 if (__reserve < __min_cap)
1810 {
1811 __set_short_size(__sz);
1812 __p = __get_short_pointer();
1813 }
1814 else
1815 {
1816 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001817 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001818 __set_long_pointer(__p);
1819 __set_long_cap(__cap+1);
1820 __set_long_size(__sz);
1821 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001822 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001823 traits_type::assign(__p[__sz], value_type());
1824}
1825
1826template <class _CharT, class _Traits, class _Allocator>
1827void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001828basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001829{
1830 if (__sz > max_size())
1831 this->__throw_length_error();
1832 pointer __p;
1833 if (__sz < __min_cap)
1834 {
1835 __set_short_size(__sz);
1836 __p = __get_short_pointer();
1837 }
1838 else
1839 {
1840 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001841 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001842 __set_long_pointer(__p);
1843 __set_long_cap(__cap+1);
1844 __set_long_size(__sz);
1845 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001846 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001847 traits_type::assign(__p[__sz], value_type());
1848}
1849
1850template <class _CharT, class _Traits, class _Allocator>
1851_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001852basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001853{
1854#ifdef _LIBCPP_DEBUG
1855 assert(__s != 0);
1856#endif
1857 __init(__s, traits_type::length(__s));
1858}
1859
1860template <class _CharT, class _Traits, class _Allocator>
1861_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001862basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001863 : __r_(__a)
1864{
1865#ifdef _LIBCPP_DEBUG
1866 assert(__s != 0);
1867#endif
1868 __init(__s, traits_type::length(__s));
1869}
1870
1871template <class _CharT, class _Traits, class _Allocator>
1872_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001873basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001874{
1875#ifdef _LIBCPP_DEBUG
1876 assert(__s != 0);
1877#endif
1878 __init(__s, __n);
1879}
1880
1881template <class _CharT, class _Traits, class _Allocator>
1882_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001883basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001884 : __r_(__a)
1885{
1886#ifdef _LIBCPP_DEBUG
1887 assert(__s != 0);
1888#endif
1889 __init(__s, __n);
1890}
1891
1892template <class _CharT, class _Traits, class _Allocator>
1893basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001894 : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001895{
1896 if (!__str.__is_long())
1897 __r_.first().__r = __str.__r_.first().__r;
1898 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001899 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001900}
1901
1902template <class _CharT, class _Traits, class _Allocator>
1903basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
1904 : __r_(__a)
1905{
1906 if (!__str.__is_long())
1907 __r_.first().__r = __str.__r_.first().__r;
1908 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001909 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001910}
1911
Howard Hinnant73d21a42010-09-04 23:28:19 +00001912#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001913
1914template <class _CharT, class _Traits, class _Allocator>
1915_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001916basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
1917 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001918 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001919{
1920 __str.__zero();
1921#ifdef _LIBCPP_DEBUG
1922 __str.__invalidate_all_iterators();
1923#endif
1924}
1925
1926template <class _CharT, class _Traits, class _Allocator>
1927_LIBCPP_INLINE_VISIBILITY inline
1928basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001929 : __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001930{
Howard Hinnante32b5e22010-11-17 17:55:08 +00001931 if (__a == __str.__alloc() || !__str.__is_long())
1932 __r_.first().__r = __str.__r_.first().__r;
1933 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001934 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001935 __str.__zero();
1936#ifdef _LIBCPP_DEBUG
1937 __str.__invalidate_all_iterators();
1938#endif
1939}
1940
Howard Hinnant73d21a42010-09-04 23:28:19 +00001941#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001942
1943template <class _CharT, class _Traits, class _Allocator>
1944void
1945basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1946{
1947 if (__n > max_size())
1948 this->__throw_length_error();
1949 pointer __p;
1950 if (__n < __min_cap)
1951 {
1952 __set_short_size(__n);
1953 __p = __get_short_pointer();
1954 }
1955 else
1956 {
1957 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001958 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001959 __set_long_pointer(__p);
1960 __set_long_cap(__cap+1);
1961 __set_long_size(__n);
1962 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001963 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001964 traits_type::assign(__p[__n], value_type());
1965}
1966
1967template <class _CharT, class _Traits, class _Allocator>
1968_LIBCPP_INLINE_VISIBILITY inline
1969basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
1970{
1971 __init(__n, __c);
1972}
1973
1974template <class _CharT, class _Traits, class _Allocator>
1975_LIBCPP_INLINE_VISIBILITY inline
1976basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
1977 : __r_(__a)
1978{
1979 __init(__n, __c);
1980}
1981
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001982template <class _CharT, class _Traits, class _Allocator>
1983basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
1984 const allocator_type& __a)
1985 : __r_(__a)
1986{
1987 size_type __str_sz = __str.size();
1988 if (__pos > __str_sz)
1989 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001990 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001991}
1992
1993template <class _CharT, class _Traits, class _Allocator>
1994template <class _InputIterator>
1995typename enable_if
1996<
1997 __is_input_iterator <_InputIterator>::value &&
1998 !__is_forward_iterator<_InputIterator>::value,
1999 void
2000>::type
2001basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2002{
2003 __zero();
2004#ifndef _LIBCPP_NO_EXCEPTIONS
2005 try
2006 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002007#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002008 for (; __first != __last; ++__first)
2009 push_back(*__first);
2010#ifndef _LIBCPP_NO_EXCEPTIONS
2011 }
2012 catch (...)
2013 {
2014 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002015 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002016 throw;
2017 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002018#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002019}
2020
2021template <class _CharT, class _Traits, class _Allocator>
2022template <class _ForwardIterator>
2023typename enable_if
2024<
2025 __is_forward_iterator<_ForwardIterator>::value,
2026 void
2027>::type
2028basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2029{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002030 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002031 if (__sz > max_size())
2032 this->__throw_length_error();
2033 pointer __p;
2034 if (__sz < __min_cap)
2035 {
2036 __set_short_size(__sz);
2037 __p = __get_short_pointer();
2038 }
2039 else
2040 {
2041 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002042 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002043 __set_long_pointer(__p);
2044 __set_long_cap(__cap+1);
2045 __set_long_size(__sz);
2046 }
2047 for (; __first != __last; ++__first, ++__p)
2048 traits_type::assign(*__p, *__first);
2049 traits_type::assign(*__p, value_type());
2050}
2051
2052template <class _CharT, class _Traits, class _Allocator>
2053template<class _InputIterator>
2054_LIBCPP_INLINE_VISIBILITY inline
2055basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2056{
2057 __init(__first, __last);
2058}
2059
2060template <class _CharT, class _Traits, class _Allocator>
2061template<class _InputIterator>
2062_LIBCPP_INLINE_VISIBILITY inline
2063basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2064 const allocator_type& __a)
2065 : __r_(__a)
2066{
2067 __init(__first, __last);
2068}
2069
Howard Hinnante3e32912011-08-12 21:56:02 +00002070#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2071
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002072template <class _CharT, class _Traits, class _Allocator>
2073_LIBCPP_INLINE_VISIBILITY inline
2074basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
2075{
2076 __init(__il.begin(), __il.end());
2077}
2078
2079template <class _CharT, class _Traits, class _Allocator>
2080_LIBCPP_INLINE_VISIBILITY inline
2081basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
2082 : __r_(__a)
2083{
2084 __init(__il.begin(), __il.end());
2085}
2086
Howard Hinnante3e32912011-08-12 21:56:02 +00002087#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2088
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002089template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002090basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2091{
2092 __invalidate_all_iterators();
2093 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002094 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002095}
2096
2097template <class _CharT, class _Traits, class _Allocator>
2098void
2099basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2100 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002101 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 +00002102{
2103 size_type __ms = max_size();
2104 if (__delta_cap > __ms - __old_cap - 1)
2105 this->__throw_length_error();
2106 pointer __old_p = __get_pointer();
2107 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002108 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002109 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002110 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002111 __invalidate_all_iterators();
2112 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002113 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2114 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002115 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002116 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002117 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2118 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002119 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2120 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002121 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002122 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002123 __set_long_pointer(__p);
2124 __set_long_cap(__cap+1);
2125 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2126 __set_long_size(__old_sz);
2127 traits_type::assign(__p[__old_sz], value_type());
2128}
2129
2130template <class _CharT, class _Traits, class _Allocator>
2131void
2132basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2133 size_type __n_copy, size_type __n_del, size_type __n_add)
2134{
2135 size_type __ms = max_size();
2136 if (__delta_cap > __ms - __old_cap - 1)
2137 this->__throw_length_error();
2138 pointer __old_p = __get_pointer();
2139 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002140 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002141 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002142 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002143 __invalidate_all_iterators();
2144 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002145 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2146 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002147 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2148 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002149 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2150 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
2151 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002152 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002153 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002154 __set_long_pointer(__p);
2155 __set_long_cap(__cap+1);
2156}
2157
2158// assign
2159
2160template <class _CharT, class _Traits, class _Allocator>
2161basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002162basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002163{
2164#ifdef _LIBCPP_DEBUG
2165 assert(__s != 0);
2166#endif
2167 size_type __cap = capacity();
2168 if (__cap >= __n)
2169 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002170 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002171 traits_type::move(__p, __s, __n);
2172 traits_type::assign(__p[__n], value_type());
2173 __set_size(__n);
2174 __invalidate_iterators_past(__n);
2175 }
2176 else
2177 {
2178 size_type __sz = size();
2179 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2180 }
2181 return *this;
2182}
2183
2184template <class _CharT, class _Traits, class _Allocator>
2185basic_string<_CharT, _Traits, _Allocator>&
2186basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2187{
2188 size_type __cap = capacity();
2189 if (__cap < __n)
2190 {
2191 size_type __sz = size();
2192 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2193 }
2194 else
2195 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002196 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002197 traits_type::assign(__p, __n, __c);
2198 traits_type::assign(__p[__n], value_type());
2199 __set_size(__n);
2200 return *this;
2201}
2202
2203template <class _CharT, class _Traits, class _Allocator>
2204basic_string<_CharT, _Traits, _Allocator>&
2205basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2206{
2207 pointer __p;
2208 if (__is_long())
2209 {
2210 __p = __get_long_pointer();
2211 __set_long_size(1);
2212 }
2213 else
2214 {
2215 __p = __get_short_pointer();
2216 __set_short_size(1);
2217 }
2218 traits_type::assign(*__p, __c);
2219 traits_type::assign(*++__p, value_type());
2220 __invalidate_iterators_past(1);
2221 return *this;
2222}
2223
2224template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00002225basic_string<_CharT, _Traits, _Allocator>&
2226basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2227{
2228 if (this != &__str)
2229 {
2230 __copy_assign_alloc(__str);
2231 assign(__str);
2232 }
2233 return *this;
2234}
2235
2236#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2237
2238template <class _CharT, class _Traits, class _Allocator>
2239_LIBCPP_INLINE_VISIBILITY inline
2240void
2241basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
2242{
2243 if (__alloc() != __str.__alloc())
2244 assign(__str);
2245 else
2246 __move_assign(__str, true_type());
2247}
2248
2249template <class _CharT, class _Traits, class _Allocator>
2250_LIBCPP_INLINE_VISIBILITY inline
2251void
2252basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002253 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002254{
2255 clear();
2256 shrink_to_fit();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00002257 __r_.first() = __str.__r_.first();
2258 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002259 __str.__zero();
2260}
2261
2262template <class _CharT, class _Traits, class _Allocator>
2263_LIBCPP_INLINE_VISIBILITY inline
2264basic_string<_CharT, _Traits, _Allocator>&
2265basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002266 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
2267 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002268{
2269 __move_assign(__str, integral_constant<bool,
2270 __alloc_traits::propagate_on_container_move_assignment::value>());
2271 return *this;
2272}
2273
2274#endif
2275
2276template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002277template<class _InputIterator>
2278typename enable_if
2279<
2280 __is_input_iterator <_InputIterator>::value &&
2281 !__is_forward_iterator<_InputIterator>::value,
2282 basic_string<_CharT, _Traits, _Allocator>&
2283>::type
2284basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2285{
2286 clear();
2287 for (; __first != __last; ++__first)
2288 push_back(*__first);
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002289 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002290}
2291
2292template <class _CharT, class _Traits, class _Allocator>
2293template<class _ForwardIterator>
2294typename enable_if
2295<
2296 __is_forward_iterator<_ForwardIterator>::value,
2297 basic_string<_CharT, _Traits, _Allocator>&
2298>::type
2299basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2300{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002301 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002302 size_type __cap = capacity();
2303 if (__cap < __n)
2304 {
2305 size_type __sz = size();
2306 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2307 }
2308 else
2309 __invalidate_iterators_past(__n);
2310 pointer __p = __get_pointer();
2311 for (; __first != __last; ++__first, ++__p)
2312 traits_type::assign(*__p, *__first);
2313 traits_type::assign(*__p, value_type());
2314 __set_size(__n);
2315 return *this;
2316}
2317
2318template <class _CharT, class _Traits, class _Allocator>
2319_LIBCPP_INLINE_VISIBILITY inline
2320basic_string<_CharT, _Traits, _Allocator>&
2321basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str)
2322{
2323 return assign(__str.data(), __str.size());
2324}
2325
2326template <class _CharT, class _Traits, class _Allocator>
2327basic_string<_CharT, _Traits, _Allocator>&
2328basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2329{
2330 size_type __sz = __str.size();
2331 if (__pos > __sz)
2332 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002333 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002334}
2335
2336template <class _CharT, class _Traits, class _Allocator>
2337basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002338basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002339{
2340#ifdef _LIBCPP_DEBUG
2341 assert(__s != 0);
2342#endif
2343 return assign(__s, traits_type::length(__s));
2344}
2345
2346// append
2347
2348template <class _CharT, class _Traits, class _Allocator>
2349basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002350basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002351{
2352#ifdef _LIBCPP_DEBUG
2353 assert(__s != 0);
2354#endif
2355 size_type __cap = capacity();
2356 size_type __sz = size();
2357 if (__cap - __sz >= __n)
2358 {
2359 if (__n)
2360 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002361 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002362 traits_type::copy(__p + __sz, __s, __n);
2363 __sz += __n;
2364 __set_size(__sz);
2365 traits_type::assign(__p[__sz], value_type());
2366 }
2367 }
2368 else
2369 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2370 return *this;
2371}
2372
2373template <class _CharT, class _Traits, class _Allocator>
2374basic_string<_CharT, _Traits, _Allocator>&
2375basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2376{
2377 if (__n)
2378 {
2379 size_type __cap = capacity();
2380 size_type __sz = size();
2381 if (__cap - __sz < __n)
2382 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2383 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002384 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002385 __sz += __n;
2386 __set_size(__sz);
2387 traits_type::assign(__p[__sz], value_type());
2388 }
2389 return *this;
2390}
2391
2392template <class _CharT, class _Traits, class _Allocator>
2393void
2394basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2395{
Howard Hinnant15467182013-04-30 21:44:48 +00002396 bool __is_short = !__is_long();
2397 size_type __cap;
2398 size_type __sz;
2399 if (__is_short)
2400 {
2401 __cap = __min_cap - 1;
2402 __sz = __get_short_size();
2403 }
2404 else
2405 {
2406 __cap = __get_long_cap() - 1;
2407 __sz = __get_long_size();
2408 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002409 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002410 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002411 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002412 __is_short = !__is_long();
2413 }
2414 pointer __p;
2415 if (__is_short)
2416 {
2417 __p = __get_short_pointer() + __sz;
2418 __set_short_size(__sz+1);
2419 }
2420 else
2421 {
2422 __p = __get_long_pointer() + __sz;
2423 __set_long_size(__sz+1);
2424 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002425 traits_type::assign(*__p, __c);
2426 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002427}
2428
2429template <class _CharT, class _Traits, class _Allocator>
2430template<class _InputIterator>
2431typename enable_if
2432<
2433 __is_input_iterator <_InputIterator>::value &&
2434 !__is_forward_iterator<_InputIterator>::value,
2435 basic_string<_CharT, _Traits, _Allocator>&
2436>::type
2437basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
2438{
2439 for (; __first != __last; ++__first)
2440 push_back(*__first);
2441 return *this;
2442}
2443
2444template <class _CharT, class _Traits, class _Allocator>
2445template<class _ForwardIterator>
2446typename enable_if
2447<
2448 __is_forward_iterator<_ForwardIterator>::value,
2449 basic_string<_CharT, _Traits, _Allocator>&
2450>::type
2451basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
2452{
2453 size_type __sz = size();
2454 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002455 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002456 if (__n)
2457 {
2458 if (__cap - __sz < __n)
2459 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2460 pointer __p = __get_pointer() + __sz;
2461 for (; __first != __last; ++__p, ++__first)
2462 traits_type::assign(*__p, *__first);
2463 traits_type::assign(*__p, value_type());
2464 __set_size(__sz + __n);
2465 }
2466 return *this;
2467}
2468
2469template <class _CharT, class _Traits, class _Allocator>
2470_LIBCPP_INLINE_VISIBILITY inline
2471basic_string<_CharT, _Traits, _Allocator>&
2472basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2473{
2474 return append(__str.data(), __str.size());
2475}
2476
2477template <class _CharT, class _Traits, class _Allocator>
2478basic_string<_CharT, _Traits, _Allocator>&
2479basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2480{
2481 size_type __sz = __str.size();
2482 if (__pos > __sz)
2483 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002484 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002485}
2486
2487template <class _CharT, class _Traits, class _Allocator>
2488basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002489basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002490{
2491#ifdef _LIBCPP_DEBUG
2492 assert(__s != 0);
2493#endif
2494 return append(__s, traits_type::length(__s));
2495}
2496
2497// insert
2498
2499template <class _CharT, class _Traits, class _Allocator>
2500basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002501basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002502{
2503#ifdef _LIBCPP_DEBUG
2504 assert(__s != 0);
2505#endif
2506 size_type __sz = size();
2507 if (__pos > __sz)
2508 this->__throw_out_of_range();
2509 size_type __cap = capacity();
2510 if (__cap - __sz >= __n)
2511 {
2512 if (__n)
2513 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002514 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002515 size_type __n_move = __sz - __pos;
2516 if (__n_move != 0)
2517 {
2518 if (__p + __pos <= __s && __s < __p + __sz)
2519 __s += __n;
2520 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2521 }
2522 traits_type::move(__p + __pos, __s, __n);
2523 __sz += __n;
2524 __set_size(__sz);
2525 traits_type::assign(__p[__sz], value_type());
2526 }
2527 }
2528 else
2529 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2530 return *this;
2531}
2532
2533template <class _CharT, class _Traits, class _Allocator>
2534basic_string<_CharT, _Traits, _Allocator>&
2535basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2536{
2537 size_type __sz = size();
2538 if (__pos > __sz)
2539 this->__throw_out_of_range();
2540 if (__n)
2541 {
2542 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002543 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002544 if (__cap - __sz >= __n)
2545 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002546 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002547 size_type __n_move = __sz - __pos;
2548 if (__n_move != 0)
2549 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2550 }
2551 else
2552 {
2553 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002554 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002555 }
2556 traits_type::assign(__p + __pos, __n, __c);
2557 __sz += __n;
2558 __set_size(__sz);
2559 traits_type::assign(__p[__sz], value_type());
2560 }
2561 return *this;
2562}
2563
2564template <class _CharT, class _Traits, class _Allocator>
2565template<class _InputIterator>
2566typename enable_if
2567<
2568 __is_input_iterator <_InputIterator>::value &&
2569 !__is_forward_iterator<_InputIterator>::value,
2570 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2571>::type
2572basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2573{
2574 size_type __old_sz = size();
2575 difference_type __ip = __pos - begin();
2576 for (; __first != __last; ++__first)
2577 push_back(*__first);
2578 pointer __p = __get_pointer();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002579 _VSTD::rotate(__p + __ip, __p + __old_sz, __p + size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002580 return iterator(__p + __ip);
2581}
2582
2583template <class _CharT, class _Traits, class _Allocator>
2584template<class _ForwardIterator>
2585typename enable_if
2586<
2587 __is_forward_iterator<_ForwardIterator>::value,
2588 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2589>::type
2590basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2591{
2592 size_type __ip = static_cast<size_type>(__pos - begin());
2593 size_type __sz = size();
2594 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002595 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002596 if (__n)
2597 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002598 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002599 if (__cap - __sz >= __n)
2600 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002601 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002602 size_type __n_move = __sz - __ip;
2603 if (__n_move != 0)
2604 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2605 }
2606 else
2607 {
2608 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002609 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002610 }
2611 __sz += __n;
2612 __set_size(__sz);
2613 traits_type::assign(__p[__sz], value_type());
2614 for (__p += __ip; __first != __last; ++__p, ++__first)
2615 traits_type::assign(*__p, *__first);
2616 }
2617 return begin() + __ip;
2618}
2619
2620template <class _CharT, class _Traits, class _Allocator>
2621_LIBCPP_INLINE_VISIBILITY inline
2622basic_string<_CharT, _Traits, _Allocator>&
2623basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2624{
2625 return insert(__pos1, __str.data(), __str.size());
2626}
2627
2628template <class _CharT, class _Traits, class _Allocator>
2629basic_string<_CharT, _Traits, _Allocator>&
2630basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2631 size_type __pos2, size_type __n)
2632{
2633 size_type __str_sz = __str.size();
2634 if (__pos2 > __str_sz)
2635 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002636 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002637}
2638
2639template <class _CharT, class _Traits, class _Allocator>
2640basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002641basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002642{
2643#ifdef _LIBCPP_DEBUG
2644 assert(__s != 0);
2645#endif
2646 return insert(__pos, __s, traits_type::length(__s));
2647}
2648
2649template <class _CharT, class _Traits, class _Allocator>
2650typename basic_string<_CharT, _Traits, _Allocator>::iterator
2651basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2652{
2653 size_type __ip = static_cast<size_type>(__pos - begin());
2654 size_type __sz = size();
2655 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002656 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002657 if (__cap == __sz)
2658 {
2659 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002660 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002661 }
2662 else
2663 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002664 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002665 size_type __n_move = __sz - __ip;
2666 if (__n_move != 0)
2667 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2668 }
2669 traits_type::assign(__p[__ip], __c);
2670 traits_type::assign(__p[++__sz], value_type());
2671 __set_size(__sz);
2672 return begin() + static_cast<difference_type>(__ip);
2673}
2674
2675template <class _CharT, class _Traits, class _Allocator>
2676_LIBCPP_INLINE_VISIBILITY inline
2677typename basic_string<_CharT, _Traits, _Allocator>::iterator
2678basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2679{
2680 difference_type __p = __pos - begin();
2681 insert(static_cast<size_type>(__p), __n, __c);
2682 return begin() + __p;
2683}
2684
2685// replace
2686
2687template <class _CharT, class _Traits, class _Allocator>
2688basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002689basic_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 +00002690{
2691#ifdef _LIBCPP_DEBUG
2692 assert(__s != 0);
2693#endif
2694 size_type __sz = size();
2695 if (__pos > __sz)
2696 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002697 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002698 size_type __cap = capacity();
2699 if (__cap - __sz + __n1 >= __n2)
2700 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002701 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002702 if (__n1 != __n2)
2703 {
2704 size_type __n_move = __sz - __pos - __n1;
2705 if (__n_move != 0)
2706 {
2707 if (__n1 > __n2)
2708 {
2709 traits_type::move(__p + __pos, __s, __n2);
2710 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2711 goto __finish;
2712 }
2713 if (__p + __pos < __s && __s < __p + __sz)
2714 {
2715 if (__p + __pos + __n1 <= __s)
2716 __s += __n2 - __n1;
2717 else // __p + __pos < __s < __p + __pos + __n1
2718 {
2719 traits_type::move(__p + __pos, __s, __n1);
2720 __pos += __n1;
2721 __s += __n2;
2722 __n2 -= __n1;
2723 __n1 = 0;
2724 }
2725 }
2726 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2727 }
2728 }
2729 traits_type::move(__p + __pos, __s, __n2);
2730__finish:
2731 __sz += __n2 - __n1;
2732 __set_size(__sz);
2733 __invalidate_iterators_past(__sz);
2734 traits_type::assign(__p[__sz], value_type());
2735 }
2736 else
2737 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2738 return *this;
2739}
2740
2741template <class _CharT, class _Traits, class _Allocator>
2742basic_string<_CharT, _Traits, _Allocator>&
2743basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
2744{
2745 size_type __sz = size();
2746 if (__pos > __sz)
2747 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002748 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002749 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002750 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002751 if (__cap - __sz + __n1 >= __n2)
2752 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002753 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002754 if (__n1 != __n2)
2755 {
2756 size_type __n_move = __sz - __pos - __n1;
2757 if (__n_move != 0)
2758 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2759 }
2760 }
2761 else
2762 {
2763 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002764 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002765 }
2766 traits_type::assign(__p + __pos, __n2, __c);
2767 __sz += __n2 - __n1;
2768 __set_size(__sz);
2769 __invalidate_iterators_past(__sz);
2770 traits_type::assign(__p[__sz], value_type());
2771 return *this;
2772}
2773
2774template <class _CharT, class _Traits, class _Allocator>
2775template<class _InputIterator>
2776typename enable_if
2777<
2778 __is_input_iterator<_InputIterator>::value,
2779 basic_string<_CharT, _Traits, _Allocator>&
2780>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002781basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002782 _InputIterator __j1, _InputIterator __j2)
2783{
2784 for (; true; ++__i1, ++__j1)
2785 {
2786 if (__i1 == __i2)
2787 {
2788 if (__j1 != __j2)
2789 insert(__i1, __j1, __j2);
2790 break;
2791 }
2792 if (__j1 == __j2)
2793 {
2794 erase(__i1, __i2);
2795 break;
2796 }
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002797 traits_type::assign(const_cast<value_type&>(*__i1), *__j1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002798 }
2799 return *this;
2800}
2801
2802template <class _CharT, class _Traits, class _Allocator>
2803_LIBCPP_INLINE_VISIBILITY inline
2804basic_string<_CharT, _Traits, _Allocator>&
2805basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2806{
2807 return replace(__pos1, __n1, __str.data(), __str.size());
2808}
2809
2810template <class _CharT, class _Traits, class _Allocator>
2811basic_string<_CharT, _Traits, _Allocator>&
2812basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2813 size_type __pos2, size_type __n2)
2814{
2815 size_type __str_sz = __str.size();
2816 if (__pos2 > __str_sz)
2817 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002818 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002819}
2820
2821template <class _CharT, class _Traits, class _Allocator>
2822basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002823basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002824{
2825#ifdef _LIBCPP_DEBUG
2826 assert(__s != 0);
2827#endif
2828 return replace(__pos, __n1, __s, traits_type::length(__s));
2829}
2830
2831template <class _CharT, class _Traits, class _Allocator>
2832_LIBCPP_INLINE_VISIBILITY inline
2833basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002834basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002835{
2836 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2837 __str.data(), __str.size());
2838}
2839
2840template <class _CharT, class _Traits, class _Allocator>
2841_LIBCPP_INLINE_VISIBILITY inline
2842basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002843basic_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 +00002844{
2845 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2846}
2847
2848template <class _CharT, class _Traits, class _Allocator>
2849_LIBCPP_INLINE_VISIBILITY inline
2850basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002851basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002852{
2853 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2854}
2855
2856template <class _CharT, class _Traits, class _Allocator>
2857_LIBCPP_INLINE_VISIBILITY inline
2858basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002859basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002860{
2861 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2862}
2863
2864// erase
2865
2866template <class _CharT, class _Traits, class _Allocator>
2867basic_string<_CharT, _Traits, _Allocator>&
2868basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2869{
2870 size_type __sz = size();
2871 if (__pos > __sz)
2872 this->__throw_out_of_range();
2873 if (__n)
2874 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002875 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002876 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002877 size_type __n_move = __sz - __pos - __n;
2878 if (__n_move != 0)
2879 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2880 __sz -= __n;
2881 __set_size(__sz);
2882 __invalidate_iterators_past(__sz);
2883 traits_type::assign(__p[__sz], value_type());
2884 }
2885 return *this;
2886}
2887
2888template <class _CharT, class _Traits, class _Allocator>
2889_LIBCPP_INLINE_VISIBILITY inline
2890typename basic_string<_CharT, _Traits, _Allocator>::iterator
2891basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2892{
2893 iterator __b = begin();
2894 size_type __r = static_cast<size_type>(__pos - __b);
2895 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00002896 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002897}
2898
2899template <class _CharT, class _Traits, class _Allocator>
2900_LIBCPP_INLINE_VISIBILITY inline
2901typename basic_string<_CharT, _Traits, _Allocator>::iterator
2902basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
2903{
2904 iterator __b = begin();
2905 size_type __r = static_cast<size_type>(__first - __b);
2906 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00002907 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002908}
2909
2910template <class _CharT, class _Traits, class _Allocator>
2911_LIBCPP_INLINE_VISIBILITY inline
2912void
2913basic_string<_CharT, _Traits, _Allocator>::pop_back()
2914{
2915#ifdef _LIBCPP_DEBUG
2916 assert(!empty());
2917#endif
2918 size_type __sz;
2919 if (__is_long())
2920 {
2921 __sz = __get_long_size() - 1;
2922 __set_long_size(__sz);
2923 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
2924 }
2925 else
2926 {
2927 __sz = __get_short_size() - 1;
2928 __set_short_size(__sz);
2929 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
2930 }
2931 __invalidate_iterators_past(__sz);
2932}
2933
2934template <class _CharT, class _Traits, class _Allocator>
2935_LIBCPP_INLINE_VISIBILITY inline
2936void
Howard Hinnanta6119a82011-05-29 19:57:12 +00002937basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002938{
2939 __invalidate_all_iterators();
2940 if (__is_long())
2941 {
2942 traits_type::assign(*__get_long_pointer(), value_type());
2943 __set_long_size(0);
2944 }
2945 else
2946 {
2947 traits_type::assign(*__get_short_pointer(), value_type());
2948 __set_short_size(0);
2949 }
2950}
2951
2952template <class _CharT, class _Traits, class _Allocator>
2953_LIBCPP_INLINE_VISIBILITY inline
2954void
2955basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
2956{
2957 if (__is_long())
2958 {
2959 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
2960 __set_long_size(__pos);
2961 }
2962 else
2963 {
2964 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
2965 __set_short_size(__pos);
2966 }
2967 __invalidate_iterators_past(__pos);
2968}
2969
2970template <class _CharT, class _Traits, class _Allocator>
2971void
2972basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
2973{
2974 size_type __sz = size();
2975 if (__n > __sz)
2976 append(__n - __sz, __c);
2977 else
2978 __erase_to_end(__n);
2979}
2980
2981template <class _CharT, class _Traits, class _Allocator>
2982_LIBCPP_INLINE_VISIBILITY inline
2983typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00002984basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002985{
Howard Hinnante32b5e22010-11-17 17:55:08 +00002986 size_type __m = __alloc_traits::max_size(__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002987#if _LIBCPP_BIG_ENDIAN
2988 return (__m <= ~__long_mask ? __m : __m/2) - 1;
2989#else
2990 return __m - 1;
2991#endif
2992}
2993
2994template <class _CharT, class _Traits, class _Allocator>
2995void
2996basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
2997{
2998 if (__res_arg > max_size())
2999 this->__throw_length_error();
3000 size_type __cap = capacity();
3001 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003002 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003003 __res_arg = __recommend(__res_arg);
3004 if (__res_arg != __cap)
3005 {
3006 pointer __new_data, __p;
3007 bool __was_long, __now_long;
3008 if (__res_arg == __min_cap - 1)
3009 {
3010 __was_long = true;
3011 __now_long = false;
3012 __new_data = __get_short_pointer();
3013 __p = __get_long_pointer();
3014 }
3015 else
3016 {
3017 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003018 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003019 else
3020 {
3021 #ifndef _LIBCPP_NO_EXCEPTIONS
3022 try
3023 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003024 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00003025 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003026 #ifndef _LIBCPP_NO_EXCEPTIONS
3027 }
3028 catch (...)
3029 {
3030 return;
3031 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003032 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003033 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003034 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00003035 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003036 }
3037 __now_long = true;
3038 __was_long = __is_long();
3039 __p = __get_pointer();
3040 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003041 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
3042 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003043 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003044 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003045 if (__now_long)
3046 {
3047 __set_long_cap(__res_arg+1);
3048 __set_long_size(__sz);
3049 __set_long_pointer(__new_data);
3050 }
3051 else
3052 __set_short_size(__sz);
3053 __invalidate_all_iterators();
3054 }
3055}
3056
3057template <class _CharT, class _Traits, class _Allocator>
3058_LIBCPP_INLINE_VISIBILITY inline
3059typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3060basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const
3061{
3062#ifdef __LIBCPP_DEBUG
3063 assert(__pos <= size());
3064#endif
3065 return *(data() + __pos);
3066}
3067
3068template <class _CharT, class _Traits, class _Allocator>
3069_LIBCPP_INLINE_VISIBILITY inline
3070typename basic_string<_CharT, _Traits, _Allocator>::reference
3071basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos)
3072{
3073#ifdef __LIBCPP_DEBUG
3074 assert(__pos < size());
3075#endif
3076 return *(__get_pointer() + __pos);
3077}
3078
3079template <class _CharT, class _Traits, class _Allocator>
3080typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3081basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3082{
3083 if (__n >= size())
3084 this->__throw_out_of_range();
3085 return (*this)[__n];
3086}
3087
3088template <class _CharT, class _Traits, class _Allocator>
3089typename basic_string<_CharT, _Traits, _Allocator>::reference
3090basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3091{
3092 if (__n >= size())
3093 this->__throw_out_of_range();
3094 return (*this)[__n];
3095}
3096
3097template <class _CharT, class _Traits, class _Allocator>
3098_LIBCPP_INLINE_VISIBILITY inline
3099typename basic_string<_CharT, _Traits, _Allocator>::reference
3100basic_string<_CharT, _Traits, _Allocator>::front()
3101{
3102#ifdef _LIBCPP_DEBUG
3103 assert(!empty());
3104#endif
3105 return *__get_pointer();
3106}
3107
3108template <class _CharT, class _Traits, class _Allocator>
3109_LIBCPP_INLINE_VISIBILITY inline
3110typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3111basic_string<_CharT, _Traits, _Allocator>::front() const
3112{
3113#ifdef _LIBCPP_DEBUG
3114 assert(!empty());
3115#endif
3116 return *data();
3117}
3118
3119template <class _CharT, class _Traits, class _Allocator>
3120_LIBCPP_INLINE_VISIBILITY inline
3121typename basic_string<_CharT, _Traits, _Allocator>::reference
3122basic_string<_CharT, _Traits, _Allocator>::back()
3123{
3124#ifdef _LIBCPP_DEBUG
3125 assert(!empty());
3126#endif
3127 return *(__get_pointer() + size() - 1);
3128}
3129
3130template <class _CharT, class _Traits, class _Allocator>
3131_LIBCPP_INLINE_VISIBILITY inline
3132typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3133basic_string<_CharT, _Traits, _Allocator>::back() const
3134{
3135#ifdef _LIBCPP_DEBUG
3136 assert(!empty());
3137#endif
3138 return *(data() + size() - 1);
3139}
3140
3141template <class _CharT, class _Traits, class _Allocator>
3142typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003143basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003144{
3145 size_type __sz = size();
3146 if (__pos > __sz)
3147 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003148 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003149 traits_type::copy(__s, data() + __pos, __rlen);
3150 return __rlen;
3151}
3152
3153template <class _CharT, class _Traits, class _Allocator>
3154_LIBCPP_INLINE_VISIBILITY inline
3155basic_string<_CharT, _Traits, _Allocator>
3156basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3157{
3158 return basic_string(*this, __pos, __n, __alloc());
3159}
3160
3161template <class _CharT, class _Traits, class _Allocator>
3162_LIBCPP_INLINE_VISIBILITY inline
3163void
3164basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00003165 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3166 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003167{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003168 _VSTD::swap(__r_.first(), __str.__r_.first());
Howard Hinnante32b5e22010-11-17 17:55:08 +00003169 __swap_alloc(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003170#ifdef _LIBCPP_DEBUG
3171 __invalidate_all_iterators();
3172 __str.__invalidate_all_iterators();
Howard Hinnant324bb032010-08-22 00:02:43 +00003173#endif // _LIBCPP_DEBUG
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003174}
3175
3176// find
3177
3178template <class _Traits>
3179struct _LIBCPP_HIDDEN __traits_eq
3180{
3181 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003182 _LIBCPP_INLINE_VISIBILITY
3183 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3184 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003185};
3186
3187template<class _CharT, class _Traits, class _Allocator>
3188typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003189basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003190 size_type __pos,
3191 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003192{
3193#ifdef _LIBCPP_DEBUG
3194 assert(__s != 0);
3195#endif
3196 size_type __sz = size();
3197 if (__pos > __sz || __sz - __pos < __n)
3198 return npos;
3199 if (__n == 0)
3200 return __pos;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003201 const value_type* __p = data();
3202 const value_type* __r = _VSTD::search(__p + __pos, __p + __sz, __s, __s + __n,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003203 __traits_eq<traits_type>());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003204 if (__r == __p + __sz)
3205 return npos;
3206 return static_cast<size_type>(__r - __p);
3207}
3208
3209template<class _CharT, class _Traits, class _Allocator>
3210_LIBCPP_INLINE_VISIBILITY inline
3211typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003212basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3213 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003214{
3215 return find(__str.data(), __pos, __str.size());
3216}
3217
3218template<class _CharT, class _Traits, class _Allocator>
3219_LIBCPP_INLINE_VISIBILITY inline
3220typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003221basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003222 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003223{
3224#ifdef _LIBCPP_DEBUG
3225 assert(__s != 0);
3226#endif
3227 return find(__s, __pos, traits_type::length(__s));
3228}
3229
3230template<class _CharT, class _Traits, class _Allocator>
3231typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003232basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3233 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003234{
3235 size_type __sz = size();
3236 if (__pos >= __sz)
3237 return npos;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003238 const value_type* __p = data();
3239 const value_type* __r = traits_type::find(__p + __pos, __sz - __pos, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003240 if (__r == 0)
3241 return npos;
3242 return static_cast<size_type>(__r - __p);
3243}
3244
3245// rfind
3246
3247template<class _CharT, class _Traits, class _Allocator>
3248typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003249basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003250 size_type __pos,
3251 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003252{
3253#ifdef _LIBCPP_DEBUG
3254 assert(__s != 0);
3255#endif
3256 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003257 __pos = _VSTD::min(__pos, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003258 if (__n < __sz - __pos)
3259 __pos += __n;
3260 else
3261 __pos = __sz;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003262 const value_type* __p = data();
3263 const value_type* __r = _VSTD::find_end(__p, __p + __pos, __s, __s + __n,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003264 __traits_eq<traits_type>());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003265 if (__n > 0 && __r == __p + __pos)
3266 return npos;
3267 return static_cast<size_type>(__r - __p);
3268}
3269
3270template<class _CharT, class _Traits, class _Allocator>
3271_LIBCPP_INLINE_VISIBILITY inline
3272typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003273basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3274 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003275{
3276 return rfind(__str.data(), __pos, __str.size());
3277}
3278
3279template<class _CharT, class _Traits, class _Allocator>
3280_LIBCPP_INLINE_VISIBILITY inline
3281typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003282basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003283 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003284{
3285#ifdef _LIBCPP_DEBUG
3286 assert(__s != 0);
3287#endif
3288 return rfind(__s, __pos, traits_type::length(__s));
3289}
3290
3291template<class _CharT, class _Traits, class _Allocator>
3292typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003293basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3294 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003295{
3296 size_type __sz = size();
3297 if (__sz)
3298 {
3299 if (__pos < __sz)
3300 ++__pos;
3301 else
3302 __pos = __sz;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003303 const value_type* __p = data();
3304 for (const value_type* __ps = __p + __pos; __ps != __p;)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003305 {
3306 if (traits_type::eq(*--__ps, __c))
3307 return static_cast<size_type>(__ps - __p);
3308 }
3309 }
3310 return npos;
3311}
3312
3313// find_first_of
3314
3315template<class _CharT, class _Traits, class _Allocator>
3316typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003317basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003318 size_type __pos,
3319 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003320{
3321#ifdef _LIBCPP_DEBUG
3322 assert(__s != 0);
3323#endif
3324 size_type __sz = size();
3325 if (__pos >= __sz || __n == 0)
3326 return npos;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003327 const value_type* __p = data();
3328 const value_type* __r = _VSTD::find_first_of(__p + __pos, __p + __sz, __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003329 __s + __n, __traits_eq<traits_type>());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003330 if (__r == __p + __sz)
3331 return npos;
3332 return static_cast<size_type>(__r - __p);
3333}
3334
3335template<class _CharT, class _Traits, class _Allocator>
3336_LIBCPP_INLINE_VISIBILITY inline
3337typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003338basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3339 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003340{
3341 return find_first_of(__str.data(), __pos, __str.size());
3342}
3343
3344template<class _CharT, class _Traits, class _Allocator>
3345_LIBCPP_INLINE_VISIBILITY inline
3346typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003347basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003348 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003349{
3350#ifdef _LIBCPP_DEBUG
3351 assert(__s != 0);
3352#endif
3353 return find_first_of(__s, __pos, traits_type::length(__s));
3354}
3355
3356template<class _CharT, class _Traits, class _Allocator>
3357_LIBCPP_INLINE_VISIBILITY inline
3358typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003359basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3360 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003361{
3362 return find(__c, __pos);
3363}
3364
3365// find_last_of
3366
3367template<class _CharT, class _Traits, class _Allocator>
3368typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003369basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003370 size_type __pos,
3371 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003372{
3373#ifdef _LIBCPP_DEBUG
3374 assert(__s != 0);
3375#endif
3376 if (__n != 0)
3377 {
3378 size_type __sz = size();
3379 if (__pos < __sz)
3380 ++__pos;
3381 else
3382 __pos = __sz;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003383 const value_type* __p = data();
3384 for (const value_type* __ps = __p + __pos; __ps != __p;)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003385 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003386 const value_type* __r = traits_type::find(__s, __n, *--__ps);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003387 if (__r)
3388 return static_cast<size_type>(__ps - __p);
3389 }
3390 }
3391 return npos;
3392}
3393
3394template<class _CharT, class _Traits, class _Allocator>
3395_LIBCPP_INLINE_VISIBILITY inline
3396typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003397basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3398 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003399{
3400 return find_last_of(__str.data(), __pos, __str.size());
3401}
3402
3403template<class _CharT, class _Traits, class _Allocator>
3404_LIBCPP_INLINE_VISIBILITY inline
3405typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003406basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003407 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003408{
3409#ifdef _LIBCPP_DEBUG
3410 assert(__s != 0);
3411#endif
3412 return find_last_of(__s, __pos, traits_type::length(__s));
3413}
3414
3415template<class _CharT, class _Traits, class _Allocator>
3416_LIBCPP_INLINE_VISIBILITY inline
3417typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003418basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3419 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003420{
3421 return rfind(__c, __pos);
3422}
3423
3424// find_first_not_of
3425
3426template<class _CharT, class _Traits, class _Allocator>
3427typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003428basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003429 size_type __pos,
3430 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003431{
3432#ifdef _LIBCPP_DEBUG
3433 assert(__s != 0);
3434#endif
3435 size_type __sz = size();
3436 if (__pos < __sz)
3437 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003438 const value_type* __p = data();
3439 const value_type* __pe = __p + __sz;
3440 for (const value_type* __ps = __p + __pos; __ps != __pe; ++__ps)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003441 if (traits_type::find(__s, __n, *__ps) == 0)
3442 return static_cast<size_type>(__ps - __p);
3443 }
3444 return npos;
3445}
3446
3447template<class _CharT, class _Traits, class _Allocator>
3448_LIBCPP_INLINE_VISIBILITY inline
3449typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003450basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3451 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003452{
3453 return find_first_not_of(__str.data(), __pos, __str.size());
3454}
3455
3456template<class _CharT, class _Traits, class _Allocator>
3457_LIBCPP_INLINE_VISIBILITY inline
3458typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003459basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003460 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003461{
3462#ifdef _LIBCPP_DEBUG
3463 assert(__s != 0);
3464#endif
3465 return find_first_not_of(__s, __pos, traits_type::length(__s));
3466}
3467
3468template<class _CharT, class _Traits, class _Allocator>
3469_LIBCPP_INLINE_VISIBILITY inline
3470typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003471basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3472 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003473{
3474 size_type __sz = size();
3475 if (__pos < __sz)
3476 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003477 const value_type* __p = data();
3478 const value_type* __pe = __p + __sz;
3479 for (const value_type* __ps = __p + __pos; __ps != __pe; ++__ps)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003480 if (!traits_type::eq(*__ps, __c))
3481 return static_cast<size_type>(__ps - __p);
3482 }
3483 return npos;
3484}
3485
3486// find_last_not_of
3487
3488template<class _CharT, class _Traits, class _Allocator>
3489typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003490basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003491 size_type __pos,
3492 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003493{
3494#ifdef _LIBCPP_DEBUG
3495 assert(__s != 0);
3496#endif
3497 size_type __sz = size();
3498 if (__pos < __sz)
3499 ++__pos;
3500 else
3501 __pos = __sz;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003502 const value_type* __p = data();
3503 for (const value_type* __ps = __p + __pos; __ps != __p;)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003504 if (traits_type::find(__s, __n, *--__ps) == 0)
3505 return static_cast<size_type>(__ps - __p);
3506 return npos;
3507}
3508
3509template<class _CharT, class _Traits, class _Allocator>
3510_LIBCPP_INLINE_VISIBILITY inline
3511typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003512basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3513 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003514{
3515 return find_last_not_of(__str.data(), __pos, __str.size());
3516}
3517
3518template<class _CharT, class _Traits, class _Allocator>
3519_LIBCPP_INLINE_VISIBILITY inline
3520typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003521basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003522 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003523{
3524#ifdef _LIBCPP_DEBUG
3525 assert(__s != 0);
3526#endif
3527 return find_last_not_of(__s, __pos, traits_type::length(__s));
3528}
3529
3530template<class _CharT, class _Traits, class _Allocator>
3531_LIBCPP_INLINE_VISIBILITY inline
3532typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003533basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3534 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003535{
3536 size_type __sz = size();
3537 if (__pos < __sz)
3538 ++__pos;
3539 else
3540 __pos = __sz;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003541 const value_type* __p = data();
3542 for (const value_type* __ps = __p + __pos; __ps != __p;)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003543 if (!traits_type::eq(*--__ps, __c))
3544 return static_cast<size_type>(__ps - __p);
3545 return npos;
3546}
3547
3548// compare
3549
3550template <class _CharT, class _Traits, class _Allocator>
3551_LIBCPP_INLINE_VISIBILITY inline
3552int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003553basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003554{
Howard Hinnantfa06d752011-07-24 21:45:06 +00003555 size_t __lhs_sz = size();
3556 size_t __rhs_sz = __str.size();
3557 int __result = traits_type::compare(data(), __str.data(),
3558 _VSTD::min(__lhs_sz, __rhs_sz));
3559 if (__result != 0)
3560 return __result;
3561 if (__lhs_sz < __rhs_sz)
3562 return -1;
3563 if (__lhs_sz > __rhs_sz)
3564 return 1;
3565 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003566}
3567
3568template <class _CharT, class _Traits, class _Allocator>
3569_LIBCPP_INLINE_VISIBILITY inline
3570int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003571basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3572 size_type __n1,
3573 const basic_string& __str) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003574{
3575 return compare(__pos1, __n1, __str.data(), __str.size());
3576}
3577
3578template <class _CharT, class _Traits, class _Allocator>
3579int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003580basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3581 size_type __n1,
3582 const basic_string& __str,
3583 size_type __pos2,
3584 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003585{
3586 size_type __sz = __str.size();
3587 if (__pos2 > __sz)
3588 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003589 return compare(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003590 __sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003591}
3592
3593template <class _CharT, class _Traits, class _Allocator>
3594int
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003595basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003596{
3597#ifdef _LIBCPP_DEBUG
3598 assert(__s != 0);
3599#endif
3600 return compare(0, npos, __s, traits_type::length(__s));
3601}
3602
3603template <class _CharT, class _Traits, class _Allocator>
3604int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003605basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3606 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003607 const value_type* __s) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003608{
3609#ifdef _LIBCPP_DEBUG
3610 assert(__s != 0);
3611#endif
3612 return compare(__pos1, __n1, __s, traits_type::length(__s));
3613}
3614
3615template <class _CharT, class _Traits, class _Allocator>
3616int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003617basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3618 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003619 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003620 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003621{
3622#ifdef _LIBCPP_DEBUG
3623 assert(__s != 0);
3624#endif
3625 size_type __sz = size();
3626 if (__pos1 > __sz || __n2 == npos)
3627 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003628 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3629 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003630 if (__r == 0)
3631 {
3632 if (__rlen < __n2)
3633 __r = -1;
3634 else if (__rlen > __n2)
3635 __r = 1;
3636 }
3637 return __r;
3638}
3639
3640// __invariants
3641
3642template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00003643_LIBCPP_INLINE_VISIBILITY inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003644bool
3645basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3646{
3647 if (size() > capacity())
3648 return false;
3649 if (capacity() < __min_cap - 1)
3650 return false;
3651 if (data() == 0)
3652 return false;
3653 if (data()[size()] != value_type(0))
3654 return false;
3655 return true;
3656}
3657
3658// operator==
3659
3660template<class _CharT, class _Traits, class _Allocator>
3661_LIBCPP_INLINE_VISIBILITY inline
3662bool
3663operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003664 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003665{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003666 size_t __lhs_sz = __lhs.size();
3667 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3668 __rhs.data(),
3669 __lhs_sz) == 0;
3670}
3671
3672template<class _Allocator>
3673_LIBCPP_INLINE_VISIBILITY inline
3674bool
3675operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3676 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3677{
3678 size_t __lhs_sz = __lhs.size();
3679 if (__lhs_sz != __rhs.size())
3680 return false;
3681 const char* __lp = __lhs.data();
3682 const char* __rp = __rhs.data();
3683 if (__lhs.__is_long())
3684 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3685 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3686 if (*__lp != *__rp)
3687 return false;
3688 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003689}
3690
3691template<class _CharT, class _Traits, class _Allocator>
3692_LIBCPP_INLINE_VISIBILITY inline
3693bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003694operator==(const _CharT* __lhs,
3695 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003696{
3697 return __rhs.compare(__lhs) == 0;
3698}
3699
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003700template<class _CharT, class _Traits, class _Allocator>
3701_LIBCPP_INLINE_VISIBILITY inline
3702bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003703operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3704 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003705{
3706 return __lhs.compare(__rhs) == 0;
3707}
3708
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003709// operator!=
3710
Howard Hinnant324bb032010-08-22 00:02:43 +00003711template<class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003712_LIBCPP_INLINE_VISIBILITY inline
3713bool
3714operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003715 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003716{
3717 return !(__lhs == __rhs);
3718}
3719
3720template<class _CharT, class _Traits, class _Allocator>
3721_LIBCPP_INLINE_VISIBILITY inline
3722bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003723operator!=(const _CharT* __lhs,
3724 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003725{
3726 return !(__lhs == __rhs);
3727}
3728
3729template<class _CharT, class _Traits, class _Allocator>
3730_LIBCPP_INLINE_VISIBILITY inline
3731bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003732operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3733 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003734{
3735 return !(__lhs == __rhs);
3736}
3737
3738// operator<
3739
3740template<class _CharT, class _Traits, class _Allocator>
3741_LIBCPP_INLINE_VISIBILITY inline
3742bool
3743operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003744 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003745{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003746 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003747}
3748
3749template<class _CharT, class _Traits, class _Allocator>
3750_LIBCPP_INLINE_VISIBILITY inline
3751bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003752operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3753 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003754{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003755 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003756}
3757
3758template<class _CharT, class _Traits, class _Allocator>
3759_LIBCPP_INLINE_VISIBILITY inline
3760bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003761operator< (const _CharT* __lhs,
3762 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003763{
3764 return __rhs.compare(__lhs) > 0;
3765}
3766
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003767// operator>
3768
3769template<class _CharT, class _Traits, class _Allocator>
3770_LIBCPP_INLINE_VISIBILITY inline
3771bool
3772operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003773 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003774{
3775 return __rhs < __lhs;
3776}
3777
3778template<class _CharT, class _Traits, class _Allocator>
3779_LIBCPP_INLINE_VISIBILITY inline
3780bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003781operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3782 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003783{
3784 return __rhs < __lhs;
3785}
3786
3787template<class _CharT, class _Traits, class _Allocator>
3788_LIBCPP_INLINE_VISIBILITY inline
3789bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003790operator> (const _CharT* __lhs,
3791 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003792{
3793 return __rhs < __lhs;
3794}
3795
3796// operator<=
3797
3798template<class _CharT, class _Traits, class _Allocator>
3799_LIBCPP_INLINE_VISIBILITY inline
3800bool
3801operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003802 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003803{
3804 return !(__rhs < __lhs);
3805}
3806
3807template<class _CharT, class _Traits, class _Allocator>
3808_LIBCPP_INLINE_VISIBILITY inline
3809bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003810operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3811 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003812{
3813 return !(__rhs < __lhs);
3814}
3815
3816template<class _CharT, class _Traits, class _Allocator>
3817_LIBCPP_INLINE_VISIBILITY inline
3818bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003819operator<=(const _CharT* __lhs,
3820 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003821{
3822 return !(__rhs < __lhs);
3823}
3824
3825// operator>=
3826
3827template<class _CharT, class _Traits, class _Allocator>
3828_LIBCPP_INLINE_VISIBILITY inline
3829bool
3830operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003831 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003832{
3833 return !(__lhs < __rhs);
3834}
3835
3836template<class _CharT, class _Traits, class _Allocator>
3837_LIBCPP_INLINE_VISIBILITY inline
3838bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003839operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3840 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003841{
3842 return !(__lhs < __rhs);
3843}
3844
3845template<class _CharT, class _Traits, class _Allocator>
3846_LIBCPP_INLINE_VISIBILITY inline
3847bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003848operator>=(const _CharT* __lhs,
3849 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003850{
3851 return !(__lhs < __rhs);
3852}
3853
3854// operator +
3855
3856template<class _CharT, class _Traits, class _Allocator>
3857basic_string<_CharT, _Traits, _Allocator>
3858operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3859 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3860{
3861 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3862 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3863 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3864 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3865 __r.append(__rhs.data(), __rhs_sz);
3866 return __r;
3867}
3868
3869template<class _CharT, class _Traits, class _Allocator>
3870basic_string<_CharT, _Traits, _Allocator>
3871operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3872{
3873 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3874 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
3875 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3876 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
3877 __r.append(__rhs.data(), __rhs_sz);
3878 return __r;
3879}
3880
3881template<class _CharT, class _Traits, class _Allocator>
3882basic_string<_CharT, _Traits, _Allocator>
3883operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3884{
3885 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3886 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3887 __r.__init(&__lhs, 1, 1 + __rhs_sz);
3888 __r.append(__rhs.data(), __rhs_sz);
3889 return __r;
3890}
3891
3892template<class _CharT, class _Traits, class _Allocator>
3893basic_string<_CharT, _Traits, _Allocator>
3894operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
3895{
3896 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3897 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3898 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
3899 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3900 __r.append(__rhs, __rhs_sz);
3901 return __r;
3902}
3903
3904template<class _CharT, class _Traits, class _Allocator>
3905basic_string<_CharT, _Traits, _Allocator>
3906operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
3907{
3908 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3909 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3910 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
3911 __r.push_back(__rhs);
3912 return __r;
3913}
3914
Howard Hinnant73d21a42010-09-04 23:28:19 +00003915#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003916
3917template<class _CharT, class _Traits, class _Allocator>
3918_LIBCPP_INLINE_VISIBILITY inline
3919basic_string<_CharT, _Traits, _Allocator>
3920operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3921{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003922 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003923}
3924
3925template<class _CharT, class _Traits, class _Allocator>
3926_LIBCPP_INLINE_VISIBILITY inline
3927basic_string<_CharT, _Traits, _Allocator>
3928operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3929{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003930 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003931}
3932
3933template<class _CharT, class _Traits, class _Allocator>
3934_LIBCPP_INLINE_VISIBILITY inline
3935basic_string<_CharT, _Traits, _Allocator>
3936operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3937{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003938 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003939}
3940
3941template<class _CharT, class _Traits, class _Allocator>
3942_LIBCPP_INLINE_VISIBILITY inline
3943basic_string<_CharT, _Traits, _Allocator>
3944operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3945{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003946 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003947}
3948
3949template<class _CharT, class _Traits, class _Allocator>
3950_LIBCPP_INLINE_VISIBILITY inline
3951basic_string<_CharT, _Traits, _Allocator>
3952operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3953{
3954 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003955 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003956}
3957
3958template<class _CharT, class _Traits, class _Allocator>
3959_LIBCPP_INLINE_VISIBILITY inline
3960basic_string<_CharT, _Traits, _Allocator>
3961operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
3962{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003963 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003964}
3965
3966template<class _CharT, class _Traits, class _Allocator>
3967_LIBCPP_INLINE_VISIBILITY inline
3968basic_string<_CharT, _Traits, _Allocator>
3969operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
3970{
3971 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003972 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003973}
3974
Howard Hinnant73d21a42010-09-04 23:28:19 +00003975#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003976
3977// swap
3978
3979template<class _CharT, class _Traits, class _Allocator>
3980_LIBCPP_INLINE_VISIBILITY inline
3981void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003982swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00003983 basic_string<_CharT, _Traits, _Allocator>& __rhs)
3984 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003985{
3986 __lhs.swap(__rhs);
3987}
3988
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003989#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
3990
3991typedef basic_string<char16_t> u16string;
3992typedef basic_string<char32_t> u32string;
3993
Howard Hinnant324bb032010-08-22 00:02:43 +00003994#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003995
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003996int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
3997long stol (const string& __str, size_t* __idx = 0, int __base = 10);
3998unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
3999long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4000unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
4001
4002float stof (const string& __str, size_t* __idx = 0);
4003double stod (const string& __str, size_t* __idx = 0);
4004long double stold(const string& __str, size_t* __idx = 0);
4005
4006string to_string(int __val);
4007string to_string(unsigned __val);
4008string to_string(long __val);
4009string to_string(unsigned long __val);
4010string to_string(long long __val);
4011string to_string(unsigned long long __val);
4012string to_string(float __val);
4013string to_string(double __val);
4014string to_string(long double __val);
4015
4016int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4017long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4018unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4019long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4020unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
4021
4022float stof (const wstring& __str, size_t* __idx = 0);
4023double stod (const wstring& __str, size_t* __idx = 0);
4024long double stold(const wstring& __str, size_t* __idx = 0);
4025
4026wstring to_wstring(int __val);
4027wstring to_wstring(unsigned __val);
4028wstring to_wstring(long __val);
4029wstring to_wstring(unsigned long __val);
4030wstring to_wstring(long long __val);
4031wstring to_wstring(unsigned long long __val);
4032wstring to_wstring(float __val);
4033wstring to_wstring(double __val);
4034wstring to_wstring(long double __val);
4035
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004036template<class _CharT, class _Traits, class _Allocator>
4037 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4038 basic_string<_CharT, _Traits, _Allocator>::npos;
4039
Sean Huntaffd9e52011-07-29 23:31:56 +00004040template<class _Ptr>
4041size_t _LIBCPP_INLINE_VISIBILITY __do_string_hash(_Ptr __p, _Ptr __e)
4042{
Howard Hinnant40c13d32011-12-05 00:08:45 +00004043 typedef typename iterator_traits<_Ptr>::value_type value_type;
Howard Hinnantc00f75d2011-12-10 20:28:56 +00004044 return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));
Sean Huntaffd9e52011-07-29 23:31:56 +00004045}
4046
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004047template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant83eade62013-03-06 23:30:19 +00004048struct _LIBCPP_TYPE_VIS hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004049 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
4050{
4051 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00004052 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004053};
4054
4055template<class _CharT, class _Traits, class _Allocator>
4056size_t
4057hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00004058 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004059{
Sean Huntaffd9e52011-07-29 23:31:56 +00004060 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004061}
4062
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004063template<class _CharT, class _Traits, class _Allocator>
4064basic_ostream<_CharT, _Traits>&
4065operator<<(basic_ostream<_CharT, _Traits>& __os,
4066 const basic_string<_CharT, _Traits, _Allocator>& __str);
4067
4068template<class _CharT, class _Traits, class _Allocator>
4069basic_istream<_CharT, _Traits>&
4070operator>>(basic_istream<_CharT, _Traits>& __is,
4071 basic_string<_CharT, _Traits, _Allocator>& __str);
4072
4073template<class _CharT, class _Traits, class _Allocator>
4074basic_istream<_CharT, _Traits>&
4075getline(basic_istream<_CharT, _Traits>& __is,
4076 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4077
4078template<class _CharT, class _Traits, class _Allocator>
4079inline _LIBCPP_INLINE_VISIBILITY
4080basic_istream<_CharT, _Traits>&
4081getline(basic_istream<_CharT, _Traits>& __is,
4082 basic_string<_CharT, _Traits, _Allocator>& __str);
4083
4084#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4085
4086template<class _CharT, class _Traits, class _Allocator>
4087inline _LIBCPP_INLINE_VISIBILITY
4088basic_istream<_CharT, _Traits>&
4089getline(basic_istream<_CharT, _Traits>&& __is,
4090 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4091
4092template<class _CharT, class _Traits, class _Allocator>
4093inline _LIBCPP_INLINE_VISIBILITY
4094basic_istream<_CharT, _Traits>&
4095getline(basic_istream<_CharT, _Traits>&& __is,
4096 basic_string<_CharT, _Traits, _Allocator>& __str);
4097
4098#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4099
Howard Hinnantff926772012-11-06 21:08:48 +00004100_LIBCPP_EXTERN_TEMPLATE(class basic_string<char>)
4101_LIBCPP_EXTERN_TEMPLATE(class basic_string<wchar_t>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004102
4103extern template
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004104 string
4105 operator+<char, char_traits<char>, allocator<char> >(char const*, string const&);
4106
4107_LIBCPP_END_NAMESPACE_STD
4108
4109#endif // _LIBCPP_STRING