blob: 9b391d1d20d956ca68d0502ee02d4364b7e52883 [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);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000164 basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
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);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000181 basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
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);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000192 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000193 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,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000207 size_type pos2, size_type n2=npos); // C++14
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,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000264 size_type pos2, size_type n2=npos) const; // C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000265 int compare(const value_type* s) const noexcept;
266 int compare(size_type pos1, size_type n1, const value_type* s) const;
267 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000268
269 bool __invariants() const;
270};
271
272template<class charT, class traits, class Allocator>
273basic_string<charT, traits, Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000274operator+(const basic_string<charT, traits, Allocator>& lhs,
275 const basic_string<charT, traits, Allocator>& rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000276
277template<class charT, class traits, class Allocator>
278basic_string<charT, traits, Allocator>
279operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
280
281template<class charT, class traits, class Allocator>
282basic_string<charT, traits, Allocator>
283operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
284
285template<class charT, class traits, class Allocator>
286basic_string<charT, traits, Allocator>
287operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
288
289template<class charT, class traits, class Allocator>
290basic_string<charT, traits, Allocator>
291operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
292
293template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000294bool operator==(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000295 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000296
297template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000298bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000299
300template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000301bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000302
Howard Hinnant324bb032010-08-22 00:02:43 +0000303template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000304bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000305 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000306
307template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000308bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000309
310template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000311bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000312
313template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000314bool operator< (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000315 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000316
317template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000318bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000319
320template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000321bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000322
323template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000324bool operator> (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000325 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000326
327template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000328bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000329
330template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000331bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000332
333template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000334bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000335 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000336
337template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000338bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000339
340template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000341bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000342
343template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000344bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000345 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000346
347template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000348bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000349
350template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000351bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000352
353template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000354void swap(basic_string<charT, traits, Allocator>& lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000355 basic_string<charT, traits, Allocator>& rhs)
356 noexcept(noexcept(lhs.swap(rhs)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000357
358template<class charT, class traits, class Allocator>
359basic_istream<charT, traits>&
360operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
361
362template<class charT, class traits, class Allocator>
363basic_ostream<charT, traits>&
364operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
365
366template<class charT, class traits, class Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +0000367basic_istream<charT, traits>&
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000368getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
369 charT delim);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000370
371template<class charT, class traits, class Allocator>
372basic_istream<charT, traits>&
373getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
374
375typedef basic_string<char> string;
376typedef basic_string<wchar_t> wstring;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000377typedef basic_string<char16_t> u16string;
378typedef basic_string<char32_t> u32string;
379
380int stoi (const string& str, size_t* idx = 0, int base = 10);
381long stol (const string& str, size_t* idx = 0, int base = 10);
382unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
383long long stoll (const string& str, size_t* idx = 0, int base = 10);
384unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
385
386float stof (const string& str, size_t* idx = 0);
387double stod (const string& str, size_t* idx = 0);
388long double stold(const string& str, size_t* idx = 0);
389
390string to_string(int val);
391string to_string(unsigned val);
392string to_string(long val);
393string to_string(unsigned long val);
394string to_string(long long val);
395string to_string(unsigned long long val);
396string to_string(float val);
397string to_string(double val);
398string to_string(long double val);
399
400int stoi (const wstring& str, size_t* idx = 0, int base = 10);
401long stol (const wstring& str, size_t* idx = 0, int base = 10);
402unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
403long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
404unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
405
406float stof (const wstring& str, size_t* idx = 0);
407double stod (const wstring& str, size_t* idx = 0);
408long double stold(const wstring& str, size_t* idx = 0);
409
410wstring to_wstring(int val);
411wstring to_wstring(unsigned val);
412wstring to_wstring(long val);
413wstring to_wstring(unsigned long val);
414wstring to_wstring(long long val);
415wstring to_wstring(unsigned long long val);
416wstring to_wstring(float val);
417wstring to_wstring(double val);
418wstring to_wstring(long double val);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000419
420template <> struct hash<string>;
421template <> struct hash<u16string>;
422template <> struct hash<u32string>;
423template <> struct hash<wstring>;
424
Marshall Clow15234322013-07-23 17:05:24 +0000425basic_string<char> operator "" s( const char *str, size_t len ); // C++14
426basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
427basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
428basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
429
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000430} // std
431
432*/
433
434#include <__config>
435#include <iosfwd>
436#include <cstring>
Howard Hinnantadff4892010-05-24 17:49:41 +0000437#include <cstdio> // For EOF.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000438#include <cwchar>
439#include <algorithm>
440#include <iterator>
441#include <utility>
442#include <memory>
443#include <stdexcept>
444#include <type_traits>
445#include <initializer_list>
446#include <__functional_base>
447#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
448#include <cstdint>
449#endif
Howard Hinnant499cea12013-08-23 17:37:05 +0000450#if defined(_LIBCPP_NO_EXCEPTIONS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000451#include <cassert>
452#endif
453
Howard Hinnant66c6f972011-11-29 16:45:27 +0000454#include <__undef_min_max>
455
Howard Hinnant08e17472011-10-17 20:05:10 +0000456#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000457#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000458#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000459
460_LIBCPP_BEGIN_NAMESPACE_STD
461
462// fpos
463
464template <class _StateT>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000465class _LIBCPP_TYPE_VIS_ONLY fpos
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000466{
467private:
468 _StateT __st_;
469 streamoff __off_;
470public:
471 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
472
473 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
474
475 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
476 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
477
478 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
479 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
480 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
481 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
482};
483
484template <class _StateT>
485inline _LIBCPP_INLINE_VISIBILITY
486streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
487 {return streamoff(__x) - streamoff(__y);}
488
489template <class _StateT>
490inline _LIBCPP_INLINE_VISIBILITY
491bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
492 {return streamoff(__x) == streamoff(__y);}
493
494template <class _StateT>
495inline _LIBCPP_INLINE_VISIBILITY
496bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
497 {return streamoff(__x) != streamoff(__y);}
498
499// char_traits
500
501template <class _CharT>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000502struct _LIBCPP_TYPE_VIS_ONLY char_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000503{
504 typedef _CharT char_type;
505 typedef int int_type;
506 typedef streamoff off_type;
507 typedef streampos pos_type;
508 typedef mbstate_t state_type;
509
Howard Hinnanta6119a82011-05-29 19:57:12 +0000510 _LIBCPP_INLINE_VISIBILITY
511 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
512 {__c1 = __c2;}
513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000514 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000515 {return __c1 == __c2;}
516 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000517 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000518 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000519
520 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
521 static size_t length(const char_type* __s);
522 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
523 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
524 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
525 static char_type* assign(char_type* __s, size_t __n, char_type __a);
526
Howard Hinnant03d71812012-07-20 19:09:12 +0000527 _LIBCPP_INLINE_VISIBILITY
528 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000529 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000530 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000531 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000532 {return char_type(__c);}
533 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000534 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000535 {return int_type(__c);}
536 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000537 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000538 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000539 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000540 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000541 {return int_type(EOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000542};
543
544template <class _CharT>
545int
546char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
547{
548 for (; __n; --__n, ++__s1, ++__s2)
549 {
550 if (lt(*__s1, *__s2))
551 return -1;
552 if (lt(*__s2, *__s1))
553 return 1;
554 }
555 return 0;
556}
557
558template <class _CharT>
559inline _LIBCPP_INLINE_VISIBILITY
560size_t
561char_traits<_CharT>::length(const char_type* __s)
562{
563 size_t __len = 0;
564 for (; !eq(*__s, char_type(0)); ++__s)
565 ++__len;
566 return __len;
567}
568
569template <class _CharT>
570inline _LIBCPP_INLINE_VISIBILITY
571const _CharT*
572char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a)
573{
574 for (; __n; --__n)
575 {
576 if (eq(*__s, __a))
577 return __s;
578 ++__s;
579 }
580 return 0;
581}
582
583template <class _CharT>
584_CharT*
585char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n)
586{
587 char_type* __r = __s1;
588 if (__s1 < __s2)
589 {
590 for (; __n; --__n, ++__s1, ++__s2)
591 assign(*__s1, *__s2);
592 }
593 else if (__s2 < __s1)
594 {
595 __s1 += __n;
596 __s2 += __n;
597 for (; __n; --__n)
598 assign(*--__s1, *--__s2);
599 }
600 return __r;
601}
602
603template <class _CharT>
604inline _LIBCPP_INLINE_VISIBILITY
605_CharT*
606char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
607{
Howard Hinnant499cea12013-08-23 17:37:05 +0000608 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000609 char_type* __r = __s1;
610 for (; __n; --__n, ++__s1, ++__s2)
611 assign(*__s1, *__s2);
612 return __r;
613}
614
615template <class _CharT>
616inline _LIBCPP_INLINE_VISIBILITY
617_CharT*
618char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
619{
620 char_type* __r = __s;
621 for (; __n; --__n, ++__s)
622 assign(*__s, __a);
623 return __r;
624}
625
626// char_traits<char>
627
628template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000629struct _LIBCPP_TYPE_VIS_ONLY char_traits<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000630{
631 typedef char char_type;
632 typedef int int_type;
633 typedef streamoff off_type;
634 typedef streampos pos_type;
635 typedef mbstate_t state_type;
636
Howard Hinnanta6119a82011-05-29 19:57:12 +0000637 _LIBCPP_INLINE_VISIBILITY
638 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
639 {__c1 = __c2;}
640 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000641 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000642 {return __c1 == __c2;}
643 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000644 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000645 {return (unsigned char)__c1 < (unsigned char)__c2;}
646
Howard Hinnanta6119a82011-05-29 19:57:12 +0000647 _LIBCPP_INLINE_VISIBILITY
648 static int compare(const char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000649 {return memcmp(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000650 _LIBCPP_INLINE_VISIBILITY
651 static size_t length(const char_type* __s) {return strlen(__s);}
652 _LIBCPP_INLINE_VISIBILITY
653 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000654 {return (const char_type*)memchr(__s, to_int_type(__a), __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000655 _LIBCPP_INLINE_VISIBILITY
656 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000657 {return (char_type*)memmove(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000658 _LIBCPP_INLINE_VISIBILITY
659 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnant499cea12013-08-23 17:37:05 +0000660 {
661 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
662 return (char_type*)memcpy(__s1, __s2, __n);
663 }
Howard Hinnanta6119a82011-05-29 19:57:12 +0000664 _LIBCPP_INLINE_VISIBILITY
665 static char_type* assign(char_type* __s, size_t __n, char_type __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000666 {return (char_type*)memset(__s, to_int_type(__a), __n);}
667
Howard Hinnant03d71812012-07-20 19:09:12 +0000668 _LIBCPP_INLINE_VISIBILITY
669 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000670 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000671 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000672 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000673 {return char_type(__c);}
674 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000675 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000676 {return int_type((unsigned char)__c);}
677 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000678 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000679 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000681 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000682 {return int_type(EOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000683};
684
685// char_traits<wchar_t>
686
687template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000688struct _LIBCPP_TYPE_VIS_ONLY char_traits<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000689{
690 typedef wchar_t char_type;
691 typedef wint_t int_type;
692 typedef streamoff off_type;
693 typedef streampos pos_type;
694 typedef mbstate_t state_type;
695
Howard Hinnanta6119a82011-05-29 19:57:12 +0000696 _LIBCPP_INLINE_VISIBILITY
697 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
698 {__c1 = __c2;}
699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000700 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000701 {return __c1 == __c2;}
702 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000703 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000704 {return __c1 < __c2;}
705
Howard Hinnanta6119a82011-05-29 19:57:12 +0000706 _LIBCPP_INLINE_VISIBILITY
707 static int compare(const char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000708 {return wmemcmp(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000709 _LIBCPP_INLINE_VISIBILITY
710 static size_t length(const char_type* __s)
711 {return wcslen(__s);}
712 _LIBCPP_INLINE_VISIBILITY
713 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000714 {return (const char_type*)wmemchr(__s, __a, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000715 _LIBCPP_INLINE_VISIBILITY
716 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000717 {return (char_type*)wmemmove(__s1, __s2, __n);}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000718 _LIBCPP_INLINE_VISIBILITY
719 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnant499cea12013-08-23 17:37:05 +0000720 {
721 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
722 return (char_type*)wmemcpy(__s1, __s2, __n);
723 }
Howard Hinnanta6119a82011-05-29 19:57:12 +0000724 _LIBCPP_INLINE_VISIBILITY
725 static char_type* assign(char_type* __s, size_t __n, char_type __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000726 {return (char_type*)wmemset(__s, __a, __n);}
727
Howard Hinnanta6119a82011-05-29 19:57:12 +0000728 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000729 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000730 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000731 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000732 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000733 {return char_type(__c);}
734 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000735 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000736 {return int_type(__c);}
737 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000738 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000739 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000740 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000741 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000742 {return int_type(WEOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000743};
744
745#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
746
747template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000748struct _LIBCPP_TYPE_VIS_ONLY char_traits<char16_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000749{
750 typedef char16_t char_type;
751 typedef uint_least16_t int_type;
752 typedef streamoff off_type;
753 typedef u16streampos pos_type;
754 typedef mbstate_t state_type;
755
Howard Hinnanta6119a82011-05-29 19:57:12 +0000756 _LIBCPP_INLINE_VISIBILITY
757 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
758 {__c1 = __c2;}
759 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000760 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000761 {return __c1 == __c2;}
762 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000763 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000764 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000765
766 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
767 static size_t length(const char_type* __s);
768 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
769 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
770 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
771 static char_type* assign(char_type* __s, size_t __n, char_type __a);
772
Howard Hinnanta6119a82011-05-29 19:57:12 +0000773 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000774 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000775 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000776 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000777 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000778 {return char_type(__c);}
779 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000780 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000781 {return int_type(__c);}
782 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000783 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000784 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000785 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000786 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000787 {return int_type(0xDFFF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000788};
789
790inline _LIBCPP_INLINE_VISIBILITY
791int
792char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
793{
794 for (; __n; --__n, ++__s1, ++__s2)
795 {
796 if (lt(*__s1, *__s2))
797 return -1;
798 if (lt(*__s2, *__s1))
799 return 1;
800 }
801 return 0;
802}
803
804inline _LIBCPP_INLINE_VISIBILITY
805size_t
806char_traits<char16_t>::length(const char_type* __s)
807{
808 size_t __len = 0;
809 for (; !eq(*__s, char_type(0)); ++__s)
810 ++__len;
811 return __len;
812}
813
814inline _LIBCPP_INLINE_VISIBILITY
815const char16_t*
816char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a)
817{
818 for (; __n; --__n)
819 {
820 if (eq(*__s, __a))
821 return __s;
822 ++__s;
823 }
824 return 0;
825}
826
827inline _LIBCPP_INLINE_VISIBILITY
828char16_t*
829char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
830{
831 char_type* __r = __s1;
832 if (__s1 < __s2)
833 {
834 for (; __n; --__n, ++__s1, ++__s2)
835 assign(*__s1, *__s2);
836 }
837 else if (__s2 < __s1)
838 {
839 __s1 += __n;
840 __s2 += __n;
841 for (; __n; --__n)
842 assign(*--__s1, *--__s2);
843 }
844 return __r;
845}
846
847inline _LIBCPP_INLINE_VISIBILITY
848char16_t*
849char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
850{
Howard Hinnant499cea12013-08-23 17:37:05 +0000851 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000852 char_type* __r = __s1;
853 for (; __n; --__n, ++__s1, ++__s2)
854 assign(*__s1, *__s2);
855 return __r;
856}
857
858inline _LIBCPP_INLINE_VISIBILITY
859char16_t*
860char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a)
861{
862 char_type* __r = __s;
863 for (; __n; --__n, ++__s)
864 assign(*__s, __a);
865 return __r;
866}
867
868template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000869struct _LIBCPP_TYPE_VIS_ONLY char_traits<char32_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000870{
871 typedef char32_t char_type;
872 typedef uint_least32_t int_type;
873 typedef streamoff off_type;
874 typedef u32streampos pos_type;
875 typedef mbstate_t state_type;
876
Howard Hinnanta6119a82011-05-29 19:57:12 +0000877 _LIBCPP_INLINE_VISIBILITY
878 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
879 {__c1 = __c2;}
880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000881 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000882 {return __c1 == __c2;}
883 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000884 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000885 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000886
887 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
888 static size_t length(const char_type* __s);
889 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
890 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
891 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
892 static char_type* assign(char_type* __s, size_t __n, char_type __a);
893
Howard Hinnanta6119a82011-05-29 19:57:12 +0000894 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000895 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000896 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000897 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000898 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000899 {return char_type(__c);}
900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000901 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000902 {return int_type(__c);}
903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000904 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000905 {return __c1 == __c2;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000906 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant03d71812012-07-20 19:09:12 +0000907 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000908 {return int_type(0xFFFFFFFF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000909};
910
911inline _LIBCPP_INLINE_VISIBILITY
912int
913char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
914{
915 for (; __n; --__n, ++__s1, ++__s2)
916 {
917 if (lt(*__s1, *__s2))
918 return -1;
919 if (lt(*__s2, *__s1))
920 return 1;
921 }
922 return 0;
923}
924
925inline _LIBCPP_INLINE_VISIBILITY
926size_t
927char_traits<char32_t>::length(const char_type* __s)
928{
929 size_t __len = 0;
930 for (; !eq(*__s, char_type(0)); ++__s)
931 ++__len;
932 return __len;
933}
934
935inline _LIBCPP_INLINE_VISIBILITY
936const char32_t*
937char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a)
938{
939 for (; __n; --__n)
940 {
941 if (eq(*__s, __a))
942 return __s;
943 ++__s;
944 }
945 return 0;
946}
947
948inline _LIBCPP_INLINE_VISIBILITY
949char32_t*
950char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
951{
952 char_type* __r = __s1;
953 if (__s1 < __s2)
954 {
955 for (; __n; --__n, ++__s1, ++__s2)
956 assign(*__s1, *__s2);
957 }
958 else if (__s2 < __s1)
959 {
960 __s1 += __n;
961 __s2 += __n;
962 for (; __n; --__n)
963 assign(*--__s1, *--__s2);
964 }
965 return __r;
966}
967
968inline _LIBCPP_INLINE_VISIBILITY
969char32_t*
970char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
971{
Howard Hinnant499cea12013-08-23 17:37:05 +0000972 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000973 char_type* __r = __s1;
974 for (; __n; --__n, ++__s1, ++__s2)
975 assign(*__s1, *__s2);
976 return __r;
977}
978
979inline _LIBCPP_INLINE_VISIBILITY
980char32_t*
981char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a)
982{
983 char_type* __r = __s;
984 for (; __n; --__n, ++__s)
985 assign(*__s, __a);
986 return __r;
987}
988
Howard Hinnant324bb032010-08-22 00:02:43 +0000989#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000990
Marshall Clowb671fc92013-12-09 16:00:28 +0000991// helper fns for basic_string
992
993template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
994_SizeT _LIBCPP_INLINE_VISIBILITY __find_first_of(const _CharT *__p, _SizeT __sz,
995 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
996{
997 if (__pos >= __sz || __n == 0)
998 return __npos;
999 const _CharT* __r = _VSTD::find_first_of
1000 (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq );
1001 if (__r == __p + __sz)
1002 return __npos;
1003 return static_cast<_SizeT>(__r - __p);
1004}
1005
1006template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1007_SizeT _LIBCPP_INLINE_VISIBILITY __find_last_of(const _CharT *__p, _SizeT __sz,
1008 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1009 {
1010 if (__n != 0)
1011 {
1012 if (__pos < __sz)
1013 ++__pos;
1014 else
1015 __pos = __sz;
1016 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1017 {
1018 const _CharT* __r = _Traits::find(__s, __n, *--__ps);
1019 if (__r)
1020 return static_cast<_SizeT>(__ps - __p);
1021 }
1022 }
1023 return __npos;
1024}
1025
1026
1027template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1028_SizeT _LIBCPP_INLINE_VISIBILITY __find_first_not_of(const _CharT *__p, _SizeT __sz,
1029 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1030{
1031 if (__pos < __sz)
1032 {
1033 const _CharT* __pe = __p + __sz;
1034 for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
1035 if (_Traits::find(__s, __n, *__ps) == 0)
1036 return static_cast<_SizeT>(__ps - __p);
1037 }
1038 return __npos;
1039}
1040
1041
1042template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1043_SizeT _LIBCPP_INLINE_VISIBILITY __find_first_not_of(const _CharT *__p, _SizeT __sz,
1044 _CharT __c, _SizeT __pos) _NOEXCEPT
1045{
1046 if (__pos < __sz)
1047 {
1048 const _CharT* __pe = __p + __sz;
1049 for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
1050 if (!_Traits::eq(*__ps, __c))
1051 return static_cast<_SizeT>(__ps - __p);
1052 }
1053 return __npos;
1054}
1055
1056
1057template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1058_SizeT _LIBCPP_INLINE_VISIBILITY __find_last_not_of(const _CharT *__p, _SizeT __sz,
1059 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1060{
1061 if (__pos < __sz)
1062 ++__pos;
1063 else
1064 __pos = __sz;
1065 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1066 if (_Traits::find(__s, __n, *--__ps) == 0)
1067 return static_cast<_SizeT>(__ps - __p);
1068 return __npos;
1069}
1070
1071
1072template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1073_SizeT _LIBCPP_INLINE_VISIBILITY __find_last_not_of(const _CharT *__p, _SizeT __sz,
1074 _CharT __c, _SizeT __pos) _NOEXCEPT
1075{
1076 if (__pos < __sz)
1077 ++__pos;
1078 else
1079 __pos = __sz;
1080 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1081 if (!_Traits::eq(*--__ps, __c))
1082 return static_cast<_SizeT>(__ps - __p);
1083 return __npos;
1084}
1085
1086template<class _Ptr>
1087size_t _LIBCPP_INLINE_VISIBILITY __do_string_hash(_Ptr __p, _Ptr __e)
1088{
1089 typedef typename iterator_traits<_Ptr>::value_type value_type;
1090 return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));
1091}
1092
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001093// basic_string
1094
1095template<class _CharT, class _Traits, class _Allocator>
1096basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001097operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
1098 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001099
1100template<class _CharT, class _Traits, class _Allocator>
1101basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001102operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001103
1104template<class _CharT, class _Traits, class _Allocator>
1105basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001106operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001107
1108template<class _CharT, class _Traits, class _Allocator>
1109basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001110operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001111
1112template<class _CharT, class _Traits, class _Allocator>
1113basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001114operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001115
1116template <bool>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001117class _LIBCPP_TYPE_VIS_ONLY __basic_string_common
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001118{
1119protected:
1120 void __throw_length_error() const;
1121 void __throw_out_of_range() const;
1122};
1123
1124template <bool __b>
1125void
1126__basic_string_common<__b>::__throw_length_error() const
1127{
1128#ifndef _LIBCPP_NO_EXCEPTIONS
1129 throw length_error("basic_string");
1130#else
1131 assert(!"basic_string length_error");
1132#endif
1133}
1134
1135template <bool __b>
1136void
1137__basic_string_common<__b>::__throw_out_of_range() const
1138{
1139#ifndef _LIBCPP_NO_EXCEPTIONS
1140 throw out_of_range("basic_string");
1141#else
1142 assert(!"basic_string out_of_range");
1143#endif
1144}
1145
Howard Hinnante9df0a52013-08-01 18:17:34 +00001146#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +00001147#pragma warning( push )
1148#pragma warning( disable: 4231 )
Howard Hinnante9df0a52013-08-01 18:17:34 +00001149#endif // _LIBCPP_MSVC
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001150_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __basic_string_common<true>)
Howard Hinnante9df0a52013-08-01 18:17:34 +00001151#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +00001152#pragma warning( pop )
Howard Hinnante9df0a52013-08-01 18:17:34 +00001153#endif // _LIBCPP_MSVC
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001154
Howard Hinnant15467182013-04-30 21:44:48 +00001155#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1156
1157template <class _CharT, size_t = sizeof(_CharT)>
1158struct __padding
1159{
1160 unsigned char __xx[sizeof(_CharT)-1];
1161};
1162
1163template <class _CharT>
1164struct __padding<_CharT, 1>
1165{
1166};
1167
1168#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1169
Howard Hinnant324bb032010-08-22 00:02:43 +00001170template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001171class _LIBCPP_TYPE_VIS_ONLY basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001172 : private __basic_string_common<true>
1173{
1174public:
1175 typedef basic_string __self;
1176 typedef _Traits traits_type;
1177 typedef typename traits_type::char_type value_type;
1178 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001179 typedef allocator_traits<allocator_type> __alloc_traits;
1180 typedef typename __alloc_traits::size_type size_type;
1181 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001182 typedef value_type& reference;
1183 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001184 typedef typename __alloc_traits::pointer pointer;
1185 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001186
Howard Hinnant499cea12013-08-23 17:37:05 +00001187 static_assert(is_pod<value_type>::value, "Character type of basic_string must be a POD");
1188 static_assert((is_same<_CharT, value_type>::value),
1189 "traits_type::char_type must be the same type as CharT");
1190 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1191 "Allocator::value_type must be same type as value_type");
1192#if defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001193 typedef pointer iterator;
1194 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001195#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001196 typedef __wrap_iter<pointer> iterator;
1197 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001198#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001199 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1200 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001201
1202private:
Howard Hinnant15467182013-04-30 21:44:48 +00001203
1204#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1205
1206 struct __long
1207 {
1208 pointer __data_;
1209 size_type __size_;
1210 size_type __cap_;
1211 };
1212
1213#if _LIBCPP_BIG_ENDIAN
1214 enum {__short_mask = 0x01};
1215 enum {__long_mask = 0x1ul};
1216#else // _LIBCPP_BIG_ENDIAN
1217 enum {__short_mask = 0x80};
1218 enum {__long_mask = ~(size_type(~0) >> 1)};
1219#endif // _LIBCPP_BIG_ENDIAN
1220
1221 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1222 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1223
1224 struct __short
1225 {
1226 value_type __data_[__min_cap];
1227 struct
1228 : __padding<value_type>
1229 {
1230 unsigned char __size_;
1231 };
1232 };
1233
1234#else
1235
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001236 struct __long
1237 {
1238 size_type __cap_;
1239 size_type __size_;
1240 pointer __data_;
1241 };
1242
1243#if _LIBCPP_BIG_ENDIAN
1244 enum {__short_mask = 0x80};
1245 enum {__long_mask = ~(size_type(~0) >> 1)};
Howard Hinnant324bb032010-08-22 00:02:43 +00001246#else // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001247 enum {__short_mask = 0x01};
Howard Hinnantec3773c2011-12-01 20:21:04 +00001248 enum {__long_mask = 0x1ul};
Howard Hinnant324bb032010-08-22 00:02:43 +00001249#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001250
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001251 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1252 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1253
1254 struct __short
1255 {
1256 union
1257 {
1258 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59 +00001259 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001260 };
1261 value_type __data_[__min_cap];
1262 };
1263
Howard Hinnant15467182013-04-30 21:44:48 +00001264#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1265
Howard Hinnant499cea12013-08-23 17:37:05 +00001266 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001267
Howard Hinnant499cea12013-08-23 17:37:05 +00001268 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001269
1270 struct __raw
1271 {
1272 size_type __words[__n_words];
1273 };
1274
1275 struct __rep
1276 {
1277 union
1278 {
1279 __long __l;
1280 __short __s;
1281 __raw __r;
1282 };
1283 };
1284
1285 __compressed_pair<__rep, allocator_type> __r_;
1286
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001287public:
1288 static const size_type npos = -1;
1289
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001290 _LIBCPP_INLINE_VISIBILITY basic_string()
1291 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001292 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001293 basic_string(const basic_string& __str);
1294 basic_string(const basic_string& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001295#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9f193f22011-01-26 00:06:59 +00001296 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001297 basic_string(basic_string&& __str)
1298 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant9f193f22011-01-26 00:06:59 +00001299 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001300 basic_string(basic_string&& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001301#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001302 _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001303 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001304 basic_string(const value_type* __s, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001305 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001306 basic_string(const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001307 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001308 basic_string(const value_type* __s, size_type __n, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001309 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001310 basic_string(size_type __n, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001311 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001312 basic_string(size_type __n, value_type __c, const allocator_type& __a);
1313 basic_string(const basic_string& __str, size_type __pos, size_type __n = npos,
1314 const allocator_type& __a = allocator_type());
1315 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001316 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001317 basic_string(_InputIterator __first, _InputIterator __last);
1318 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001319 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001320 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001321#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001322 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001323 basic_string(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001324 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001325 basic_string(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001326#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001327
1328 ~basic_string();
1329
Howard Hinnante32b5e22010-11-17 17:55:08 +00001330 basic_string& operator=(const basic_string& __str);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001331#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001332 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001333 basic_string& operator=(basic_string&& __str)
1334 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
1335 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001336#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001337 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001338 basic_string& operator=(value_type __c);
Howard Hinnante3e32912011-08-12 21:56:02 +00001339#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001340 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001341 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001342#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001343
Howard Hinnant499cea12013-08-23 17:37:05 +00001344#if _LIBCPP_DEBUG_LEVEL >= 2
1345 _LIBCPP_INLINE_VISIBILITY
1346 iterator begin() _NOEXCEPT
1347 {return iterator(this, __get_pointer());}
1348 _LIBCPP_INLINE_VISIBILITY
1349 const_iterator begin() const _NOEXCEPT
1350 {return const_iterator(this, __get_pointer());}
1351 _LIBCPP_INLINE_VISIBILITY
1352 iterator end() _NOEXCEPT
1353 {return iterator(this, __get_pointer() + size());}
1354 _LIBCPP_INLINE_VISIBILITY
1355 const_iterator end() const _NOEXCEPT
1356 {return const_iterator(this, __get_pointer() + size());}
1357#else
Howard Hinnanta6119a82011-05-29 19:57:12 +00001358 _LIBCPP_INLINE_VISIBILITY
1359 iterator begin() _NOEXCEPT
1360 {return iterator(__get_pointer());}
1361 _LIBCPP_INLINE_VISIBILITY
1362 const_iterator begin() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001363 {return const_iterator(__get_pointer());}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001364 _LIBCPP_INLINE_VISIBILITY
1365 iterator end() _NOEXCEPT
1366 {return iterator(__get_pointer() + size());}
1367 _LIBCPP_INLINE_VISIBILITY
1368 const_iterator end() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001369 {return const_iterator(__get_pointer() + size());}
Howard Hinnant499cea12013-08-23 17:37:05 +00001370#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnanta6119a82011-05-29 19:57:12 +00001371 _LIBCPP_INLINE_VISIBILITY
1372 reverse_iterator rbegin() _NOEXCEPT
1373 {return reverse_iterator(end());}
1374 _LIBCPP_INLINE_VISIBILITY
1375 const_reverse_iterator rbegin() const _NOEXCEPT
1376 {return const_reverse_iterator(end());}
1377 _LIBCPP_INLINE_VISIBILITY
1378 reverse_iterator rend() _NOEXCEPT
1379 {return reverse_iterator(begin());}
1380 _LIBCPP_INLINE_VISIBILITY
1381 const_reverse_iterator rend() const _NOEXCEPT
1382 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001383
Howard Hinnanta6119a82011-05-29 19:57:12 +00001384 _LIBCPP_INLINE_VISIBILITY
1385 const_iterator cbegin() const _NOEXCEPT
1386 {return begin();}
1387 _LIBCPP_INLINE_VISIBILITY
1388 const_iterator cend() const _NOEXCEPT
1389 {return end();}
1390 _LIBCPP_INLINE_VISIBILITY
1391 const_reverse_iterator crbegin() const _NOEXCEPT
1392 {return rbegin();}
1393 _LIBCPP_INLINE_VISIBILITY
1394 const_reverse_iterator crend() const _NOEXCEPT
1395 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001396
Howard Hinnanta6119a82011-05-29 19:57:12 +00001397 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001398 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001399 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
1400 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
1401 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001402 {return (__is_long() ? __get_long_cap() : __min_cap) - 1;}
1403
1404 void resize(size_type __n, value_type __c);
1405 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
1406
1407 void reserve(size_type res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001408 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001409 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001410 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001411 void clear() _NOEXCEPT;
1412 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001413
1414 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const;
1415 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos);
1416
1417 const_reference at(size_type __n) const;
1418 reference at(size_type __n);
1419
1420 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001421 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001422 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +00001423#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001424 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Howard Hinnante3e32912011-08-12 21:56:02 +00001425#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001426
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001427 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001428 basic_string& append(const basic_string& __str);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001429 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001430 basic_string& append(const value_type* __s, size_type __n);
1431 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001432 basic_string& append(size_type __n, value_type __c);
1433 template<class _InputIterator>
1434 typename enable_if
1435 <
1436 __is_input_iterator <_InputIterator>::value &&
1437 !__is_forward_iterator<_InputIterator>::value,
1438 basic_string&
1439 >::type
1440 append(_InputIterator __first, _InputIterator __last);
1441 template<class _ForwardIterator>
1442 typename enable_if
1443 <
1444 __is_forward_iterator<_ForwardIterator>::value,
1445 basic_string&
1446 >::type
1447 append(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001448#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001449 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001450 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001451#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001452
1453 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001454 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001455 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001456 _LIBCPP_INLINE_VISIBILITY reference front();
1457 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
1458 _LIBCPP_INLINE_VISIBILITY reference back();
1459 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001460
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001461 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001462 basic_string& assign(const basic_string& __str);
Howard Hinnanta6119a82011-05-29 19:57:12 +00001463#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1464 _LIBCPP_INLINE_VISIBILITY
1465 basic_string& assign(basic_string&& str)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001466 {*this = _VSTD::move(str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001467#endif
Marshall Clowa93b5e22014-03-04 19:17:19 +00001468 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001469 basic_string& assign(const value_type* __s, size_type __n);
1470 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001471 basic_string& assign(size_type __n, value_type __c);
1472 template<class _InputIterator>
1473 typename enable_if
1474 <
1475 __is_input_iterator <_InputIterator>::value &&
1476 !__is_forward_iterator<_InputIterator>::value,
1477 basic_string&
1478 >::type
1479 assign(_InputIterator __first, _InputIterator __last);
1480 template<class _ForwardIterator>
1481 typename enable_if
1482 <
1483 __is_forward_iterator<_ForwardIterator>::value,
1484 basic_string&
1485 >::type
1486 assign(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001487#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001488 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001489 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001490#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001491
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001493 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001494 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001495 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1496 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001497 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1498 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001500 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1501 template<class _InputIterator>
1502 typename enable_if
1503 <
1504 __is_input_iterator <_InputIterator>::value &&
1505 !__is_forward_iterator<_InputIterator>::value,
1506 iterator
1507 >::type
1508 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1509 template<class _ForwardIterator>
1510 typename enable_if
1511 <
1512 __is_forward_iterator<_ForwardIterator>::value,
1513 iterator
1514 >::type
1515 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001516#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001517 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001518 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1519 {return insert(__pos, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001520#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001521
1522 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001523 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001524 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001525 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001526 iterator erase(const_iterator __first, const_iterator __last);
1527
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001529 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001530 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001531 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1532 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001533 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001534 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001535 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001536 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001537 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001538 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001539 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001540 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001541 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001542 template<class _InputIterator>
1543 typename enable_if
1544 <
1545 __is_input_iterator<_InputIterator>::value,
1546 basic_string&
1547 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001548 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Howard Hinnante3e32912011-08-12 21:56:02 +00001549#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001550 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001551 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001552 {return replace(__i1, __i2, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001553#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001554
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001555 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001556 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001557 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1558
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001559 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001560 void swap(basic_string& __str)
1561 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1562 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001563
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001564 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001565 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001567 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001568
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001570 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001571
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001572 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001573 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001574 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001575 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001576 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001577 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001578
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001579 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001580 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001581 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001583 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001584 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001585
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001587 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001588 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001590 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001591 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001592 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001593
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001595 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001596 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001597 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001598 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001600 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001601
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001603 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001604 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 +00001605 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001606 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001607 _LIBCPP_INLINE_VISIBILITY
1608 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1609
1610 _LIBCPP_INLINE_VISIBILITY
1611 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001612 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 +00001613 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001614 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001615 _LIBCPP_INLINE_VISIBILITY
1616 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1617
1618 _LIBCPP_INLINE_VISIBILITY
1619 int compare(const basic_string& __str) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001620 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001621 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clowa93b5e22014-03-04 19:17:19 +00001622 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001623 int compare(const value_type* __s) const _NOEXCEPT;
1624 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1625 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001626
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001627 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:13 +00001628
1629 _LIBCPP_INLINE_VISIBILITY
1630 bool __is_long() const _NOEXCEPT
1631 {return bool(__r_.first().__s.__size_ & __short_mask);}
1632
Howard Hinnant499cea12013-08-23 17:37:05 +00001633#if _LIBCPP_DEBUG_LEVEL >= 2
1634
1635 bool __dereferenceable(const const_iterator* __i) const;
1636 bool __decrementable(const const_iterator* __i) const;
1637 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1638 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1639
1640#endif // _LIBCPP_DEBUG_LEVEL >= 2
1641
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001642private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001643 _LIBCPP_INLINE_VISIBILITY
1644 allocator_type& __alloc() _NOEXCEPT
1645 {return __r_.second();}
1646 _LIBCPP_INLINE_VISIBILITY
1647 const allocator_type& __alloc() const _NOEXCEPT
1648 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001649
Howard Hinnant15467182013-04-30 21:44:48 +00001650#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1651
Howard Hinnanta6119a82011-05-29 19:57:12 +00001652 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001653 void __set_short_size(size_type __s) _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001654# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001655 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:48 +00001656# else
1657 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1658# endif
1659
Howard Hinnanta6119a82011-05-29 19:57:12 +00001660 _LIBCPP_INLINE_VISIBILITY
1661 size_type __get_short_size() const _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001662# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001663 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:48 +00001664# else
1665 {return __r_.first().__s.__size_;}
1666# endif
1667
1668#else // _LIBCPP_ALTERNATE_STRING_LAYOUT
1669
1670 _LIBCPP_INLINE_VISIBILITY
1671 void __set_short_size(size_type __s) _NOEXCEPT
1672# if _LIBCPP_BIG_ENDIAN
1673 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1674# else
1675 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1676# endif
1677
1678 _LIBCPP_INLINE_VISIBILITY
1679 size_type __get_short_size() const _NOEXCEPT
1680# if _LIBCPP_BIG_ENDIAN
1681 {return __r_.first().__s.__size_;}
1682# else
1683 {return __r_.first().__s.__size_ >> 1;}
1684# endif
1685
1686#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1687
Howard Hinnanta6119a82011-05-29 19:57:12 +00001688 _LIBCPP_INLINE_VISIBILITY
1689 void __set_long_size(size_type __s) _NOEXCEPT
1690 {__r_.first().__l.__size_ = __s;}
1691 _LIBCPP_INLINE_VISIBILITY
1692 size_type __get_long_size() const _NOEXCEPT
1693 {return __r_.first().__l.__size_;}
1694 _LIBCPP_INLINE_VISIBILITY
1695 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001696 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1697
Howard Hinnanta6119a82011-05-29 19:57:12 +00001698 _LIBCPP_INLINE_VISIBILITY
1699 void __set_long_cap(size_type __s) _NOEXCEPT
1700 {__r_.first().__l.__cap_ = __long_mask | __s;}
1701 _LIBCPP_INLINE_VISIBILITY
1702 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001703 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001704
Howard Hinnanta6119a82011-05-29 19:57:12 +00001705 _LIBCPP_INLINE_VISIBILITY
1706 void __set_long_pointer(pointer __p) _NOEXCEPT
1707 {__r_.first().__l.__data_ = __p;}
1708 _LIBCPP_INLINE_VISIBILITY
1709 pointer __get_long_pointer() _NOEXCEPT
1710 {return __r_.first().__l.__data_;}
1711 _LIBCPP_INLINE_VISIBILITY
1712 const_pointer __get_long_pointer() const _NOEXCEPT
1713 {return __r_.first().__l.__data_;}
1714 _LIBCPP_INLINE_VISIBILITY
1715 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001716 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001717 _LIBCPP_INLINE_VISIBILITY
1718 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001719 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001720 _LIBCPP_INLINE_VISIBILITY
1721 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001722 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001723 _LIBCPP_INLINE_VISIBILITY
1724 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001725 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1726
Howard Hinnanta6119a82011-05-29 19:57:12 +00001727 _LIBCPP_INLINE_VISIBILITY
1728 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001729 {
1730 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1731 for (unsigned __i = 0; __i < __n_words; ++__i)
1732 __a[__i] = 0;
1733 }
1734
1735 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:20 +00001737 size_type __align_it(size_type __s) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +00001738 {return __s + (__a-1) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001739 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001740 static _LIBCPP_INLINE_VISIBILITY
1741 size_type __recommend(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001742 {return (__s < __min_cap ? __min_cap :
Howard Hinnant7f764502013-08-14 18:00:20 +00001743 __align_it<sizeof(value_type) < __alignment ?
Howard Hinnanta6119a82011-05-29 19:57:12 +00001744 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001745
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001746 void __init(const value_type* __s, size_type __sz, size_type __reserve);
1747 void __init(const value_type* __s, size_type __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001748 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001749
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001750 template <class _InputIterator>
1751 typename enable_if
1752 <
1753 __is_input_iterator <_InputIterator>::value &&
1754 !__is_forward_iterator<_InputIterator>::value,
1755 void
1756 >::type
1757 __init(_InputIterator __first, _InputIterator __last);
1758
1759 template <class _ForwardIterator>
1760 typename enable_if
1761 <
1762 __is_forward_iterator<_ForwardIterator>::value,
1763 void
1764 >::type
1765 __init(_ForwardIterator __first, _ForwardIterator __last);
1766
1767 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001768 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001769 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1770 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001771 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001772
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001773 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001774 void __erase_to_end(size_type __pos);
1775
Howard Hinnante32b5e22010-11-17 17:55:08 +00001776 _LIBCPP_INLINE_VISIBILITY
1777 void __copy_assign_alloc(const basic_string& __str)
1778 {__copy_assign_alloc(__str, integral_constant<bool,
1779 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1780
1781 _LIBCPP_INLINE_VISIBILITY
1782 void __copy_assign_alloc(const basic_string& __str, true_type)
1783 {
1784 if (__alloc() != __str.__alloc())
1785 {
1786 clear();
1787 shrink_to_fit();
1788 }
1789 __alloc() = __str.__alloc();
1790 }
1791
1792 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001793 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001794 {}
1795
1796#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001797 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00001798 void __move_assign(basic_string& __str, false_type);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001799 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001800 void __move_assign(basic_string& __str, true_type)
1801 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001802#endif
1803
1804 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001805 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001806 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001807 _NOEXCEPT_(
1808 !__alloc_traits::propagate_on_container_move_assignment::value ||
1809 is_nothrow_move_assignable<allocator_type>::value)
1810 {__move_assign_alloc(__str, integral_constant<bool,
1811 __alloc_traits::propagate_on_container_move_assignment::value>());}
1812
1813 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001814 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001815 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1816 {
1817 __alloc() = _VSTD::move(__c.__alloc());
1818 }
1819
1820 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001821 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001822 _NOEXCEPT
1823 {}
1824
1825 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001826 static void __swap_alloc(allocator_type& __x, allocator_type& __y)
1827 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1828 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001829 {__swap_alloc(__x, __y, integral_constant<bool,
1830 __alloc_traits::propagate_on_container_swap::value>());}
1831
1832 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001833 static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
1834 _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001835 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001836 using _VSTD::swap;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001837 swap(__x, __y);
1838 }
1839 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001840 static void __swap_alloc(allocator_type&, allocator_type&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001841 {}
1842
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001843 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1844 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001845
1846 friend basic_string operator+<>(const basic_string&, const basic_string&);
1847 friend basic_string operator+<>(const value_type*, const basic_string&);
1848 friend basic_string operator+<>(value_type, const basic_string&);
1849 friend basic_string operator+<>(const basic_string&, const value_type*);
1850 friend basic_string operator+<>(const basic_string&, value_type);
1851};
1852
1853template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001854inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001855void
1856basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1857{
Howard Hinnant499cea12013-08-23 17:37:05 +00001858#if _LIBCPP_DEBUG_LEVEL >= 2
1859 __get_db()->__invalidate_all(this);
1860#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001861}
1862
1863template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001864inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001865void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001866basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant499cea12013-08-23 17:37:05 +00001867#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantec3773c2011-12-01 20:21:04 +00001868 __pos
1869#endif
1870 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001871{
Howard Hinnant499cea12013-08-23 17:37:05 +00001872#if _LIBCPP_DEBUG_LEVEL >= 2
1873 __c_node* __c = __get_db()->__find_c_and_lock(this);
1874 if (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001875 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001876 const_pointer __new_last = __get_pointer() + __pos;
1877 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001878 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001879 --__p;
1880 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1881 if (__i->base() > __new_last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001882 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001883 (*__p)->__c_ = nullptr;
1884 if (--__c->end_ != __p)
1885 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001886 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001887 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001888 __get_db()->unlock();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001889 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001890#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001891}
1892
1893template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001894inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001895basic_string<_CharT, _Traits, _Allocator>::basic_string()
1896 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001897{
Howard Hinnant499cea12013-08-23 17:37:05 +00001898#if _LIBCPP_DEBUG_LEVEL >= 2
1899 __get_db()->__insert_c(this);
1900#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001901 __zero();
1902}
1903
1904template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001905inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001906basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
1907 : __r_(__a)
1908{
Howard Hinnant499cea12013-08-23 17:37:05 +00001909#if _LIBCPP_DEBUG_LEVEL >= 2
1910 __get_db()->__insert_c(this);
1911#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001912 __zero();
1913}
1914
1915template <class _CharT, class _Traits, class _Allocator>
1916void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001917basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001918{
1919 if (__reserve > max_size())
1920 this->__throw_length_error();
1921 pointer __p;
1922 if (__reserve < __min_cap)
1923 {
1924 __set_short_size(__sz);
1925 __p = __get_short_pointer();
1926 }
1927 else
1928 {
1929 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001930 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001931 __set_long_pointer(__p);
1932 __set_long_cap(__cap+1);
1933 __set_long_size(__sz);
1934 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001935 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001936 traits_type::assign(__p[__sz], value_type());
1937}
1938
1939template <class _CharT, class _Traits, class _Allocator>
1940void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001941basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001942{
1943 if (__sz > max_size())
1944 this->__throw_length_error();
1945 pointer __p;
1946 if (__sz < __min_cap)
1947 {
1948 __set_short_size(__sz);
1949 __p = __get_short_pointer();
1950 }
1951 else
1952 {
1953 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001954 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001955 __set_long_pointer(__p);
1956 __set_long_cap(__cap+1);
1957 __set_long_size(__sz);
1958 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001959 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001960 traits_type::assign(__p[__sz], value_type());
1961}
1962
1963template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001964inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001965basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001966{
Howard Hinnant499cea12013-08-23 17:37:05 +00001967 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001968 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00001969#if _LIBCPP_DEBUG_LEVEL >= 2
1970 __get_db()->__insert_c(this);
1971#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001972}
1973
1974template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001975inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001976basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001977 : __r_(__a)
1978{
Howard Hinnant499cea12013-08-23 17:37:05 +00001979 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001980 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00001981#if _LIBCPP_DEBUG_LEVEL >= 2
1982 __get_db()->__insert_c(this);
1983#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001984}
1985
1986template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001987inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001988basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001989{
Howard Hinnant499cea12013-08-23 17:37:05 +00001990 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001991 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001992#if _LIBCPP_DEBUG_LEVEL >= 2
1993 __get_db()->__insert_c(this);
1994#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001995}
1996
1997template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001998inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001999basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002000 : __r_(__a)
2001{
Howard Hinnant499cea12013-08-23 17:37:05 +00002002 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002003 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00002004#if _LIBCPP_DEBUG_LEVEL >= 2
2005 __get_db()->__insert_c(this);
2006#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002007}
2008
2009template <class _CharT, class _Traits, class _Allocator>
2010basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002011 : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002012{
2013 if (!__str.__is_long())
2014 __r_.first().__r = __str.__r_.first().__r;
2015 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002016 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00002017#if _LIBCPP_DEBUG_LEVEL >= 2
2018 __get_db()->__insert_c(this);
2019#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002020}
2021
2022template <class _CharT, class _Traits, class _Allocator>
2023basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
2024 : __r_(__a)
2025{
2026 if (!__str.__is_long())
2027 __r_.first().__r = __str.__r_.first().__r;
2028 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002029 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00002030#if _LIBCPP_DEBUG_LEVEL >= 2
2031 __get_db()->__insert_c(this);
2032#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002033}
2034
Howard Hinnant73d21a42010-09-04 23:28:19 +00002035#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002036
2037template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002038inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002039basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
2040 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002041 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002042{
2043 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:05 +00002044#if _LIBCPP_DEBUG_LEVEL >= 2
2045 __get_db()->__insert_c(this);
2046 if (__is_long())
2047 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002048#endif
2049}
2050
2051template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002052inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002053basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002054 : __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002055{
Howard Hinnante32b5e22010-11-17 17:55:08 +00002056 if (__a == __str.__alloc() || !__str.__is_long())
2057 __r_.first().__r = __str.__r_.first().__r;
2058 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002059 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002060 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:05 +00002061#if _LIBCPP_DEBUG_LEVEL >= 2
2062 __get_db()->__insert_c(this);
2063 if (__is_long())
2064 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002065#endif
2066}
2067
Howard Hinnant73d21a42010-09-04 23:28:19 +00002068#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002069
2070template <class _CharT, class _Traits, class _Allocator>
2071void
2072basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
2073{
2074 if (__n > max_size())
2075 this->__throw_length_error();
2076 pointer __p;
2077 if (__n < __min_cap)
2078 {
2079 __set_short_size(__n);
2080 __p = __get_short_pointer();
2081 }
2082 else
2083 {
2084 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002085 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002086 __set_long_pointer(__p);
2087 __set_long_cap(__cap+1);
2088 __set_long_size(__n);
2089 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002090 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002091 traits_type::assign(__p[__n], value_type());
2092}
2093
2094template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002095inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002096basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
2097{
2098 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00002099#if _LIBCPP_DEBUG_LEVEL >= 2
2100 __get_db()->__insert_c(this);
2101#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002102}
2103
2104template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002105inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002106basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
2107 : __r_(__a)
2108{
2109 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00002110#if _LIBCPP_DEBUG_LEVEL >= 2
2111 __get_db()->__insert_c(this);
2112#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002113}
2114
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002115template <class _CharT, class _Traits, class _Allocator>
2116basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
2117 const allocator_type& __a)
2118 : __r_(__a)
2119{
2120 size_type __str_sz = __str.size();
2121 if (__pos > __str_sz)
2122 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002123 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant499cea12013-08-23 17:37:05 +00002124#if _LIBCPP_DEBUG_LEVEL >= 2
2125 __get_db()->__insert_c(this);
2126#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002127}
2128
2129template <class _CharT, class _Traits, class _Allocator>
2130template <class _InputIterator>
2131typename enable_if
2132<
2133 __is_input_iterator <_InputIterator>::value &&
2134 !__is_forward_iterator<_InputIterator>::value,
2135 void
2136>::type
2137basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2138{
2139 __zero();
2140#ifndef _LIBCPP_NO_EXCEPTIONS
2141 try
2142 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002143#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002144 for (; __first != __last; ++__first)
2145 push_back(*__first);
2146#ifndef _LIBCPP_NO_EXCEPTIONS
2147 }
2148 catch (...)
2149 {
2150 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002151 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002152 throw;
2153 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002154#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002155}
2156
2157template <class _CharT, class _Traits, class _Allocator>
2158template <class _ForwardIterator>
2159typename enable_if
2160<
2161 __is_forward_iterator<_ForwardIterator>::value,
2162 void
2163>::type
2164basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2165{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002166 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002167 if (__sz > max_size())
2168 this->__throw_length_error();
2169 pointer __p;
2170 if (__sz < __min_cap)
2171 {
2172 __set_short_size(__sz);
2173 __p = __get_short_pointer();
2174 }
2175 else
2176 {
2177 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002178 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002179 __set_long_pointer(__p);
2180 __set_long_cap(__cap+1);
2181 __set_long_size(__sz);
2182 }
2183 for (; __first != __last; ++__first, ++__p)
2184 traits_type::assign(*__p, *__first);
2185 traits_type::assign(*__p, value_type());
2186}
2187
2188template <class _CharT, class _Traits, class _Allocator>
2189template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002190inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002191basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2192{
2193 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002194#if _LIBCPP_DEBUG_LEVEL >= 2
2195 __get_db()->__insert_c(this);
2196#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002197}
2198
2199template <class _CharT, class _Traits, class _Allocator>
2200template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002201inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002202basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2203 const allocator_type& __a)
2204 : __r_(__a)
2205{
2206 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002207#if _LIBCPP_DEBUG_LEVEL >= 2
2208 __get_db()->__insert_c(this);
2209#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002210}
2211
Howard Hinnante3e32912011-08-12 21:56:02 +00002212#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2213
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002214template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002215inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002216basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
2217{
2218 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002219#if _LIBCPP_DEBUG_LEVEL >= 2
2220 __get_db()->__insert_c(this);
2221#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002222}
2223
2224template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002225inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002226basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
2227 : __r_(__a)
2228{
2229 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002230#if _LIBCPP_DEBUG_LEVEL >= 2
2231 __get_db()->__insert_c(this);
2232#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002233}
2234
Howard Hinnante3e32912011-08-12 21:56:02 +00002235#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2236
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002237template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002238basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2239{
Howard Hinnant499cea12013-08-23 17:37:05 +00002240#if _LIBCPP_DEBUG_LEVEL >= 2
2241 __get_db()->__erase_c(this);
2242#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002243 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002244 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002245}
2246
2247template <class _CharT, class _Traits, class _Allocator>
2248void
2249basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2250 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002251 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 +00002252{
2253 size_type __ms = max_size();
2254 if (__delta_cap > __ms - __old_cap - 1)
2255 this->__throw_length_error();
2256 pointer __old_p = __get_pointer();
2257 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002258 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002259 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002260 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002261 __invalidate_all_iterators();
2262 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002263 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2264 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002265 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002266 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002267 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2268 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002269 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2270 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002271 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002272 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002273 __set_long_pointer(__p);
2274 __set_long_cap(__cap+1);
2275 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2276 __set_long_size(__old_sz);
2277 traits_type::assign(__p[__old_sz], value_type());
2278}
2279
2280template <class _CharT, class _Traits, class _Allocator>
2281void
2282basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2283 size_type __n_copy, size_type __n_del, size_type __n_add)
2284{
2285 size_type __ms = max_size();
Marshall Clowecc8d7b2013-11-06 14:24:38 +00002286 if (__delta_cap > __ms - __old_cap)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002287 this->__throw_length_error();
2288 pointer __old_p = __get_pointer();
2289 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002290 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002291 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002292 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002293 __invalidate_all_iterators();
2294 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002295 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2296 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002297 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2298 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002299 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2300 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
2301 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002302 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002303 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002304 __set_long_pointer(__p);
2305 __set_long_cap(__cap+1);
2306}
2307
2308// assign
2309
2310template <class _CharT, class _Traits, class _Allocator>
2311basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002312basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002313{
Alp Tokerec34c482014-05-15 11:27:39 +00002314 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002315 size_type __cap = capacity();
2316 if (__cap >= __n)
2317 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002318 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002319 traits_type::move(__p, __s, __n);
2320 traits_type::assign(__p[__n], value_type());
2321 __set_size(__n);
2322 __invalidate_iterators_past(__n);
2323 }
2324 else
2325 {
2326 size_type __sz = size();
2327 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2328 }
2329 return *this;
2330}
2331
2332template <class _CharT, class _Traits, class _Allocator>
2333basic_string<_CharT, _Traits, _Allocator>&
2334basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2335{
2336 size_type __cap = capacity();
2337 if (__cap < __n)
2338 {
2339 size_type __sz = size();
2340 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2341 }
2342 else
2343 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002344 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002345 traits_type::assign(__p, __n, __c);
2346 traits_type::assign(__p[__n], value_type());
2347 __set_size(__n);
2348 return *this;
2349}
2350
2351template <class _CharT, class _Traits, class _Allocator>
2352basic_string<_CharT, _Traits, _Allocator>&
2353basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2354{
2355 pointer __p;
2356 if (__is_long())
2357 {
2358 __p = __get_long_pointer();
2359 __set_long_size(1);
2360 }
2361 else
2362 {
2363 __p = __get_short_pointer();
2364 __set_short_size(1);
2365 }
2366 traits_type::assign(*__p, __c);
2367 traits_type::assign(*++__p, value_type());
2368 __invalidate_iterators_past(1);
2369 return *this;
2370}
2371
2372template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00002373basic_string<_CharT, _Traits, _Allocator>&
2374basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2375{
2376 if (this != &__str)
2377 {
2378 __copy_assign_alloc(__str);
2379 assign(__str);
2380 }
2381 return *this;
2382}
2383
2384#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2385
2386template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002387inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002388void
2389basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
2390{
2391 if (__alloc() != __str.__alloc())
2392 assign(__str);
2393 else
2394 __move_assign(__str, true_type());
2395}
2396
2397template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002398inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002399void
2400basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002401 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002402{
2403 clear();
2404 shrink_to_fit();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00002405 __r_.first() = __str.__r_.first();
2406 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002407 __str.__zero();
2408}
2409
2410template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002411inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002412basic_string<_CharT, _Traits, _Allocator>&
2413basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002414 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
2415 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002416{
2417 __move_assign(__str, integral_constant<bool,
2418 __alloc_traits::propagate_on_container_move_assignment::value>());
2419 return *this;
2420}
2421
2422#endif
2423
2424template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002425template<class _InputIterator>
2426typename enable_if
2427<
2428 __is_input_iterator <_InputIterator>::value &&
2429 !__is_forward_iterator<_InputIterator>::value,
2430 basic_string<_CharT, _Traits, _Allocator>&
2431>::type
2432basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2433{
2434 clear();
2435 for (; __first != __last; ++__first)
2436 push_back(*__first);
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002437 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002438}
2439
2440template <class _CharT, class _Traits, class _Allocator>
2441template<class _ForwardIterator>
2442typename enable_if
2443<
2444 __is_forward_iterator<_ForwardIterator>::value,
2445 basic_string<_CharT, _Traits, _Allocator>&
2446>::type
2447basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2448{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002449 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002450 size_type __cap = capacity();
2451 if (__cap < __n)
2452 {
2453 size_type __sz = size();
2454 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2455 }
2456 else
2457 __invalidate_iterators_past(__n);
2458 pointer __p = __get_pointer();
2459 for (; __first != __last; ++__first, ++__p)
2460 traits_type::assign(*__p, *__first);
2461 traits_type::assign(*__p, value_type());
2462 __set_size(__n);
2463 return *this;
2464}
2465
2466template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002467inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002468basic_string<_CharT, _Traits, _Allocator>&
2469basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str)
2470{
2471 return assign(__str.data(), __str.size());
2472}
2473
2474template <class _CharT, class _Traits, class _Allocator>
2475basic_string<_CharT, _Traits, _Allocator>&
2476basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2477{
2478 size_type __sz = __str.size();
2479 if (__pos > __sz)
2480 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002481 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002482}
2483
2484template <class _CharT, class _Traits, class _Allocator>
2485basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002486basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002487{
Alp Tokerec34c482014-05-15 11:27:39 +00002488 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002489 return assign(__s, traits_type::length(__s));
2490}
2491
2492// append
2493
2494template <class _CharT, class _Traits, class _Allocator>
2495basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002496basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002497{
Alp Tokerec34c482014-05-15 11:27:39 +00002498 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002499 size_type __cap = capacity();
2500 size_type __sz = size();
2501 if (__cap - __sz >= __n)
2502 {
2503 if (__n)
2504 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002505 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002506 traits_type::copy(__p + __sz, __s, __n);
2507 __sz += __n;
2508 __set_size(__sz);
2509 traits_type::assign(__p[__sz], value_type());
2510 }
2511 }
2512 else
2513 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2514 return *this;
2515}
2516
2517template <class _CharT, class _Traits, class _Allocator>
2518basic_string<_CharT, _Traits, _Allocator>&
2519basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2520{
2521 if (__n)
2522 {
2523 size_type __cap = capacity();
2524 size_type __sz = size();
2525 if (__cap - __sz < __n)
2526 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2527 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002528 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002529 __sz += __n;
2530 __set_size(__sz);
2531 traits_type::assign(__p[__sz], value_type());
2532 }
2533 return *this;
2534}
2535
2536template <class _CharT, class _Traits, class _Allocator>
2537void
2538basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2539{
Howard Hinnant15467182013-04-30 21:44:48 +00002540 bool __is_short = !__is_long();
2541 size_type __cap;
2542 size_type __sz;
2543 if (__is_short)
2544 {
2545 __cap = __min_cap - 1;
2546 __sz = __get_short_size();
2547 }
2548 else
2549 {
2550 __cap = __get_long_cap() - 1;
2551 __sz = __get_long_size();
2552 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002553 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002554 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002555 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002556 __is_short = !__is_long();
2557 }
2558 pointer __p;
2559 if (__is_short)
2560 {
2561 __p = __get_short_pointer() + __sz;
2562 __set_short_size(__sz+1);
2563 }
2564 else
2565 {
2566 __p = __get_long_pointer() + __sz;
2567 __set_long_size(__sz+1);
2568 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002569 traits_type::assign(*__p, __c);
2570 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002571}
2572
2573template <class _CharT, class _Traits, class _Allocator>
2574template<class _InputIterator>
2575typename enable_if
2576<
2577 __is_input_iterator <_InputIterator>::value &&
2578 !__is_forward_iterator<_InputIterator>::value,
2579 basic_string<_CharT, _Traits, _Allocator>&
2580>::type
2581basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
2582{
2583 for (; __first != __last; ++__first)
2584 push_back(*__first);
2585 return *this;
2586}
2587
2588template <class _CharT, class _Traits, class _Allocator>
2589template<class _ForwardIterator>
2590typename enable_if
2591<
2592 __is_forward_iterator<_ForwardIterator>::value,
2593 basic_string<_CharT, _Traits, _Allocator>&
2594>::type
2595basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
2596{
2597 size_type __sz = size();
2598 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002599 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002600 if (__n)
2601 {
2602 if (__cap - __sz < __n)
2603 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2604 pointer __p = __get_pointer() + __sz;
2605 for (; __first != __last; ++__p, ++__first)
2606 traits_type::assign(*__p, *__first);
2607 traits_type::assign(*__p, value_type());
2608 __set_size(__sz + __n);
2609 }
2610 return *this;
2611}
2612
2613template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002614inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002615basic_string<_CharT, _Traits, _Allocator>&
2616basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2617{
2618 return append(__str.data(), __str.size());
2619}
2620
2621template <class _CharT, class _Traits, class _Allocator>
2622basic_string<_CharT, _Traits, _Allocator>&
2623basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2624{
2625 size_type __sz = __str.size();
2626 if (__pos > __sz)
2627 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002628 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002629}
2630
2631template <class _CharT, class _Traits, class _Allocator>
2632basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002633basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002634{
Alp Tokerec34c482014-05-15 11:27:39 +00002635 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002636 return append(__s, traits_type::length(__s));
2637}
2638
2639// insert
2640
2641template <class _CharT, class _Traits, class _Allocator>
2642basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002643basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002644{
Alp Tokerec34c482014-05-15 11:27:39 +00002645 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002646 size_type __sz = size();
2647 if (__pos > __sz)
2648 this->__throw_out_of_range();
2649 size_type __cap = capacity();
2650 if (__cap - __sz >= __n)
2651 {
2652 if (__n)
2653 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002654 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002655 size_type __n_move = __sz - __pos;
2656 if (__n_move != 0)
2657 {
2658 if (__p + __pos <= __s && __s < __p + __sz)
2659 __s += __n;
2660 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2661 }
2662 traits_type::move(__p + __pos, __s, __n);
2663 __sz += __n;
2664 __set_size(__sz);
2665 traits_type::assign(__p[__sz], value_type());
2666 }
2667 }
2668 else
2669 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2670 return *this;
2671}
2672
2673template <class _CharT, class _Traits, class _Allocator>
2674basic_string<_CharT, _Traits, _Allocator>&
2675basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2676{
2677 size_type __sz = size();
2678 if (__pos > __sz)
2679 this->__throw_out_of_range();
2680 if (__n)
2681 {
2682 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002683 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002684 if (__cap - __sz >= __n)
2685 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002686 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002687 size_type __n_move = __sz - __pos;
2688 if (__n_move != 0)
2689 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2690 }
2691 else
2692 {
2693 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002694 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002695 }
2696 traits_type::assign(__p + __pos, __n, __c);
2697 __sz += __n;
2698 __set_size(__sz);
2699 traits_type::assign(__p[__sz], value_type());
2700 }
2701 return *this;
2702}
2703
2704template <class _CharT, class _Traits, class _Allocator>
2705template<class _InputIterator>
2706typename enable_if
2707<
2708 __is_input_iterator <_InputIterator>::value &&
2709 !__is_forward_iterator<_InputIterator>::value,
2710 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2711>::type
2712basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2713{
Howard Hinnant499cea12013-08-23 17:37:05 +00002714#if _LIBCPP_DEBUG_LEVEL >= 2
2715 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2716 "string::insert(iterator, range) called with an iterator not"
2717 " referring to this string");
2718#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002719 size_type __old_sz = size();
2720 difference_type __ip = __pos - begin();
2721 for (; __first != __last; ++__first)
2722 push_back(*__first);
2723 pointer __p = __get_pointer();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002724 _VSTD::rotate(__p + __ip, __p + __old_sz, __p + size());
Howard Hinnant499cea12013-08-23 17:37:05 +00002725#if _LIBCPP_DEBUG_LEVEL >= 2
2726 return iterator(this, __p + __ip);
2727#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002728 return iterator(__p + __ip);
Howard Hinnant499cea12013-08-23 17:37:05 +00002729#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002730}
2731
2732template <class _CharT, class _Traits, class _Allocator>
2733template<class _ForwardIterator>
2734typename enable_if
2735<
2736 __is_forward_iterator<_ForwardIterator>::value,
2737 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2738>::type
2739basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2740{
Howard Hinnant499cea12013-08-23 17:37:05 +00002741#if _LIBCPP_DEBUG_LEVEL >= 2
2742 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2743 "string::insert(iterator, range) called with an iterator not"
2744 " referring to this string");
2745#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002746 size_type __ip = static_cast<size_type>(__pos - begin());
2747 size_type __sz = size();
2748 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002749 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002750 if (__n)
2751 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002752 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002753 if (__cap - __sz >= __n)
2754 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002755 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002756 size_type __n_move = __sz - __ip;
2757 if (__n_move != 0)
2758 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2759 }
2760 else
2761 {
2762 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002763 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002764 }
2765 __sz += __n;
2766 __set_size(__sz);
2767 traits_type::assign(__p[__sz], value_type());
2768 for (__p += __ip; __first != __last; ++__p, ++__first)
2769 traits_type::assign(*__p, *__first);
2770 }
2771 return begin() + __ip;
2772}
2773
2774template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002775inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002776basic_string<_CharT, _Traits, _Allocator>&
2777basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2778{
2779 return insert(__pos1, __str.data(), __str.size());
2780}
2781
2782template <class _CharT, class _Traits, class _Allocator>
2783basic_string<_CharT, _Traits, _Allocator>&
2784basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2785 size_type __pos2, size_type __n)
2786{
2787 size_type __str_sz = __str.size();
2788 if (__pos2 > __str_sz)
2789 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002790 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002791}
2792
2793template <class _CharT, class _Traits, class _Allocator>
2794basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002795basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002796{
Alp Tokerec34c482014-05-15 11:27:39 +00002797 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002798 return insert(__pos, __s, traits_type::length(__s));
2799}
2800
2801template <class _CharT, class _Traits, class _Allocator>
2802typename basic_string<_CharT, _Traits, _Allocator>::iterator
2803basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2804{
2805 size_type __ip = static_cast<size_type>(__pos - begin());
2806 size_type __sz = size();
2807 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002808 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002809 if (__cap == __sz)
2810 {
2811 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002812 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002813 }
2814 else
2815 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002816 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002817 size_type __n_move = __sz - __ip;
2818 if (__n_move != 0)
2819 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2820 }
2821 traits_type::assign(__p[__ip], __c);
2822 traits_type::assign(__p[++__sz], value_type());
2823 __set_size(__sz);
2824 return begin() + static_cast<difference_type>(__ip);
2825}
2826
2827template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002828inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002829typename basic_string<_CharT, _Traits, _Allocator>::iterator
2830basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2831{
Howard Hinnant499cea12013-08-23 17:37:05 +00002832#if _LIBCPP_DEBUG_LEVEL >= 2
2833 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2834 "string::insert(iterator, n, value) called with an iterator not"
2835 " referring to this string");
2836#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002837 difference_type __p = __pos - begin();
2838 insert(static_cast<size_type>(__p), __n, __c);
2839 return begin() + __p;
2840}
2841
2842// replace
2843
2844template <class _CharT, class _Traits, class _Allocator>
2845basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002846basic_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 +00002847{
Alp Tokerec34c482014-05-15 11:27:39 +00002848 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002849 size_type __sz = size();
2850 if (__pos > __sz)
2851 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002852 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002853 size_type __cap = capacity();
2854 if (__cap - __sz + __n1 >= __n2)
2855 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002856 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002857 if (__n1 != __n2)
2858 {
2859 size_type __n_move = __sz - __pos - __n1;
2860 if (__n_move != 0)
2861 {
2862 if (__n1 > __n2)
2863 {
2864 traits_type::move(__p + __pos, __s, __n2);
2865 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2866 goto __finish;
2867 }
2868 if (__p + __pos < __s && __s < __p + __sz)
2869 {
2870 if (__p + __pos + __n1 <= __s)
2871 __s += __n2 - __n1;
2872 else // __p + __pos < __s < __p + __pos + __n1
2873 {
2874 traits_type::move(__p + __pos, __s, __n1);
2875 __pos += __n1;
2876 __s += __n2;
2877 __n2 -= __n1;
2878 __n1 = 0;
2879 }
2880 }
2881 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2882 }
2883 }
2884 traits_type::move(__p + __pos, __s, __n2);
2885__finish:
2886 __sz += __n2 - __n1;
2887 __set_size(__sz);
2888 __invalidate_iterators_past(__sz);
2889 traits_type::assign(__p[__sz], value_type());
2890 }
2891 else
2892 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2893 return *this;
2894}
2895
2896template <class _CharT, class _Traits, class _Allocator>
2897basic_string<_CharT, _Traits, _Allocator>&
2898basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
2899{
2900 size_type __sz = size();
2901 if (__pos > __sz)
2902 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002903 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002904 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002905 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002906 if (__cap - __sz + __n1 >= __n2)
2907 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002908 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002909 if (__n1 != __n2)
2910 {
2911 size_type __n_move = __sz - __pos - __n1;
2912 if (__n_move != 0)
2913 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2914 }
2915 }
2916 else
2917 {
2918 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002919 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002920 }
2921 traits_type::assign(__p + __pos, __n2, __c);
2922 __sz += __n2 - __n1;
2923 __set_size(__sz);
2924 __invalidate_iterators_past(__sz);
2925 traits_type::assign(__p[__sz], value_type());
2926 return *this;
2927}
2928
2929template <class _CharT, class _Traits, class _Allocator>
2930template<class _InputIterator>
2931typename enable_if
2932<
2933 __is_input_iterator<_InputIterator>::value,
2934 basic_string<_CharT, _Traits, _Allocator>&
2935>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002936basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002937 _InputIterator __j1, _InputIterator __j2)
2938{
2939 for (; true; ++__i1, ++__j1)
2940 {
2941 if (__i1 == __i2)
2942 {
2943 if (__j1 != __j2)
2944 insert(__i1, __j1, __j2);
2945 break;
2946 }
2947 if (__j1 == __j2)
2948 {
2949 erase(__i1, __i2);
2950 break;
2951 }
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002952 traits_type::assign(const_cast<value_type&>(*__i1), *__j1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002953 }
2954 return *this;
2955}
2956
2957template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002958inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002959basic_string<_CharT, _Traits, _Allocator>&
2960basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2961{
2962 return replace(__pos1, __n1, __str.data(), __str.size());
2963}
2964
2965template <class _CharT, class _Traits, class _Allocator>
2966basic_string<_CharT, _Traits, _Allocator>&
2967basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2968 size_type __pos2, size_type __n2)
2969{
2970 size_type __str_sz = __str.size();
2971 if (__pos2 > __str_sz)
2972 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002973 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002974}
2975
2976template <class _CharT, class _Traits, class _Allocator>
2977basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002978basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002979{
Alp Tokerec34c482014-05-15 11:27:39 +00002980 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002981 return replace(__pos, __n1, __s, traits_type::length(__s));
2982}
2983
2984template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002985inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002986basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002987basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002988{
2989 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2990 __str.data(), __str.size());
2991}
2992
2993template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002994inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002995basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002996basic_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 +00002997{
2998 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2999}
3000
3001template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003002inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003003basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003004basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003005{
3006 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
3007}
3008
3009template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003010inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003011basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00003012basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003013{
3014 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
3015}
3016
3017// erase
3018
3019template <class _CharT, class _Traits, class _Allocator>
3020basic_string<_CharT, _Traits, _Allocator>&
3021basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
3022{
3023 size_type __sz = size();
3024 if (__pos > __sz)
3025 this->__throw_out_of_range();
3026 if (__n)
3027 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003028 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00003029 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003030 size_type __n_move = __sz - __pos - __n;
3031 if (__n_move != 0)
3032 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
3033 __sz -= __n;
3034 __set_size(__sz);
3035 __invalidate_iterators_past(__sz);
3036 traits_type::assign(__p[__sz], value_type());
3037 }
3038 return *this;
3039}
3040
3041template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003042inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003043typename basic_string<_CharT, _Traits, _Allocator>::iterator
3044basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
3045{
Howard Hinnant499cea12013-08-23 17:37:05 +00003046#if _LIBCPP_DEBUG_LEVEL >= 2
3047 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
3048 "string::erase(iterator) called with an iterator not"
3049 " referring to this string");
3050#endif
3051 _LIBCPP_ASSERT(__pos != end(),
3052 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003053 iterator __b = begin();
3054 size_type __r = static_cast<size_type>(__pos - __b);
3055 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00003056 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003057}
3058
3059template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003060inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003061typename basic_string<_CharT, _Traits, _Allocator>::iterator
3062basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
3063{
Howard Hinnant499cea12013-08-23 17:37:05 +00003064#if _LIBCPP_DEBUG_LEVEL >= 2
3065 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
3066 "string::erase(iterator, iterator) called with an iterator not"
3067 " referring to this string");
3068#endif
3069 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003070 iterator __b = begin();
3071 size_type __r = static_cast<size_type>(__first - __b);
3072 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00003073 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003074}
3075
3076template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003077inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003078void
3079basic_string<_CharT, _Traits, _Allocator>::pop_back()
3080{
Howard Hinnant499cea12013-08-23 17:37:05 +00003081 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003082 size_type __sz;
3083 if (__is_long())
3084 {
3085 __sz = __get_long_size() - 1;
3086 __set_long_size(__sz);
3087 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3088 }
3089 else
3090 {
3091 __sz = __get_short_size() - 1;
3092 __set_short_size(__sz);
3093 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3094 }
3095 __invalidate_iterators_past(__sz);
3096}
3097
3098template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003099inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003100void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003101basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003102{
3103 __invalidate_all_iterators();
3104 if (__is_long())
3105 {
3106 traits_type::assign(*__get_long_pointer(), value_type());
3107 __set_long_size(0);
3108 }
3109 else
3110 {
3111 traits_type::assign(*__get_short_pointer(), value_type());
3112 __set_short_size(0);
3113 }
3114}
3115
3116template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003117inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003118void
3119basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3120{
3121 if (__is_long())
3122 {
3123 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3124 __set_long_size(__pos);
3125 }
3126 else
3127 {
3128 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3129 __set_short_size(__pos);
3130 }
3131 __invalidate_iterators_past(__pos);
3132}
3133
3134template <class _CharT, class _Traits, class _Allocator>
3135void
3136basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3137{
3138 size_type __sz = size();
3139 if (__n > __sz)
3140 append(__n - __sz, __c);
3141 else
3142 __erase_to_end(__n);
3143}
3144
3145template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003146inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003147typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003148basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003149{
Howard Hinnante32b5e22010-11-17 17:55:08 +00003150 size_type __m = __alloc_traits::max_size(__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003151#if _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:08 +00003152 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003153#else
Marshall Clow09f85502013-10-31 17:23:08 +00003154 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003155#endif
3156}
3157
3158template <class _CharT, class _Traits, class _Allocator>
3159void
3160basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
3161{
3162 if (__res_arg > max_size())
3163 this->__throw_length_error();
3164 size_type __cap = capacity();
3165 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003166 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003167 __res_arg = __recommend(__res_arg);
3168 if (__res_arg != __cap)
3169 {
3170 pointer __new_data, __p;
3171 bool __was_long, __now_long;
3172 if (__res_arg == __min_cap - 1)
3173 {
3174 __was_long = true;
3175 __now_long = false;
3176 __new_data = __get_short_pointer();
3177 __p = __get_long_pointer();
3178 }
3179 else
3180 {
3181 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003182 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003183 else
3184 {
3185 #ifndef _LIBCPP_NO_EXCEPTIONS
3186 try
3187 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003188 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00003189 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003190 #ifndef _LIBCPP_NO_EXCEPTIONS
3191 }
3192 catch (...)
3193 {
3194 return;
3195 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003196 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003197 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003198 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00003199 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003200 }
3201 __now_long = true;
3202 __was_long = __is_long();
3203 __p = __get_pointer();
3204 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003205 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
3206 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003207 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003208 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003209 if (__now_long)
3210 {
3211 __set_long_cap(__res_arg+1);
3212 __set_long_size(__sz);
3213 __set_long_pointer(__new_data);
3214 }
3215 else
3216 __set_short_size(__sz);
3217 __invalidate_all_iterators();
3218 }
3219}
3220
3221template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003222inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003223typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3224basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const
3225{
Howard Hinnant499cea12013-08-23 17:37:05 +00003226 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003227 return *(data() + __pos);
3228}
3229
3230template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003231inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003232typename basic_string<_CharT, _Traits, _Allocator>::reference
3233basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos)
3234{
Howard Hinnant499cea12013-08-23 17:37:05 +00003235 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003236 return *(__get_pointer() + __pos);
3237}
3238
3239template <class _CharT, class _Traits, class _Allocator>
3240typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3241basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3242{
3243 if (__n >= size())
3244 this->__throw_out_of_range();
3245 return (*this)[__n];
3246}
3247
3248template <class _CharT, class _Traits, class _Allocator>
3249typename basic_string<_CharT, _Traits, _Allocator>::reference
3250basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3251{
3252 if (__n >= size())
3253 this->__throw_out_of_range();
3254 return (*this)[__n];
3255}
3256
3257template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003258inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003259typename basic_string<_CharT, _Traits, _Allocator>::reference
3260basic_string<_CharT, _Traits, _Allocator>::front()
3261{
Howard Hinnant499cea12013-08-23 17:37:05 +00003262 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003263 return *__get_pointer();
3264}
3265
3266template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003267inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003268typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3269basic_string<_CharT, _Traits, _Allocator>::front() const
3270{
Howard Hinnant499cea12013-08-23 17:37:05 +00003271 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003272 return *data();
3273}
3274
3275template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003276inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003277typename basic_string<_CharT, _Traits, _Allocator>::reference
3278basic_string<_CharT, _Traits, _Allocator>::back()
3279{
Howard Hinnant499cea12013-08-23 17:37:05 +00003280 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003281 return *(__get_pointer() + size() - 1);
3282}
3283
3284template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003285inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003286typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3287basic_string<_CharT, _Traits, _Allocator>::back() const
3288{
Howard Hinnant499cea12013-08-23 17:37:05 +00003289 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003290 return *(data() + size() - 1);
3291}
3292
3293template <class _CharT, class _Traits, class _Allocator>
3294typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003295basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003296{
3297 size_type __sz = size();
3298 if (__pos > __sz)
3299 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003300 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003301 traits_type::copy(__s, data() + __pos, __rlen);
3302 return __rlen;
3303}
3304
3305template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003306inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003307basic_string<_CharT, _Traits, _Allocator>
3308basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3309{
3310 return basic_string(*this, __pos, __n, __alloc());
3311}
3312
3313template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003314inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003315void
3316basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00003317 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3318 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003319{
Howard Hinnant499cea12013-08-23 17:37:05 +00003320#if _LIBCPP_DEBUG_LEVEL >= 2
3321 if (!__is_long())
3322 __get_db()->__invalidate_all(this);
3323 if (!__str.__is_long())
3324 __get_db()->__invalidate_all(&__str);
3325 __get_db()->swap(this, &__str);
3326#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00003327 _VSTD::swap(__r_.first(), __str.__r_.first());
Howard Hinnante32b5e22010-11-17 17:55:08 +00003328 __swap_alloc(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003329}
3330
3331// find
3332
3333template <class _Traits>
3334struct _LIBCPP_HIDDEN __traits_eq
3335{
3336 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003337 _LIBCPP_INLINE_VISIBILITY
3338 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3339 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003340};
3341
3342template<class _CharT, class _Traits, class _Allocator>
3343typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003344basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003345 size_type __pos,
3346 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003347{
Alp Tokerec34c482014-05-15 11:27:39 +00003348 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003349 size_type __sz = size();
3350 if (__pos > __sz || __sz - __pos < __n)
3351 return npos;
3352 if (__n == 0)
3353 return __pos;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003354 const value_type* __p = data();
3355 const value_type* __r = _VSTD::search(__p + __pos, __p + __sz, __s, __s + __n,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003356 __traits_eq<traits_type>());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003357 if (__r == __p + __sz)
3358 return npos;
3359 return static_cast<size_type>(__r - __p);
3360}
3361
3362template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003363inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003364typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003365basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3366 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003367{
3368 return find(__str.data(), __pos, __str.size());
3369}
3370
3371template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003372inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003373typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003374basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003375 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003376{
Alp Tokerec34c482014-05-15 11:27:39 +00003377 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003378 return find(__s, __pos, traits_type::length(__s));
3379}
3380
3381template<class _CharT, class _Traits, class _Allocator>
3382typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003383basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3384 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003385{
3386 size_type __sz = size();
3387 if (__pos >= __sz)
3388 return npos;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003389 const value_type* __p = data();
3390 const value_type* __r = traits_type::find(__p + __pos, __sz - __pos, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003391 if (__r == 0)
3392 return npos;
3393 return static_cast<size_type>(__r - __p);
3394}
3395
3396// rfind
3397
3398template<class _CharT, class _Traits, class _Allocator>
3399typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003400basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003401 size_type __pos,
3402 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003403{
Alp Tokerec34c482014-05-15 11:27:39 +00003404 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003405 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003406 __pos = _VSTD::min(__pos, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003407 if (__n < __sz - __pos)
3408 __pos += __n;
3409 else
3410 __pos = __sz;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003411 const value_type* __p = data();
3412 const value_type* __r = _VSTD::find_end(__p, __p + __pos, __s, __s + __n,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003413 __traits_eq<traits_type>());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003414 if (__n > 0 && __r == __p + __pos)
3415 return npos;
3416 return static_cast<size_type>(__r - __p);
3417}
3418
3419template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003420inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003421typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003422basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3423 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003424{
3425 return rfind(__str.data(), __pos, __str.size());
3426}
3427
3428template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003429inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003430typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003431basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003432 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003433{
Alp Tokerec34c482014-05-15 11:27:39 +00003434 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003435 return rfind(__s, __pos, traits_type::length(__s));
3436}
3437
3438template<class _CharT, class _Traits, class _Allocator>
3439typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003440basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3441 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003442{
3443 size_type __sz = size();
3444 if (__sz)
3445 {
3446 if (__pos < __sz)
3447 ++__pos;
3448 else
3449 __pos = __sz;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003450 const value_type* __p = data();
3451 for (const value_type* __ps = __p + __pos; __ps != __p;)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003452 {
3453 if (traits_type::eq(*--__ps, __c))
3454 return static_cast<size_type>(__ps - __p);
3455 }
3456 }
3457 return npos;
3458}
3459
3460// find_first_of
3461
3462template<class _CharT, class _Traits, class _Allocator>
3463typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003464basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003465 size_type __pos,
3466 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003467{
Alp Tokerec34c482014-05-15 11:27:39 +00003468 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clowb671fc92013-12-09 16:00:28 +00003469 return _VSTD::__find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003470 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003471}
3472
3473template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003474inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003475typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003476basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3477 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003478{
Marshall Clowb671fc92013-12-09 16:00:28 +00003479 return _VSTD::__find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003480 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003481}
3482
3483template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003484inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003485typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003486basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003487 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003488{
Alp Tokerec34c482014-05-15 11:27:39 +00003489 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clowb671fc92013-12-09 16:00:28 +00003490 return _VSTD::__find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003491 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003492}
3493
3494template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003495inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003496typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003497basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3498 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003499{
3500 return find(__c, __pos);
3501}
3502
3503// find_last_of
3504
3505template<class _CharT, class _Traits, class _Allocator>
3506typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003507basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003508 size_type __pos,
3509 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003510{
Alp Tokerec34c482014-05-15 11:27:39 +00003511 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clowb671fc92013-12-09 16:00:28 +00003512 return _VSTD::__find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003513 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003514}
3515
3516template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003517inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003518typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003519basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3520 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003521{
Marshall Clowb671fc92013-12-09 16:00:28 +00003522 return _VSTD::__find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003523 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003524}
3525
3526template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003527inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003528typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003529basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003530 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003531{
Alp Tokerec34c482014-05-15 11:27:39 +00003532 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clowb671fc92013-12-09 16:00:28 +00003533 return _VSTD::__find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003534 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003535}
3536
3537template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003538inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003539typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003540basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3541 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003542{
3543 return rfind(__c, __pos);
3544}
3545
3546// find_first_not_of
3547
3548template<class _CharT, class _Traits, class _Allocator>
3549typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003550basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003551 size_type __pos,
3552 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003553{
Alp Tokerec34c482014-05-15 11:27:39 +00003554 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clowb671fc92013-12-09 16:00:28 +00003555 return _VSTD::__find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003556 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003557}
3558
3559template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003560inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003561typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003562basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3563 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003564{
Marshall Clowb671fc92013-12-09 16:00:28 +00003565 return _VSTD::__find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003566 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003567}
3568
3569template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003570inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003571typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003572basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003573 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003574{
Alp Tokerec34c482014-05-15 11:27:39 +00003575 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clowb671fc92013-12-09 16:00:28 +00003576 return _VSTD::__find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003577 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003578}
3579
3580template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003581inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003582typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003583basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3584 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003585{
Marshall Clowb671fc92013-12-09 16:00:28 +00003586 return _VSTD::__find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003587 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003588}
3589
3590// find_last_not_of
3591
3592template<class _CharT, class _Traits, class _Allocator>
3593typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003594basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003595 size_type __pos,
3596 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003597{
Alp Tokerec34c482014-05-15 11:27:39 +00003598 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clowb671fc92013-12-09 16:00:28 +00003599 return _VSTD::__find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003600 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003601}
3602
3603template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003604inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003605typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003606basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3607 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003608{
Marshall Clowb671fc92013-12-09 16:00:28 +00003609 return _VSTD::__find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003610 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003611}
3612
3613template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003614inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003615typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003616basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003617 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003618{
Alp Tokerec34c482014-05-15 11:27:39 +00003619 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clowb671fc92013-12-09 16:00:28 +00003620 return _VSTD::__find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003621 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003622}
3623
3624template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003625inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003626typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003627basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3628 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003629{
Marshall Clowb671fc92013-12-09 16:00:28 +00003630 return _VSTD::__find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003631 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003632}
3633
3634// compare
3635
3636template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003637inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003638int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003639basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003640{
Howard Hinnantfa06d752011-07-24 21:45:06 +00003641 size_t __lhs_sz = size();
3642 size_t __rhs_sz = __str.size();
3643 int __result = traits_type::compare(data(), __str.data(),
3644 _VSTD::min(__lhs_sz, __rhs_sz));
3645 if (__result != 0)
3646 return __result;
3647 if (__lhs_sz < __rhs_sz)
3648 return -1;
3649 if (__lhs_sz > __rhs_sz)
3650 return 1;
3651 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003652}
3653
3654template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003655inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003656int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003657basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3658 size_type __n1,
3659 const basic_string& __str) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003660{
3661 return compare(__pos1, __n1, __str.data(), __str.size());
3662}
3663
3664template <class _CharT, class _Traits, class _Allocator>
3665int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003666basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3667 size_type __n1,
3668 const basic_string& __str,
3669 size_type __pos2,
3670 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003671{
3672 size_type __sz = __str.size();
3673 if (__pos2 > __sz)
3674 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003675 return compare(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003676 __sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003677}
3678
3679template <class _CharT, class _Traits, class _Allocator>
3680int
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003681basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003682{
Alp Tokerec34c482014-05-15 11:27:39 +00003683 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003684 return compare(0, npos, __s, traits_type::length(__s));
3685}
3686
3687template <class _CharT, class _Traits, class _Allocator>
3688int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003689basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3690 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003691 const value_type* __s) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003692{
Alp Tokerec34c482014-05-15 11:27:39 +00003693 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003694 return compare(__pos1, __n1, __s, traits_type::length(__s));
3695}
3696
3697template <class _CharT, class _Traits, class _Allocator>
3698int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003699basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3700 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003701 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003702 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003703{
Alp Tokerec34c482014-05-15 11:27:39 +00003704 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003705 size_type __sz = size();
3706 if (__pos1 > __sz || __n2 == npos)
3707 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003708 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3709 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003710 if (__r == 0)
3711 {
3712 if (__rlen < __n2)
3713 __r = -1;
3714 else if (__rlen > __n2)
3715 __r = 1;
3716 }
3717 return __r;
3718}
3719
3720// __invariants
3721
3722template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003723inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003724bool
3725basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3726{
3727 if (size() > capacity())
3728 return false;
3729 if (capacity() < __min_cap - 1)
3730 return false;
3731 if (data() == 0)
3732 return false;
3733 if (data()[size()] != value_type(0))
3734 return false;
3735 return true;
3736}
3737
3738// operator==
3739
3740template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003741inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003742bool
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 Hinnant08dd2532013-04-22 23:55:13 +00003746 size_t __lhs_sz = __lhs.size();
3747 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3748 __rhs.data(),
3749 __lhs_sz) == 0;
3750}
3751
3752template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003753inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:13 +00003754bool
3755operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3756 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3757{
3758 size_t __lhs_sz = __lhs.size();
3759 if (__lhs_sz != __rhs.size())
3760 return false;
3761 const char* __lp = __lhs.data();
3762 const char* __rp = __rhs.data();
3763 if (__lhs.__is_long())
3764 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3765 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3766 if (*__lp != *__rp)
3767 return false;
3768 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003769}
3770
3771template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003772inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003773bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003774operator==(const _CharT* __lhs,
3775 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003776{
3777 return __rhs.compare(__lhs) == 0;
3778}
3779
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003780template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003781inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003782bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003783operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3784 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003785{
3786 return __lhs.compare(__rhs) == 0;
3787}
3788
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003789// operator!=
3790
Howard Hinnant324bb032010-08-22 00:02:43 +00003791template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003792inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003793bool
3794operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003795 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003796{
3797 return !(__lhs == __rhs);
3798}
3799
3800template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003801inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003802bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003803operator!=(const _CharT* __lhs,
3804 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003805{
3806 return !(__lhs == __rhs);
3807}
3808
3809template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003810inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003811bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003812operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3813 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003814{
3815 return !(__lhs == __rhs);
3816}
3817
3818// operator<
3819
3820template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003821inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003822bool
3823operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003824 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003825{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003826 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003827}
3828
3829template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003830inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003831bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003832operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3833 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003834{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003835 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003836}
3837
3838template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003839inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003840bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003841operator< (const _CharT* __lhs,
3842 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003843{
3844 return __rhs.compare(__lhs) > 0;
3845}
3846
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003847// operator>
3848
3849template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003850inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003851bool
3852operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003853 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003854{
3855 return __rhs < __lhs;
3856}
3857
3858template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003859inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003860bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003861operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3862 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003863{
3864 return __rhs < __lhs;
3865}
3866
3867template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003868inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003869bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003870operator> (const _CharT* __lhs,
3871 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003872{
3873 return __rhs < __lhs;
3874}
3875
3876// operator<=
3877
3878template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003879inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003880bool
3881operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003882 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003883{
3884 return !(__rhs < __lhs);
3885}
3886
3887template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003888inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003889bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003890operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3891 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003892{
3893 return !(__rhs < __lhs);
3894}
3895
3896template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003897inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003898bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003899operator<=(const _CharT* __lhs,
3900 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003901{
3902 return !(__rhs < __lhs);
3903}
3904
3905// operator>=
3906
3907template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003908inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003909bool
3910operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003911 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003912{
3913 return !(__lhs < __rhs);
3914}
3915
3916template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003917inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003918bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003919operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3920 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003921{
3922 return !(__lhs < __rhs);
3923}
3924
3925template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003926inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003927bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003928operator>=(const _CharT* __lhs,
3929 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003930{
3931 return !(__lhs < __rhs);
3932}
3933
3934// operator +
3935
3936template<class _CharT, class _Traits, class _Allocator>
3937basic_string<_CharT, _Traits, _Allocator>
3938operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3939 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3940{
3941 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3942 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3943 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3944 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3945 __r.append(__rhs.data(), __rhs_sz);
3946 return __r;
3947}
3948
3949template<class _CharT, class _Traits, class _Allocator>
3950basic_string<_CharT, _Traits, _Allocator>
3951operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3952{
3953 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3954 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
3955 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3956 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
3957 __r.append(__rhs.data(), __rhs_sz);
3958 return __r;
3959}
3960
3961template<class _CharT, class _Traits, class _Allocator>
3962basic_string<_CharT, _Traits, _Allocator>
3963operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3964{
3965 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3966 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3967 __r.__init(&__lhs, 1, 1 + __rhs_sz);
3968 __r.append(__rhs.data(), __rhs_sz);
3969 return __r;
3970}
3971
3972template<class _CharT, class _Traits, class _Allocator>
3973basic_string<_CharT, _Traits, _Allocator>
3974operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
3975{
3976 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3977 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3978 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
3979 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3980 __r.append(__rhs, __rhs_sz);
3981 return __r;
3982}
3983
3984template<class _CharT, class _Traits, class _Allocator>
3985basic_string<_CharT, _Traits, _Allocator>
3986operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
3987{
3988 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3989 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3990 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
3991 __r.push_back(__rhs);
3992 return __r;
3993}
3994
Howard Hinnant73d21a42010-09-04 23:28:19 +00003995#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003996
3997template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003998inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003999basic_string<_CharT, _Traits, _Allocator>
4000operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4001{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004002 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004003}
4004
4005template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004006inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004007basic_string<_CharT, _Traits, _Allocator>
4008operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4009{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004010 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004011}
4012
4013template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004014inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004015basic_string<_CharT, _Traits, _Allocator>
4016operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4017{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004018 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004019}
4020
4021template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004022inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004023basic_string<_CharT, _Traits, _Allocator>
4024operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4025{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004026 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004027}
4028
4029template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004030inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004031basic_string<_CharT, _Traits, _Allocator>
4032operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4033{
4034 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004035 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004036}
4037
4038template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004039inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004040basic_string<_CharT, _Traits, _Allocator>
4041operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
4042{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004043 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004044}
4045
4046template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004047inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004048basic_string<_CharT, _Traits, _Allocator>
4049operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
4050{
4051 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004052 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004053}
4054
Howard Hinnant73d21a42010-09-04 23:28:19 +00004055#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004056
4057// swap
4058
4059template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004060inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004061void
Howard Hinnanta6119a82011-05-29 19:57:12 +00004062swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00004063 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4064 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004065{
4066 __lhs.swap(__rhs);
4067}
4068
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004069#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
4070
4071typedef basic_string<char16_t> u16string;
4072typedef basic_string<char32_t> u32string;
4073
Howard Hinnant324bb032010-08-22 00:02:43 +00004074#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004075
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004076_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4077_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4078_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4079_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4080_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004081
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004082_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
4083_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
4084_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004085
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004086_LIBCPP_FUNC_VIS string to_string(int __val);
4087_LIBCPP_FUNC_VIS string to_string(unsigned __val);
4088_LIBCPP_FUNC_VIS string to_string(long __val);
4089_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4090_LIBCPP_FUNC_VIS string to_string(long long __val);
4091_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4092_LIBCPP_FUNC_VIS string to_string(float __val);
4093_LIBCPP_FUNC_VIS string to_string(double __val);
4094_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004095
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004096_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4097_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4098_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4099_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4100_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004101
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004102_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
4103_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
4104_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004105
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004106_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4107_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4108_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4109_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4110_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4111_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4112_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4113_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4114_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004115
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004116template<class _CharT, class _Traits, class _Allocator>
4117 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4118 basic_string<_CharT, _Traits, _Allocator>::npos;
4119
4120template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004121struct _LIBCPP_TYPE_VIS_ONLY hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004122 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
4123{
4124 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00004125 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004126};
4127
4128template<class _CharT, class _Traits, class _Allocator>
4129size_t
4130hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00004131 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004132{
Sean Huntaffd9e52011-07-29 23:31:56 +00004133 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004134}
4135
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004136template<class _CharT, class _Traits, class _Allocator>
4137basic_ostream<_CharT, _Traits>&
4138operator<<(basic_ostream<_CharT, _Traits>& __os,
4139 const basic_string<_CharT, _Traits, _Allocator>& __str);
4140
4141template<class _CharT, class _Traits, class _Allocator>
4142basic_istream<_CharT, _Traits>&
4143operator>>(basic_istream<_CharT, _Traits>& __is,
4144 basic_string<_CharT, _Traits, _Allocator>& __str);
4145
4146template<class _CharT, class _Traits, class _Allocator>
4147basic_istream<_CharT, _Traits>&
4148getline(basic_istream<_CharT, _Traits>& __is,
4149 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4150
4151template<class _CharT, class _Traits, class _Allocator>
4152inline _LIBCPP_INLINE_VISIBILITY
4153basic_istream<_CharT, _Traits>&
4154getline(basic_istream<_CharT, _Traits>& __is,
4155 basic_string<_CharT, _Traits, _Allocator>& __str);
4156
4157#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4158
4159template<class _CharT, class _Traits, class _Allocator>
4160inline _LIBCPP_INLINE_VISIBILITY
4161basic_istream<_CharT, _Traits>&
4162getline(basic_istream<_CharT, _Traits>&& __is,
4163 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4164
4165template<class _CharT, class _Traits, class _Allocator>
4166inline _LIBCPP_INLINE_VISIBILITY
4167basic_istream<_CharT, _Traits>&
4168getline(basic_istream<_CharT, _Traits>&& __is,
4169 basic_string<_CharT, _Traits, _Allocator>& __str);
4170
4171#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4172
Howard Hinnant499cea12013-08-23 17:37:05 +00004173#if _LIBCPP_DEBUG_LEVEL >= 2
4174
4175template<class _CharT, class _Traits, class _Allocator>
4176bool
4177basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4178{
4179 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
4180 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
4181}
4182
4183template<class _CharT, class _Traits, class _Allocator>
4184bool
4185basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4186{
4187 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
4188 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
4189}
4190
4191template<class _CharT, class _Traits, class _Allocator>
4192bool
4193basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4194{
4195 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4196 return this->data() <= __p && __p <= this->data() + this->size();
4197}
4198
4199template<class _CharT, class _Traits, class _Allocator>
4200bool
4201basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4202{
4203 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4204 return this->data() <= __p && __p < this->data() + this->size();
4205}
4206
4207#endif // _LIBCPP_DEBUG_LEVEL >= 2
4208
Marshall Clow15234322013-07-23 17:05:24 +00004209#if _LIBCPP_STD_VER > 11
4210// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:32 +00004211inline namespace literals
Marshall Clow15234322013-07-23 17:05:24 +00004212{
4213 inline namespace string_literals
4214 {
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004215 inline _LIBCPP_INLINE_VISIBILITY
4216 basic_string<char> operator "" s( const char *__str, size_t __len )
4217 {
4218 return basic_string<char> (__str, __len);
4219 }
Marshall Clow15234322013-07-23 17:05:24 +00004220
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004221 inline _LIBCPP_INLINE_VISIBILITY
4222 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4223 {
4224 return basic_string<wchar_t> (__str, __len);
4225 }
Marshall Clow15234322013-07-23 17:05:24 +00004226
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004227 inline _LIBCPP_INLINE_VISIBILITY
4228 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4229 {
4230 return basic_string<char16_t> (__str, __len);
4231 }
Marshall Clow15234322013-07-23 17:05:24 +00004232
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004233 inline _LIBCPP_INLINE_VISIBILITY
4234 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4235 {
4236 return basic_string<char32_t> (__str, __len);
4237 }
Marshall Clow15234322013-07-23 17:05:24 +00004238 }
4239}
4240#endif
4241
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004242_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<char>)
4243_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<wchar_t>)
Howard Hinnant499cea12013-08-23 17:37:05 +00004244_LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004245
4246_LIBCPP_END_NAMESPACE_STD
4247
4248#endif // _LIBCPP_STRING