blob: d6c148ac6dab60e6b8486e73f109ad7dfe9bbba5 [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
Marshall Clow37025e12014-06-10 18:51:55 +0000993// __str_find
Marshall Clowb671fc92013-12-09 16:00:28 +0000994template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Marshall Clow360f3192014-06-02 02:22:49 +0000995_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +0000996__str_find(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +0000997 _CharT __c, _SizeT __pos) _NOEXCEPT
998{
999 if (__pos >= __sz)
1000 return __npos;
1001 const _CharT* __r = _Traits::find(__p + __pos, __sz - __pos, __c);
1002 if (__r == 0)
1003 return __npos;
1004 return static_cast<_SizeT>(__r - __p);
1005}
1006
1007template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1008_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001009__str_find(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001010 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1011{
1012 if (__pos > __sz || __sz - __pos < __n)
1013 return __npos;
1014 if (__n == 0)
1015 return __pos;
Marshall Clow360f3192014-06-02 02:22:49 +00001016 const _CharT* __r =
Marshall Clow37025e12014-06-10 18:51:55 +00001017 _VSTD::__search(__p + __pos, __p + __sz,
1018 __s, __s + __n, _Traits::eq,
1019 random_access_iterator_tag(), random_access_iterator_tag());
Marshall Clow360f3192014-06-02 02:22:49 +00001020 if (__r == __p + __sz)
1021 return __npos;
1022 return static_cast<_SizeT>(__r - __p);
1023}
1024
1025
Marshall Clow37025e12014-06-10 18:51:55 +00001026// __str_rfind
Marshall Clow360f3192014-06-02 02:22:49 +00001027
1028template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1029_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001030__str_rfind(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001031 _CharT __c, _SizeT __pos) _NOEXCEPT
1032{
1033 if (__sz < 1)
Marshall Clowd5549cc2014-07-17 15:32:20 +00001034 return __npos;
1035 if (__pos < __sz)
1036 ++__pos;
1037 else
1038 __pos = __sz;
1039 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1040 {
1041 if (_Traits::eq(*--__ps, __c))
1042 return static_cast<_SizeT>(__ps - __p);
1043 }
Marshall Clow360f3192014-06-02 02:22:49 +00001044 return __npos;
1045}
1046
1047template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1048_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001049__str_rfind(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001050 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1051{
1052 __pos = _VSTD::min(__pos, __sz);
1053 if (__n < __sz - __pos)
1054 __pos += __n;
1055 else
1056 __pos = __sz;
Marshall Clow37025e12014-06-10 18:51:55 +00001057 const _CharT* __r = _VSTD::__find_end(
1058 __p, __p + __pos, __s, __s + __n, _Traits::eq,
1059 random_access_iterator_tag(), random_access_iterator_tag());
Marshall Clow360f3192014-06-02 02:22:49 +00001060 if (__n > 0 && __r == __p + __pos)
1061 return __npos;
1062 return static_cast<_SizeT>(__r - __p);
1063}
1064
Marshall Clow37025e12014-06-10 18:51:55 +00001065// __str_find_first_of
Marshall Clow360f3192014-06-02 02:22:49 +00001066template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1067_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001068__str_find_first_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001069 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001070{
1071 if (__pos >= __sz || __n == 0)
1072 return __npos;
Marshall Clow37025e12014-06-10 18:51:55 +00001073 const _CharT* __r = _VSTD::__find_first_of_ce
Marshall Clowb671fc92013-12-09 16:00:28 +00001074 (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq );
1075 if (__r == __p + __sz)
1076 return __npos;
1077 return static_cast<_SizeT>(__r - __p);
1078}
1079
Marshall Clow360f3192014-06-02 02:22:49 +00001080
Marshall Clow37025e12014-06-10 18:51:55 +00001081// __str_find_last_of
Marshall Clowb671fc92013-12-09 16:00:28 +00001082template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Marshall Clow360f3192014-06-02 02:22:49 +00001083_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001084__str_find_last_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001085 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001086 {
1087 if (__n != 0)
1088 {
1089 if (__pos < __sz)
1090 ++__pos;
1091 else
1092 __pos = __sz;
1093 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1094 {
1095 const _CharT* __r = _Traits::find(__s, __n, *--__ps);
1096 if (__r)
1097 return static_cast<_SizeT>(__ps - __p);
1098 }
1099 }
1100 return __npos;
1101}
1102
1103
Marshall Clow37025e12014-06-10 18:51:55 +00001104// __str_find_first_not_of
Marshall Clowb671fc92013-12-09 16:00:28 +00001105template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Marshall Clow360f3192014-06-02 02:22:49 +00001106_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001107__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001108 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001109{
1110 if (__pos < __sz)
1111 {
1112 const _CharT* __pe = __p + __sz;
1113 for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
1114 if (_Traits::find(__s, __n, *__ps) == 0)
1115 return static_cast<_SizeT>(__ps - __p);
1116 }
1117 return __npos;
1118}
1119
1120
1121template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Marshall Clow360f3192014-06-02 02:22:49 +00001122_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001123__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001124 _CharT __c, _SizeT __pos) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001125{
1126 if (__pos < __sz)
1127 {
1128 const _CharT* __pe = __p + __sz;
1129 for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
1130 if (!_Traits::eq(*__ps, __c))
1131 return static_cast<_SizeT>(__ps - __p);
1132 }
1133 return __npos;
1134}
1135
1136
Marshall Clow37025e12014-06-10 18:51:55 +00001137// __str_find_last_not_of
Marshall Clowb671fc92013-12-09 16:00:28 +00001138template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Marshall Clow360f3192014-06-02 02:22:49 +00001139_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001140__str_find_last_not_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001141 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001142{
1143 if (__pos < __sz)
1144 ++__pos;
1145 else
1146 __pos = __sz;
1147 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1148 if (_Traits::find(__s, __n, *--__ps) == 0)
1149 return static_cast<_SizeT>(__ps - __p);
1150 return __npos;
1151}
1152
1153
1154template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Marshall Clow360f3192014-06-02 02:22:49 +00001155_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001156__str_find_last_not_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001157 _CharT __c, _SizeT __pos) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001158{
1159 if (__pos < __sz)
1160 ++__pos;
1161 else
1162 __pos = __sz;
1163 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1164 if (!_Traits::eq(*--__ps, __c))
1165 return static_cast<_SizeT>(__ps - __p);
1166 return __npos;
1167}
1168
1169template<class _Ptr>
1170size_t _LIBCPP_INLINE_VISIBILITY __do_string_hash(_Ptr __p, _Ptr __e)
1171{
1172 typedef typename iterator_traits<_Ptr>::value_type value_type;
1173 return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));
1174}
1175
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001176// basic_string
1177
1178template<class _CharT, class _Traits, class _Allocator>
1179basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001180operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
1181 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001182
1183template<class _CharT, class _Traits, class _Allocator>
1184basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001185operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001186
1187template<class _CharT, class _Traits, class _Allocator>
1188basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001189operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001190
1191template<class _CharT, class _Traits, class _Allocator>
1192basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001193operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001194
1195template<class _CharT, class _Traits, class _Allocator>
1196basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001197operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001198
1199template <bool>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001200class _LIBCPP_TYPE_VIS_ONLY __basic_string_common
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001201{
1202protected:
1203 void __throw_length_error() const;
1204 void __throw_out_of_range() const;
1205};
1206
1207template <bool __b>
1208void
1209__basic_string_common<__b>::__throw_length_error() const
1210{
1211#ifndef _LIBCPP_NO_EXCEPTIONS
1212 throw length_error("basic_string");
1213#else
1214 assert(!"basic_string length_error");
1215#endif
1216}
1217
1218template <bool __b>
1219void
1220__basic_string_common<__b>::__throw_out_of_range() const
1221{
1222#ifndef _LIBCPP_NO_EXCEPTIONS
1223 throw out_of_range("basic_string");
1224#else
1225 assert(!"basic_string out_of_range");
1226#endif
1227}
1228
Howard Hinnante9df0a52013-08-01 18:17:34 +00001229#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +00001230#pragma warning( push )
1231#pragma warning( disable: 4231 )
Howard Hinnante9df0a52013-08-01 18:17:34 +00001232#endif // _LIBCPP_MSVC
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001233_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __basic_string_common<true>)
Howard Hinnante9df0a52013-08-01 18:17:34 +00001234#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +00001235#pragma warning( pop )
Howard Hinnante9df0a52013-08-01 18:17:34 +00001236#endif // _LIBCPP_MSVC
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001237
Howard Hinnant15467182013-04-30 21:44:48 +00001238#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1239
1240template <class _CharT, size_t = sizeof(_CharT)>
1241struct __padding
1242{
1243 unsigned char __xx[sizeof(_CharT)-1];
1244};
1245
1246template <class _CharT>
1247struct __padding<_CharT, 1>
1248{
1249};
1250
1251#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1252
Howard Hinnant324bb032010-08-22 00:02:43 +00001253template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001254class _LIBCPP_TYPE_VIS_ONLY basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001255 : private __basic_string_common<true>
1256{
1257public:
1258 typedef basic_string __self;
1259 typedef _Traits traits_type;
1260 typedef typename traits_type::char_type value_type;
1261 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001262 typedef allocator_traits<allocator_type> __alloc_traits;
1263 typedef typename __alloc_traits::size_type size_type;
1264 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001265 typedef value_type& reference;
1266 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001267 typedef typename __alloc_traits::pointer pointer;
1268 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001269
Howard Hinnant499cea12013-08-23 17:37:05 +00001270 static_assert(is_pod<value_type>::value, "Character type of basic_string must be a POD");
1271 static_assert((is_same<_CharT, value_type>::value),
1272 "traits_type::char_type must be the same type as CharT");
1273 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1274 "Allocator::value_type must be same type as value_type");
1275#if defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001276 typedef pointer iterator;
1277 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001278#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001279 typedef __wrap_iter<pointer> iterator;
1280 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001281#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001282 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1283 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001284
1285private:
Howard Hinnant15467182013-04-30 21:44:48 +00001286
1287#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1288
1289 struct __long
1290 {
1291 pointer __data_;
1292 size_type __size_;
1293 size_type __cap_;
1294 };
1295
1296#if _LIBCPP_BIG_ENDIAN
1297 enum {__short_mask = 0x01};
1298 enum {__long_mask = 0x1ul};
1299#else // _LIBCPP_BIG_ENDIAN
1300 enum {__short_mask = 0x80};
1301 enum {__long_mask = ~(size_type(~0) >> 1)};
1302#endif // _LIBCPP_BIG_ENDIAN
1303
1304 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1305 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1306
1307 struct __short
1308 {
1309 value_type __data_[__min_cap];
1310 struct
1311 : __padding<value_type>
1312 {
1313 unsigned char __size_;
1314 };
1315 };
1316
1317#else
1318
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001319 struct __long
1320 {
1321 size_type __cap_;
1322 size_type __size_;
1323 pointer __data_;
1324 };
1325
1326#if _LIBCPP_BIG_ENDIAN
1327 enum {__short_mask = 0x80};
1328 enum {__long_mask = ~(size_type(~0) >> 1)};
Howard Hinnant324bb032010-08-22 00:02:43 +00001329#else // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001330 enum {__short_mask = 0x01};
Howard Hinnantec3773c2011-12-01 20:21:04 +00001331 enum {__long_mask = 0x1ul};
Howard Hinnant324bb032010-08-22 00:02:43 +00001332#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001333
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001334 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1335 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1336
1337 struct __short
1338 {
1339 union
1340 {
1341 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59 +00001342 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001343 };
1344 value_type __data_[__min_cap];
1345 };
1346
Howard Hinnant15467182013-04-30 21:44:48 +00001347#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1348
Howard Hinnant499cea12013-08-23 17:37:05 +00001349 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001350
Howard Hinnant499cea12013-08-23 17:37:05 +00001351 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001352
1353 struct __raw
1354 {
1355 size_type __words[__n_words];
1356 };
1357
1358 struct __rep
1359 {
1360 union
1361 {
1362 __long __l;
1363 __short __s;
1364 __raw __r;
1365 };
1366 };
1367
1368 __compressed_pair<__rep, allocator_type> __r_;
1369
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001370public:
1371 static const size_type npos = -1;
1372
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001373 _LIBCPP_INLINE_VISIBILITY basic_string()
1374 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001375 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001376 basic_string(const basic_string& __str);
1377 basic_string(const basic_string& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001378#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9f193f22011-01-26 00:06:59 +00001379 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001380 basic_string(basic_string&& __str)
1381 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant9f193f22011-01-26 00:06:59 +00001382 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001383 basic_string(basic_string&& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001384#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001385 _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001386 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001387 basic_string(const value_type* __s, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001388 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001389 basic_string(const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001390 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001391 basic_string(const value_type* __s, size_type __n, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001392 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001393 basic_string(size_type __n, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001394 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001395 basic_string(size_type __n, value_type __c, const allocator_type& __a);
1396 basic_string(const basic_string& __str, size_type __pos, size_type __n = npos,
1397 const allocator_type& __a = allocator_type());
1398 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001399 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001400 basic_string(_InputIterator __first, _InputIterator __last);
1401 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001402 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001403 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001404#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001405 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001406 basic_string(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001407 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001408 basic_string(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001409#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001410
1411 ~basic_string();
1412
Howard Hinnante32b5e22010-11-17 17:55:08 +00001413 basic_string& operator=(const basic_string& __str);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001414#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001415 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001416 basic_string& operator=(basic_string&& __str)
1417 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
1418 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001419#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001420 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001421 basic_string& operator=(value_type __c);
Howard Hinnante3e32912011-08-12 21:56:02 +00001422#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001423 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001424 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001425#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001426
Howard Hinnant499cea12013-08-23 17:37:05 +00001427#if _LIBCPP_DEBUG_LEVEL >= 2
1428 _LIBCPP_INLINE_VISIBILITY
1429 iterator begin() _NOEXCEPT
1430 {return iterator(this, __get_pointer());}
1431 _LIBCPP_INLINE_VISIBILITY
1432 const_iterator begin() const _NOEXCEPT
1433 {return const_iterator(this, __get_pointer());}
1434 _LIBCPP_INLINE_VISIBILITY
1435 iterator end() _NOEXCEPT
1436 {return iterator(this, __get_pointer() + size());}
1437 _LIBCPP_INLINE_VISIBILITY
1438 const_iterator end() const _NOEXCEPT
1439 {return const_iterator(this, __get_pointer() + size());}
1440#else
Howard Hinnanta6119a82011-05-29 19:57:12 +00001441 _LIBCPP_INLINE_VISIBILITY
1442 iterator begin() _NOEXCEPT
1443 {return iterator(__get_pointer());}
1444 _LIBCPP_INLINE_VISIBILITY
1445 const_iterator begin() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001446 {return const_iterator(__get_pointer());}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001447 _LIBCPP_INLINE_VISIBILITY
1448 iterator end() _NOEXCEPT
1449 {return iterator(__get_pointer() + size());}
1450 _LIBCPP_INLINE_VISIBILITY
1451 const_iterator end() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001452 {return const_iterator(__get_pointer() + size());}
Howard Hinnant499cea12013-08-23 17:37:05 +00001453#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnanta6119a82011-05-29 19:57:12 +00001454 _LIBCPP_INLINE_VISIBILITY
1455 reverse_iterator rbegin() _NOEXCEPT
1456 {return reverse_iterator(end());}
1457 _LIBCPP_INLINE_VISIBILITY
1458 const_reverse_iterator rbegin() const _NOEXCEPT
1459 {return const_reverse_iterator(end());}
1460 _LIBCPP_INLINE_VISIBILITY
1461 reverse_iterator rend() _NOEXCEPT
1462 {return reverse_iterator(begin());}
1463 _LIBCPP_INLINE_VISIBILITY
1464 const_reverse_iterator rend() const _NOEXCEPT
1465 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001466
Howard Hinnanta6119a82011-05-29 19:57:12 +00001467 _LIBCPP_INLINE_VISIBILITY
1468 const_iterator cbegin() const _NOEXCEPT
1469 {return begin();}
1470 _LIBCPP_INLINE_VISIBILITY
1471 const_iterator cend() const _NOEXCEPT
1472 {return end();}
1473 _LIBCPP_INLINE_VISIBILITY
1474 const_reverse_iterator crbegin() const _NOEXCEPT
1475 {return rbegin();}
1476 _LIBCPP_INLINE_VISIBILITY
1477 const_reverse_iterator crend() const _NOEXCEPT
1478 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001479
Howard Hinnanta6119a82011-05-29 19:57:12 +00001480 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001481 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001482 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
1483 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
1484 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001485 {return (__is_long() ? __get_long_cap() : __min_cap) - 1;}
1486
1487 void resize(size_type __n, value_type __c);
1488 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
1489
1490 void reserve(size_type res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001491 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001492 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001493 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001494 void clear() _NOEXCEPT;
1495 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001496
1497 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const;
1498 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos);
1499
1500 const_reference at(size_type __n) const;
1501 reference at(size_type __n);
1502
1503 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001504 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001505 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +00001506#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001507 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Howard Hinnante3e32912011-08-12 21:56:02 +00001508#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001509
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001511 basic_string& append(const basic_string& __str);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001512 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001513 basic_string& append(const value_type* __s, size_type __n);
1514 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001515 basic_string& append(size_type __n, value_type __c);
1516 template<class _InputIterator>
1517 typename enable_if
1518 <
1519 __is_input_iterator <_InputIterator>::value &&
1520 !__is_forward_iterator<_InputIterator>::value,
1521 basic_string&
1522 >::type
1523 append(_InputIterator __first, _InputIterator __last);
1524 template<class _ForwardIterator>
1525 typename enable_if
1526 <
1527 __is_forward_iterator<_ForwardIterator>::value,
1528 basic_string&
1529 >::type
1530 append(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001531#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001532 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001533 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001534#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001535
1536 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001537 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001538 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001539 _LIBCPP_INLINE_VISIBILITY reference front();
1540 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
1541 _LIBCPP_INLINE_VISIBILITY reference back();
1542 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001543
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001544 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001545 basic_string& assign(const basic_string& __str);
Howard Hinnanta6119a82011-05-29 19:57:12 +00001546#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1547 _LIBCPP_INLINE_VISIBILITY
1548 basic_string& assign(basic_string&& str)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001549 {*this = _VSTD::move(str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001550#endif
Marshall Clowa93b5e22014-03-04 19:17:19 +00001551 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001552 basic_string& assign(const value_type* __s, size_type __n);
1553 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001554 basic_string& assign(size_type __n, value_type __c);
1555 template<class _InputIterator>
1556 typename enable_if
1557 <
1558 __is_input_iterator <_InputIterator>::value &&
1559 !__is_forward_iterator<_InputIterator>::value,
1560 basic_string&
1561 >::type
1562 assign(_InputIterator __first, _InputIterator __last);
1563 template<class _ForwardIterator>
1564 typename enable_if
1565 <
1566 __is_forward_iterator<_ForwardIterator>::value,
1567 basic_string&
1568 >::type
1569 assign(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001570#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001571 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001572 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001573#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001574
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001575 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001576 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001577 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001578 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1579 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001580 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1581 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001583 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1584 template<class _InputIterator>
1585 typename enable_if
1586 <
1587 __is_input_iterator <_InputIterator>::value &&
1588 !__is_forward_iterator<_InputIterator>::value,
1589 iterator
1590 >::type
1591 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1592 template<class _ForwardIterator>
1593 typename enable_if
1594 <
1595 __is_forward_iterator<_ForwardIterator>::value,
1596 iterator
1597 >::type
1598 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001599#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001600 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001601 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1602 {return insert(__pos, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001603#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001604
1605 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001606 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001607 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001608 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001609 iterator erase(const_iterator __first, const_iterator __last);
1610
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001611 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001612 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001613 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 +00001614 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1615 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001616 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001618 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001619 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001620 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001622 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001624 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001625 template<class _InputIterator>
1626 typename enable_if
1627 <
1628 __is_input_iterator<_InputIterator>::value,
1629 basic_string&
1630 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001631 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Howard Hinnante3e32912011-08-12 21:56:02 +00001632#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001633 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001634 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001635 {return replace(__i1, __i2, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001636#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001637
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001638 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001639 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001640 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1641
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001642 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001643 void swap(basic_string& __str)
1644 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1645 __is_nothrow_swappable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001646
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001647 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001648 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001649 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001650 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001651
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001652 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001653 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001654
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001655 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001656 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001657 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001658 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001659 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001660 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001661
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001662 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001663 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001664 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001665 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001666 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001667 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001668
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001669 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001670 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001671 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001672 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001673 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001674 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001675 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001676
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001677 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001678 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001679 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001681 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001682 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001683 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001684
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001685 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001686 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001687 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 +00001688 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001689 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001690 _LIBCPP_INLINE_VISIBILITY
1691 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1692
1693 _LIBCPP_INLINE_VISIBILITY
1694 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001695 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 +00001696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001697 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001698 _LIBCPP_INLINE_VISIBILITY
1699 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1700
1701 _LIBCPP_INLINE_VISIBILITY
1702 int compare(const basic_string& __str) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001704 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clowa93b5e22014-03-04 19:17:19 +00001705 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 +00001706 int compare(const value_type* __s) const _NOEXCEPT;
1707 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1708 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001709
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001710 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:13 +00001711
1712 _LIBCPP_INLINE_VISIBILITY
1713 bool __is_long() const _NOEXCEPT
1714 {return bool(__r_.first().__s.__size_ & __short_mask);}
1715
Howard Hinnant499cea12013-08-23 17:37:05 +00001716#if _LIBCPP_DEBUG_LEVEL >= 2
1717
1718 bool __dereferenceable(const const_iterator* __i) const;
1719 bool __decrementable(const const_iterator* __i) const;
1720 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1721 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1722
1723#endif // _LIBCPP_DEBUG_LEVEL >= 2
1724
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001725private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001726 _LIBCPP_INLINE_VISIBILITY
1727 allocator_type& __alloc() _NOEXCEPT
1728 {return __r_.second();}
1729 _LIBCPP_INLINE_VISIBILITY
1730 const allocator_type& __alloc() const _NOEXCEPT
1731 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001732
Howard Hinnant15467182013-04-30 21:44:48 +00001733#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1734
Howard Hinnanta6119a82011-05-29 19:57:12 +00001735 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001736 void __set_short_size(size_type __s) _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001737# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001738 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:48 +00001739# else
1740 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1741# endif
1742
Howard Hinnanta6119a82011-05-29 19:57:12 +00001743 _LIBCPP_INLINE_VISIBILITY
1744 size_type __get_short_size() const _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001745# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001746 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:48 +00001747# else
1748 {return __r_.first().__s.__size_;}
1749# endif
1750
1751#else // _LIBCPP_ALTERNATE_STRING_LAYOUT
1752
1753 _LIBCPP_INLINE_VISIBILITY
1754 void __set_short_size(size_type __s) _NOEXCEPT
1755# if _LIBCPP_BIG_ENDIAN
1756 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1757# else
1758 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1759# endif
1760
1761 _LIBCPP_INLINE_VISIBILITY
1762 size_type __get_short_size() const _NOEXCEPT
1763# if _LIBCPP_BIG_ENDIAN
1764 {return __r_.first().__s.__size_;}
1765# else
1766 {return __r_.first().__s.__size_ >> 1;}
1767# endif
1768
1769#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1770
Howard Hinnanta6119a82011-05-29 19:57:12 +00001771 _LIBCPP_INLINE_VISIBILITY
1772 void __set_long_size(size_type __s) _NOEXCEPT
1773 {__r_.first().__l.__size_ = __s;}
1774 _LIBCPP_INLINE_VISIBILITY
1775 size_type __get_long_size() const _NOEXCEPT
1776 {return __r_.first().__l.__size_;}
1777 _LIBCPP_INLINE_VISIBILITY
1778 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001779 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1780
Howard Hinnanta6119a82011-05-29 19:57:12 +00001781 _LIBCPP_INLINE_VISIBILITY
1782 void __set_long_cap(size_type __s) _NOEXCEPT
1783 {__r_.first().__l.__cap_ = __long_mask | __s;}
1784 _LIBCPP_INLINE_VISIBILITY
1785 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001786 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001787
Howard Hinnanta6119a82011-05-29 19:57:12 +00001788 _LIBCPP_INLINE_VISIBILITY
1789 void __set_long_pointer(pointer __p) _NOEXCEPT
1790 {__r_.first().__l.__data_ = __p;}
1791 _LIBCPP_INLINE_VISIBILITY
1792 pointer __get_long_pointer() _NOEXCEPT
1793 {return __r_.first().__l.__data_;}
1794 _LIBCPP_INLINE_VISIBILITY
1795 const_pointer __get_long_pointer() const _NOEXCEPT
1796 {return __r_.first().__l.__data_;}
1797 _LIBCPP_INLINE_VISIBILITY
1798 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001799 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001800 _LIBCPP_INLINE_VISIBILITY
1801 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001802 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001803 _LIBCPP_INLINE_VISIBILITY
1804 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001805 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001806 _LIBCPP_INLINE_VISIBILITY
1807 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001808 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1809
Howard Hinnanta6119a82011-05-29 19:57:12 +00001810 _LIBCPP_INLINE_VISIBILITY
1811 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001812 {
1813 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1814 for (unsigned __i = 0; __i < __n_words; ++__i)
1815 __a[__i] = 0;
1816 }
1817
1818 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001819 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:20 +00001820 size_type __align_it(size_type __s) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +00001821 {return __s + (__a-1) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001822 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001823 static _LIBCPP_INLINE_VISIBILITY
1824 size_type __recommend(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001825 {return (__s < __min_cap ? __min_cap :
Howard Hinnant7f764502013-08-14 18:00:20 +00001826 __align_it<sizeof(value_type) < __alignment ?
Howard Hinnanta6119a82011-05-29 19:57:12 +00001827 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001828
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001829 void __init(const value_type* __s, size_type __sz, size_type __reserve);
1830 void __init(const value_type* __s, size_type __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001831 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001832
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001833 template <class _InputIterator>
1834 typename enable_if
1835 <
1836 __is_input_iterator <_InputIterator>::value &&
1837 !__is_forward_iterator<_InputIterator>::value,
1838 void
1839 >::type
1840 __init(_InputIterator __first, _InputIterator __last);
1841
1842 template <class _ForwardIterator>
1843 typename enable_if
1844 <
1845 __is_forward_iterator<_ForwardIterator>::value,
1846 void
1847 >::type
1848 __init(_ForwardIterator __first, _ForwardIterator __last);
1849
1850 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001851 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001852 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1853 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001854 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001855
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001857 void __erase_to_end(size_type __pos);
1858
Howard Hinnante32b5e22010-11-17 17:55:08 +00001859 _LIBCPP_INLINE_VISIBILITY
1860 void __copy_assign_alloc(const basic_string& __str)
1861 {__copy_assign_alloc(__str, integral_constant<bool,
1862 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1863
1864 _LIBCPP_INLINE_VISIBILITY
1865 void __copy_assign_alloc(const basic_string& __str, true_type)
1866 {
1867 if (__alloc() != __str.__alloc())
1868 {
1869 clear();
1870 shrink_to_fit();
1871 }
1872 __alloc() = __str.__alloc();
1873 }
1874
1875 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001876 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001877 {}
1878
1879#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00001881 void __move_assign(basic_string& __str, false_type);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001882 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001883 void __move_assign(basic_string& __str, true_type)
1884 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001885#endif
1886
1887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001888 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001889 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001890 _NOEXCEPT_(
1891 !__alloc_traits::propagate_on_container_move_assignment::value ||
1892 is_nothrow_move_assignable<allocator_type>::value)
1893 {__move_assign_alloc(__str, integral_constant<bool,
1894 __alloc_traits::propagate_on_container_move_assignment::value>());}
1895
1896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001897 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001898 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1899 {
1900 __alloc() = _VSTD::move(__c.__alloc());
1901 }
1902
1903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001904 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001905 _NOEXCEPT
1906 {}
1907
1908 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001909 static void __swap_alloc(allocator_type& __x, allocator_type& __y)
1910 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1911 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001912 {__swap_alloc(__x, __y, integral_constant<bool,
1913 __alloc_traits::propagate_on_container_swap::value>());}
1914
1915 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001916 static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
1917 _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001918 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001919 using _VSTD::swap;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001920 swap(__x, __y);
1921 }
1922 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001923 static void __swap_alloc(allocator_type&, allocator_type&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001924 {}
1925
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001926 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1927 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001928
1929 friend basic_string operator+<>(const basic_string&, const basic_string&);
1930 friend basic_string operator+<>(const value_type*, const basic_string&);
1931 friend basic_string operator+<>(value_type, const basic_string&);
1932 friend basic_string operator+<>(const basic_string&, const value_type*);
1933 friend basic_string operator+<>(const basic_string&, value_type);
1934};
1935
1936template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001937inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001938void
1939basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1940{
Howard Hinnant499cea12013-08-23 17:37:05 +00001941#if _LIBCPP_DEBUG_LEVEL >= 2
1942 __get_db()->__invalidate_all(this);
1943#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001944}
1945
1946template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001947inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001948void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001949basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant499cea12013-08-23 17:37:05 +00001950#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantec3773c2011-12-01 20:21:04 +00001951 __pos
1952#endif
1953 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001954{
Howard Hinnant499cea12013-08-23 17:37:05 +00001955#if _LIBCPP_DEBUG_LEVEL >= 2
1956 __c_node* __c = __get_db()->__find_c_and_lock(this);
1957 if (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001958 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001959 const_pointer __new_last = __get_pointer() + __pos;
1960 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001961 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001962 --__p;
1963 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1964 if (__i->base() > __new_last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001965 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001966 (*__p)->__c_ = nullptr;
1967 if (--__c->end_ != __p)
1968 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001969 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001970 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001971 __get_db()->unlock();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001972 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001973#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001974}
1975
1976template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001977inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001978basic_string<_CharT, _Traits, _Allocator>::basic_string()
1979 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001980{
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 __zero();
1985}
1986
1987template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001988inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001989basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
1990 : __r_(__a)
1991{
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 __zero();
1996}
1997
1998template <class _CharT, class _Traits, class _Allocator>
1999void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002000basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002001{
2002 if (__reserve > max_size())
2003 this->__throw_length_error();
2004 pointer __p;
2005 if (__reserve < __min_cap)
2006 {
2007 __set_short_size(__sz);
2008 __p = __get_short_pointer();
2009 }
2010 else
2011 {
2012 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002013 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002014 __set_long_pointer(__p);
2015 __set_long_cap(__cap+1);
2016 __set_long_size(__sz);
2017 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002018 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002019 traits_type::assign(__p[__sz], value_type());
2020}
2021
2022template <class _CharT, class _Traits, class _Allocator>
2023void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002024basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002025{
2026 if (__sz > max_size())
2027 this->__throw_length_error();
2028 pointer __p;
2029 if (__sz < __min_cap)
2030 {
2031 __set_short_size(__sz);
2032 __p = __get_short_pointer();
2033 }
2034 else
2035 {
2036 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002037 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002038 __set_long_pointer(__p);
2039 __set_long_cap(__cap+1);
2040 __set_long_size(__sz);
2041 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002042 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002043 traits_type::assign(__p[__sz], value_type());
2044}
2045
2046template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002047inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002048basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002049{
Howard Hinnant499cea12013-08-23 17:37:05 +00002050 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002051 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00002052#if _LIBCPP_DEBUG_LEVEL >= 2
2053 __get_db()->__insert_c(this);
2054#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002055}
2056
2057template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002058inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002059basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002060 : __r_(__a)
2061{
Howard Hinnant499cea12013-08-23 17:37:05 +00002062 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002063 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00002064#if _LIBCPP_DEBUG_LEVEL >= 2
2065 __get_db()->__insert_c(this);
2066#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002067}
2068
2069template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002070inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002071basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002072{
Howard Hinnant499cea12013-08-23 17:37:05 +00002073 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002074 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00002075#if _LIBCPP_DEBUG_LEVEL >= 2
2076 __get_db()->__insert_c(this);
2077#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002078}
2079
2080template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002081inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002082basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002083 : __r_(__a)
2084{
Howard Hinnant499cea12013-08-23 17:37:05 +00002085 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002086 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00002087#if _LIBCPP_DEBUG_LEVEL >= 2
2088 __get_db()->__insert_c(this);
2089#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002090}
2091
2092template <class _CharT, class _Traits, class _Allocator>
2093basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002094 : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002095{
2096 if (!__str.__is_long())
2097 __r_.first().__r = __str.__r_.first().__r;
2098 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002099 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00002100#if _LIBCPP_DEBUG_LEVEL >= 2
2101 __get_db()->__insert_c(this);
2102#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002103}
2104
2105template <class _CharT, class _Traits, class _Allocator>
2106basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
2107 : __r_(__a)
2108{
2109 if (!__str.__is_long())
2110 __r_.first().__r = __str.__r_.first().__r;
2111 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002112 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00002113#if _LIBCPP_DEBUG_LEVEL >= 2
2114 __get_db()->__insert_c(this);
2115#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002116}
2117
Howard Hinnant73d21a42010-09-04 23:28:19 +00002118#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002119
2120template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002121inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002122basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
2123 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002124 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002125{
2126 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:05 +00002127#if _LIBCPP_DEBUG_LEVEL >= 2
2128 __get_db()->__insert_c(this);
2129 if (__is_long())
2130 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002131#endif
2132}
2133
2134template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002135inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002136basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002137 : __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002138{
Marshall Clowd5549cc2014-07-17 15:32:20 +00002139 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002140 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd5549cc2014-07-17 15:32:20 +00002141 else
2142 {
2143 __r_.first().__r = __str.__r_.first().__r;
2144 __str.__zero();
2145 }
Howard Hinnant499cea12013-08-23 17:37:05 +00002146#if _LIBCPP_DEBUG_LEVEL >= 2
2147 __get_db()->__insert_c(this);
2148 if (__is_long())
2149 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002150#endif
2151}
2152
Howard Hinnant73d21a42010-09-04 23:28:19 +00002153#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002154
2155template <class _CharT, class _Traits, class _Allocator>
2156void
2157basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
2158{
2159 if (__n > max_size())
2160 this->__throw_length_error();
2161 pointer __p;
2162 if (__n < __min_cap)
2163 {
2164 __set_short_size(__n);
2165 __p = __get_short_pointer();
2166 }
2167 else
2168 {
2169 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002170 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002171 __set_long_pointer(__p);
2172 __set_long_cap(__cap+1);
2173 __set_long_size(__n);
2174 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002175 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002176 traits_type::assign(__p[__n], value_type());
2177}
2178
2179template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002180inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002181basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
2182{
2183 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00002184#if _LIBCPP_DEBUG_LEVEL >= 2
2185 __get_db()->__insert_c(this);
2186#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002187}
2188
2189template <class _CharT, class _Traits, class _Allocator>
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(size_type __n, value_type __c, const allocator_type& __a)
2192 : __r_(__a)
2193{
2194 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00002195#if _LIBCPP_DEBUG_LEVEL >= 2
2196 __get_db()->__insert_c(this);
2197#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002198}
2199
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002200template <class _CharT, class _Traits, class _Allocator>
2201basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
2202 const allocator_type& __a)
2203 : __r_(__a)
2204{
2205 size_type __str_sz = __str.size();
2206 if (__pos > __str_sz)
2207 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002208 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant499cea12013-08-23 17:37:05 +00002209#if _LIBCPP_DEBUG_LEVEL >= 2
2210 __get_db()->__insert_c(this);
2211#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002212}
2213
2214template <class _CharT, class _Traits, class _Allocator>
2215template <class _InputIterator>
2216typename enable_if
2217<
2218 __is_input_iterator <_InputIterator>::value &&
2219 !__is_forward_iterator<_InputIterator>::value,
2220 void
2221>::type
2222basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2223{
2224 __zero();
2225#ifndef _LIBCPP_NO_EXCEPTIONS
2226 try
2227 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002228#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002229 for (; __first != __last; ++__first)
2230 push_back(*__first);
2231#ifndef _LIBCPP_NO_EXCEPTIONS
2232 }
2233 catch (...)
2234 {
2235 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002236 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002237 throw;
2238 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002239#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002240}
2241
2242template <class _CharT, class _Traits, class _Allocator>
2243template <class _ForwardIterator>
2244typename enable_if
2245<
2246 __is_forward_iterator<_ForwardIterator>::value,
2247 void
2248>::type
2249basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2250{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002251 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002252 if (__sz > max_size())
2253 this->__throw_length_error();
2254 pointer __p;
2255 if (__sz < __min_cap)
2256 {
2257 __set_short_size(__sz);
2258 __p = __get_short_pointer();
2259 }
2260 else
2261 {
2262 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002263 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002264 __set_long_pointer(__p);
2265 __set_long_cap(__cap+1);
2266 __set_long_size(__sz);
2267 }
2268 for (; __first != __last; ++__first, ++__p)
2269 traits_type::assign(*__p, *__first);
2270 traits_type::assign(*__p, value_type());
2271}
2272
2273template <class _CharT, class _Traits, class _Allocator>
2274template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002275inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002276basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2277{
2278 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002279#if _LIBCPP_DEBUG_LEVEL >= 2
2280 __get_db()->__insert_c(this);
2281#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002282}
2283
2284template <class _CharT, class _Traits, class _Allocator>
2285template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002286inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002287basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2288 const allocator_type& __a)
2289 : __r_(__a)
2290{
2291 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002292#if _LIBCPP_DEBUG_LEVEL >= 2
2293 __get_db()->__insert_c(this);
2294#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002295}
2296
Howard Hinnante3e32912011-08-12 21:56:02 +00002297#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2298
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002299template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002300inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002301basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
2302{
2303 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002304#if _LIBCPP_DEBUG_LEVEL >= 2
2305 __get_db()->__insert_c(this);
2306#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002307}
2308
2309template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002310inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002311basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
2312 : __r_(__a)
2313{
2314 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002315#if _LIBCPP_DEBUG_LEVEL >= 2
2316 __get_db()->__insert_c(this);
2317#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002318}
2319
Howard Hinnante3e32912011-08-12 21:56:02 +00002320#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2321
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002322template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002323basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2324{
Howard Hinnant499cea12013-08-23 17:37:05 +00002325#if _LIBCPP_DEBUG_LEVEL >= 2
2326 __get_db()->__erase_c(this);
2327#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002328 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002329 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002330}
2331
2332template <class _CharT, class _Traits, class _Allocator>
2333void
2334basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2335 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002336 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 +00002337{
2338 size_type __ms = max_size();
2339 if (__delta_cap > __ms - __old_cap - 1)
2340 this->__throw_length_error();
2341 pointer __old_p = __get_pointer();
2342 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002343 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002344 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002345 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002346 __invalidate_all_iterators();
2347 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002348 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2349 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002350 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002351 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002352 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2353 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002354 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2355 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002356 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002357 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002358 __set_long_pointer(__p);
2359 __set_long_cap(__cap+1);
2360 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2361 __set_long_size(__old_sz);
2362 traits_type::assign(__p[__old_sz], value_type());
2363}
2364
2365template <class _CharT, class _Traits, class _Allocator>
2366void
2367basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2368 size_type __n_copy, size_type __n_del, size_type __n_add)
2369{
2370 size_type __ms = max_size();
Marshall Clowecc8d7b2013-11-06 14:24:38 +00002371 if (__delta_cap > __ms - __old_cap)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002372 this->__throw_length_error();
2373 pointer __old_p = __get_pointer();
2374 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002375 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002376 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002377 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002378 __invalidate_all_iterators();
2379 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002380 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2381 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002382 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2383 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002384 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2385 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
2386 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002387 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002388 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002389 __set_long_pointer(__p);
2390 __set_long_cap(__cap+1);
2391}
2392
2393// assign
2394
2395template <class _CharT, class _Traits, class _Allocator>
2396basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002397basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002398{
Alp Tokerec34c482014-05-15 11:27:39 +00002399 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002400 size_type __cap = capacity();
2401 if (__cap >= __n)
2402 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002403 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002404 traits_type::move(__p, __s, __n);
2405 traits_type::assign(__p[__n], value_type());
2406 __set_size(__n);
2407 __invalidate_iterators_past(__n);
2408 }
2409 else
2410 {
2411 size_type __sz = size();
2412 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2413 }
2414 return *this;
2415}
2416
2417template <class _CharT, class _Traits, class _Allocator>
2418basic_string<_CharT, _Traits, _Allocator>&
2419basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2420{
2421 size_type __cap = capacity();
2422 if (__cap < __n)
2423 {
2424 size_type __sz = size();
2425 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2426 }
2427 else
2428 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002429 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002430 traits_type::assign(__p, __n, __c);
2431 traits_type::assign(__p[__n], value_type());
2432 __set_size(__n);
2433 return *this;
2434}
2435
2436template <class _CharT, class _Traits, class _Allocator>
2437basic_string<_CharT, _Traits, _Allocator>&
2438basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2439{
2440 pointer __p;
2441 if (__is_long())
2442 {
2443 __p = __get_long_pointer();
2444 __set_long_size(1);
2445 }
2446 else
2447 {
2448 __p = __get_short_pointer();
2449 __set_short_size(1);
2450 }
2451 traits_type::assign(*__p, __c);
2452 traits_type::assign(*++__p, value_type());
2453 __invalidate_iterators_past(1);
2454 return *this;
2455}
2456
2457template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00002458basic_string<_CharT, _Traits, _Allocator>&
2459basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2460{
2461 if (this != &__str)
2462 {
2463 __copy_assign_alloc(__str);
2464 assign(__str);
2465 }
2466 return *this;
2467}
2468
2469#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2470
2471template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002472inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002473void
2474basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
2475{
2476 if (__alloc() != __str.__alloc())
2477 assign(__str);
2478 else
2479 __move_assign(__str, true_type());
2480}
2481
2482template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002483inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002484void
2485basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002486 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002487{
2488 clear();
2489 shrink_to_fit();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00002490 __r_.first() = __str.__r_.first();
2491 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002492 __str.__zero();
2493}
2494
2495template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002496inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002497basic_string<_CharT, _Traits, _Allocator>&
2498basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002499 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
2500 is_nothrow_move_assignable<allocator_type>::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002501{
2502 __move_assign(__str, integral_constant<bool,
2503 __alloc_traits::propagate_on_container_move_assignment::value>());
2504 return *this;
2505}
2506
2507#endif
2508
2509template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002510template<class _InputIterator>
2511typename enable_if
2512<
2513 __is_input_iterator <_InputIterator>::value &&
2514 !__is_forward_iterator<_InputIterator>::value,
2515 basic_string<_CharT, _Traits, _Allocator>&
2516>::type
2517basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2518{
2519 clear();
2520 for (; __first != __last; ++__first)
2521 push_back(*__first);
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002522 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002523}
2524
2525template <class _CharT, class _Traits, class _Allocator>
2526template<class _ForwardIterator>
2527typename enable_if
2528<
2529 __is_forward_iterator<_ForwardIterator>::value,
2530 basic_string<_CharT, _Traits, _Allocator>&
2531>::type
2532basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2533{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002534 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002535 size_type __cap = capacity();
2536 if (__cap < __n)
2537 {
2538 size_type __sz = size();
2539 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2540 }
2541 else
2542 __invalidate_iterators_past(__n);
2543 pointer __p = __get_pointer();
2544 for (; __first != __last; ++__first, ++__p)
2545 traits_type::assign(*__p, *__first);
2546 traits_type::assign(*__p, value_type());
2547 __set_size(__n);
2548 return *this;
2549}
2550
2551template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002552inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002553basic_string<_CharT, _Traits, _Allocator>&
2554basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str)
2555{
2556 return assign(__str.data(), __str.size());
2557}
2558
2559template <class _CharT, class _Traits, class _Allocator>
2560basic_string<_CharT, _Traits, _Allocator>&
2561basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2562{
2563 size_type __sz = __str.size();
2564 if (__pos > __sz)
2565 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002566 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002567}
2568
2569template <class _CharT, class _Traits, class _Allocator>
2570basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002571basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002572{
Alp Tokerec34c482014-05-15 11:27:39 +00002573 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002574 return assign(__s, traits_type::length(__s));
2575}
2576
2577// append
2578
2579template <class _CharT, class _Traits, class _Allocator>
2580basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002581basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002582{
Alp Tokerec34c482014-05-15 11:27:39 +00002583 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002584 size_type __cap = capacity();
2585 size_type __sz = size();
2586 if (__cap - __sz >= __n)
2587 {
2588 if (__n)
2589 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002590 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002591 traits_type::copy(__p + __sz, __s, __n);
2592 __sz += __n;
2593 __set_size(__sz);
2594 traits_type::assign(__p[__sz], value_type());
2595 }
2596 }
2597 else
2598 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2599 return *this;
2600}
2601
2602template <class _CharT, class _Traits, class _Allocator>
2603basic_string<_CharT, _Traits, _Allocator>&
2604basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2605{
2606 if (__n)
2607 {
2608 size_type __cap = capacity();
2609 size_type __sz = size();
2610 if (__cap - __sz < __n)
2611 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2612 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002613 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002614 __sz += __n;
2615 __set_size(__sz);
2616 traits_type::assign(__p[__sz], value_type());
2617 }
2618 return *this;
2619}
2620
2621template <class _CharT, class _Traits, class _Allocator>
2622void
2623basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2624{
Howard Hinnant15467182013-04-30 21:44:48 +00002625 bool __is_short = !__is_long();
2626 size_type __cap;
2627 size_type __sz;
2628 if (__is_short)
2629 {
2630 __cap = __min_cap - 1;
2631 __sz = __get_short_size();
2632 }
2633 else
2634 {
2635 __cap = __get_long_cap() - 1;
2636 __sz = __get_long_size();
2637 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002638 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002639 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002640 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002641 __is_short = !__is_long();
2642 }
2643 pointer __p;
2644 if (__is_short)
2645 {
2646 __p = __get_short_pointer() + __sz;
2647 __set_short_size(__sz+1);
2648 }
2649 else
2650 {
2651 __p = __get_long_pointer() + __sz;
2652 __set_long_size(__sz+1);
2653 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002654 traits_type::assign(*__p, __c);
2655 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002656}
2657
2658template <class _CharT, class _Traits, class _Allocator>
2659template<class _InputIterator>
2660typename enable_if
2661<
2662 __is_input_iterator <_InputIterator>::value &&
2663 !__is_forward_iterator<_InputIterator>::value,
2664 basic_string<_CharT, _Traits, _Allocator>&
2665>::type
2666basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
2667{
2668 for (; __first != __last; ++__first)
2669 push_back(*__first);
2670 return *this;
2671}
2672
2673template <class _CharT, class _Traits, class _Allocator>
2674template<class _ForwardIterator>
2675typename enable_if
2676<
2677 __is_forward_iterator<_ForwardIterator>::value,
2678 basic_string<_CharT, _Traits, _Allocator>&
2679>::type
2680basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
2681{
2682 size_type __sz = size();
2683 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002684 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002685 if (__n)
2686 {
2687 if (__cap - __sz < __n)
2688 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2689 pointer __p = __get_pointer() + __sz;
2690 for (; __first != __last; ++__p, ++__first)
2691 traits_type::assign(*__p, *__first);
2692 traits_type::assign(*__p, value_type());
2693 __set_size(__sz + __n);
2694 }
2695 return *this;
2696}
2697
2698template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002699inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002700basic_string<_CharT, _Traits, _Allocator>&
2701basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2702{
2703 return append(__str.data(), __str.size());
2704}
2705
2706template <class _CharT, class _Traits, class _Allocator>
2707basic_string<_CharT, _Traits, _Allocator>&
2708basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2709{
2710 size_type __sz = __str.size();
2711 if (__pos > __sz)
2712 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002713 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002714}
2715
2716template <class _CharT, class _Traits, class _Allocator>
2717basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002718basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002719{
Alp Tokerec34c482014-05-15 11:27:39 +00002720 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002721 return append(__s, traits_type::length(__s));
2722}
2723
2724// insert
2725
2726template <class _CharT, class _Traits, class _Allocator>
2727basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002728basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002729{
Alp Tokerec34c482014-05-15 11:27:39 +00002730 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002731 size_type __sz = size();
2732 if (__pos > __sz)
2733 this->__throw_out_of_range();
2734 size_type __cap = capacity();
2735 if (__cap - __sz >= __n)
2736 {
2737 if (__n)
2738 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002739 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002740 size_type __n_move = __sz - __pos;
2741 if (__n_move != 0)
2742 {
2743 if (__p + __pos <= __s && __s < __p + __sz)
2744 __s += __n;
2745 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2746 }
2747 traits_type::move(__p + __pos, __s, __n);
2748 __sz += __n;
2749 __set_size(__sz);
2750 traits_type::assign(__p[__sz], value_type());
2751 }
2752 }
2753 else
2754 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2755 return *this;
2756}
2757
2758template <class _CharT, class _Traits, class _Allocator>
2759basic_string<_CharT, _Traits, _Allocator>&
2760basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2761{
2762 size_type __sz = size();
2763 if (__pos > __sz)
2764 this->__throw_out_of_range();
2765 if (__n)
2766 {
2767 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002768 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002769 if (__cap - __sz >= __n)
2770 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002771 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002772 size_type __n_move = __sz - __pos;
2773 if (__n_move != 0)
2774 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2775 }
2776 else
2777 {
2778 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002779 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002780 }
2781 traits_type::assign(__p + __pos, __n, __c);
2782 __sz += __n;
2783 __set_size(__sz);
2784 traits_type::assign(__p[__sz], value_type());
2785 }
2786 return *this;
2787}
2788
2789template <class _CharT, class _Traits, class _Allocator>
2790template<class _InputIterator>
2791typename enable_if
2792<
2793 __is_input_iterator <_InputIterator>::value &&
2794 !__is_forward_iterator<_InputIterator>::value,
2795 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2796>::type
2797basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2798{
Howard Hinnant499cea12013-08-23 17:37:05 +00002799#if _LIBCPP_DEBUG_LEVEL >= 2
2800 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2801 "string::insert(iterator, range) called with an iterator not"
2802 " referring to this string");
2803#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002804 size_type __old_sz = size();
2805 difference_type __ip = __pos - begin();
2806 for (; __first != __last; ++__first)
2807 push_back(*__first);
2808 pointer __p = __get_pointer();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002809 _VSTD::rotate(__p + __ip, __p + __old_sz, __p + size());
Howard Hinnant499cea12013-08-23 17:37:05 +00002810#if _LIBCPP_DEBUG_LEVEL >= 2
2811 return iterator(this, __p + __ip);
2812#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002813 return iterator(__p + __ip);
Howard Hinnant499cea12013-08-23 17:37:05 +00002814#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002815}
2816
2817template <class _CharT, class _Traits, class _Allocator>
2818template<class _ForwardIterator>
2819typename enable_if
2820<
2821 __is_forward_iterator<_ForwardIterator>::value,
2822 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2823>::type
2824basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2825{
Howard Hinnant499cea12013-08-23 17:37:05 +00002826#if _LIBCPP_DEBUG_LEVEL >= 2
2827 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2828 "string::insert(iterator, range) called with an iterator not"
2829 " referring to this string");
2830#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002831 size_type __ip = static_cast<size_type>(__pos - begin());
2832 size_type __sz = size();
2833 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002834 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002835 if (__n)
2836 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002837 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002838 if (__cap - __sz >= __n)
2839 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002840 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002841 size_type __n_move = __sz - __ip;
2842 if (__n_move != 0)
2843 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2844 }
2845 else
2846 {
2847 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002848 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002849 }
2850 __sz += __n;
2851 __set_size(__sz);
2852 traits_type::assign(__p[__sz], value_type());
2853 for (__p += __ip; __first != __last; ++__p, ++__first)
2854 traits_type::assign(*__p, *__first);
2855 }
2856 return begin() + __ip;
2857}
2858
2859template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002860inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002861basic_string<_CharT, _Traits, _Allocator>&
2862basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2863{
2864 return insert(__pos1, __str.data(), __str.size());
2865}
2866
2867template <class _CharT, class _Traits, class _Allocator>
2868basic_string<_CharT, _Traits, _Allocator>&
2869basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2870 size_type __pos2, size_type __n)
2871{
2872 size_type __str_sz = __str.size();
2873 if (__pos2 > __str_sz)
2874 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002875 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002876}
2877
2878template <class _CharT, class _Traits, class _Allocator>
2879basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002880basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002881{
Alp Tokerec34c482014-05-15 11:27:39 +00002882 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002883 return insert(__pos, __s, traits_type::length(__s));
2884}
2885
2886template <class _CharT, class _Traits, class _Allocator>
2887typename basic_string<_CharT, _Traits, _Allocator>::iterator
2888basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2889{
2890 size_type __ip = static_cast<size_type>(__pos - begin());
2891 size_type __sz = size();
2892 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002893 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002894 if (__cap == __sz)
2895 {
2896 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002897 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002898 }
2899 else
2900 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002901 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002902 size_type __n_move = __sz - __ip;
2903 if (__n_move != 0)
2904 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2905 }
2906 traits_type::assign(__p[__ip], __c);
2907 traits_type::assign(__p[++__sz], value_type());
2908 __set_size(__sz);
2909 return begin() + static_cast<difference_type>(__ip);
2910}
2911
2912template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002913inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002914typename basic_string<_CharT, _Traits, _Allocator>::iterator
2915basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2916{
Howard Hinnant499cea12013-08-23 17:37:05 +00002917#if _LIBCPP_DEBUG_LEVEL >= 2
2918 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2919 "string::insert(iterator, n, value) called with an iterator not"
2920 " referring to this string");
2921#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002922 difference_type __p = __pos - begin();
2923 insert(static_cast<size_type>(__p), __n, __c);
2924 return begin() + __p;
2925}
2926
2927// replace
2928
2929template <class _CharT, class _Traits, class _Allocator>
2930basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002931basic_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 +00002932{
Alp Tokerec34c482014-05-15 11:27:39 +00002933 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002934 size_type __sz = size();
2935 if (__pos > __sz)
2936 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002937 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002938 size_type __cap = capacity();
2939 if (__cap - __sz + __n1 >= __n2)
2940 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002941 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002942 if (__n1 != __n2)
2943 {
2944 size_type __n_move = __sz - __pos - __n1;
2945 if (__n_move != 0)
2946 {
2947 if (__n1 > __n2)
2948 {
2949 traits_type::move(__p + __pos, __s, __n2);
2950 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2951 goto __finish;
2952 }
2953 if (__p + __pos < __s && __s < __p + __sz)
2954 {
2955 if (__p + __pos + __n1 <= __s)
2956 __s += __n2 - __n1;
2957 else // __p + __pos < __s < __p + __pos + __n1
2958 {
2959 traits_type::move(__p + __pos, __s, __n1);
2960 __pos += __n1;
2961 __s += __n2;
2962 __n2 -= __n1;
2963 __n1 = 0;
2964 }
2965 }
2966 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2967 }
2968 }
2969 traits_type::move(__p + __pos, __s, __n2);
2970__finish:
2971 __sz += __n2 - __n1;
2972 __set_size(__sz);
2973 __invalidate_iterators_past(__sz);
2974 traits_type::assign(__p[__sz], value_type());
2975 }
2976 else
2977 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2978 return *this;
2979}
2980
2981template <class _CharT, class _Traits, class _Allocator>
2982basic_string<_CharT, _Traits, _Allocator>&
2983basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
2984{
2985 size_type __sz = size();
2986 if (__pos > __sz)
2987 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002988 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002989 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002990 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002991 if (__cap - __sz + __n1 >= __n2)
2992 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002993 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002994 if (__n1 != __n2)
2995 {
2996 size_type __n_move = __sz - __pos - __n1;
2997 if (__n_move != 0)
2998 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2999 }
3000 }
3001 else
3002 {
3003 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003004 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003005 }
3006 traits_type::assign(__p + __pos, __n2, __c);
3007 __sz += __n2 - __n1;
3008 __set_size(__sz);
3009 __invalidate_iterators_past(__sz);
3010 traits_type::assign(__p[__sz], value_type());
3011 return *this;
3012}
3013
3014template <class _CharT, class _Traits, class _Allocator>
3015template<class _InputIterator>
3016typename enable_if
3017<
3018 __is_input_iterator<_InputIterator>::value,
3019 basic_string<_CharT, _Traits, _Allocator>&
3020>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00003021basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003022 _InputIterator __j1, _InputIterator __j2)
3023{
3024 for (; true; ++__i1, ++__j1)
3025 {
3026 if (__i1 == __i2)
3027 {
3028 if (__j1 != __j2)
3029 insert(__i1, __j1, __j2);
3030 break;
3031 }
3032 if (__j1 == __j2)
3033 {
3034 erase(__i1, __i2);
3035 break;
3036 }
Howard Hinnant7b2cb482010-11-17 21:11:40 +00003037 traits_type::assign(const_cast<value_type&>(*__i1), *__j1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003038 }
3039 return *this;
3040}
3041
3042template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003043inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003044basic_string<_CharT, _Traits, _Allocator>&
3045basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
3046{
3047 return replace(__pos1, __n1, __str.data(), __str.size());
3048}
3049
3050template <class _CharT, class _Traits, class _Allocator>
3051basic_string<_CharT, _Traits, _Allocator>&
3052basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
3053 size_type __pos2, size_type __n2)
3054{
3055 size_type __str_sz = __str.size();
3056 if (__pos2 > __str_sz)
3057 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003058 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003059}
3060
3061template <class _CharT, class _Traits, class _Allocator>
3062basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003063basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003064{
Alp Tokerec34c482014-05-15 11:27:39 +00003065 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003066 return replace(__pos, __n1, __s, traits_type::length(__s));
3067}
3068
3069template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003070inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003071basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00003072basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003073{
3074 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
3075 __str.data(), __str.size());
3076}
3077
3078template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003079inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003080basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003081basic_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 +00003082{
3083 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
3084}
3085
3086template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003087inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003088basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003089basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003090{
3091 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
3092}
3093
3094template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003095inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003096basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00003097basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003098{
3099 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
3100}
3101
3102// erase
3103
3104template <class _CharT, class _Traits, class _Allocator>
3105basic_string<_CharT, _Traits, _Allocator>&
3106basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
3107{
3108 size_type __sz = size();
3109 if (__pos > __sz)
3110 this->__throw_out_of_range();
3111 if (__n)
3112 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003113 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00003114 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003115 size_type __n_move = __sz - __pos - __n;
3116 if (__n_move != 0)
3117 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
3118 __sz -= __n;
3119 __set_size(__sz);
3120 __invalidate_iterators_past(__sz);
3121 traits_type::assign(__p[__sz], value_type());
3122 }
3123 return *this;
3124}
3125
3126template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003127inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003128typename basic_string<_CharT, _Traits, _Allocator>::iterator
3129basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
3130{
Howard Hinnant499cea12013-08-23 17:37:05 +00003131#if _LIBCPP_DEBUG_LEVEL >= 2
3132 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
3133 "string::erase(iterator) called with an iterator not"
3134 " referring to this string");
3135#endif
3136 _LIBCPP_ASSERT(__pos != end(),
3137 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003138 iterator __b = begin();
3139 size_type __r = static_cast<size_type>(__pos - __b);
3140 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00003141 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003142}
3143
3144template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003145inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003146typename basic_string<_CharT, _Traits, _Allocator>::iterator
3147basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
3148{
Howard Hinnant499cea12013-08-23 17:37:05 +00003149#if _LIBCPP_DEBUG_LEVEL >= 2
3150 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
3151 "string::erase(iterator, iterator) called with an iterator not"
3152 " referring to this string");
3153#endif
3154 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003155 iterator __b = begin();
3156 size_type __r = static_cast<size_type>(__first - __b);
3157 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00003158 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003159}
3160
3161template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003162inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003163void
3164basic_string<_CharT, _Traits, _Allocator>::pop_back()
3165{
Howard Hinnant499cea12013-08-23 17:37:05 +00003166 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003167 size_type __sz;
3168 if (__is_long())
3169 {
3170 __sz = __get_long_size() - 1;
3171 __set_long_size(__sz);
3172 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3173 }
3174 else
3175 {
3176 __sz = __get_short_size() - 1;
3177 __set_short_size(__sz);
3178 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3179 }
3180 __invalidate_iterators_past(__sz);
3181}
3182
3183template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003184inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003185void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003186basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003187{
3188 __invalidate_all_iterators();
3189 if (__is_long())
3190 {
3191 traits_type::assign(*__get_long_pointer(), value_type());
3192 __set_long_size(0);
3193 }
3194 else
3195 {
3196 traits_type::assign(*__get_short_pointer(), value_type());
3197 __set_short_size(0);
3198 }
3199}
3200
3201template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003202inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003203void
3204basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3205{
3206 if (__is_long())
3207 {
3208 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3209 __set_long_size(__pos);
3210 }
3211 else
3212 {
3213 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3214 __set_short_size(__pos);
3215 }
3216 __invalidate_iterators_past(__pos);
3217}
3218
3219template <class _CharT, class _Traits, class _Allocator>
3220void
3221basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3222{
3223 size_type __sz = size();
3224 if (__n > __sz)
3225 append(__n - __sz, __c);
3226 else
3227 __erase_to_end(__n);
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>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003233basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003234{
Howard Hinnante32b5e22010-11-17 17:55:08 +00003235 size_type __m = __alloc_traits::max_size(__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003236#if _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:08 +00003237 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003238#else
Marshall Clow09f85502013-10-31 17:23:08 +00003239 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003240#endif
3241}
3242
3243template <class _CharT, class _Traits, class _Allocator>
3244void
3245basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
3246{
3247 if (__res_arg > max_size())
3248 this->__throw_length_error();
3249 size_type __cap = capacity();
3250 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003251 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003252 __res_arg = __recommend(__res_arg);
3253 if (__res_arg != __cap)
3254 {
3255 pointer __new_data, __p;
3256 bool __was_long, __now_long;
3257 if (__res_arg == __min_cap - 1)
3258 {
3259 __was_long = true;
3260 __now_long = false;
3261 __new_data = __get_short_pointer();
3262 __p = __get_long_pointer();
3263 }
3264 else
3265 {
3266 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003267 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003268 else
3269 {
3270 #ifndef _LIBCPP_NO_EXCEPTIONS
3271 try
3272 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003273 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00003274 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003275 #ifndef _LIBCPP_NO_EXCEPTIONS
3276 }
3277 catch (...)
3278 {
3279 return;
3280 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003281 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003282 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003283 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00003284 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003285 }
3286 __now_long = true;
3287 __was_long = __is_long();
3288 __p = __get_pointer();
3289 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003290 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
3291 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003292 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003293 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003294 if (__now_long)
3295 {
3296 __set_long_cap(__res_arg+1);
3297 __set_long_size(__sz);
3298 __set_long_pointer(__new_data);
3299 }
3300 else
3301 __set_short_size(__sz);
3302 __invalidate_all_iterators();
3303 }
3304}
3305
3306template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003307inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003308typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3309basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const
3310{
Howard Hinnant499cea12013-08-23 17:37:05 +00003311 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003312 return *(data() + __pos);
3313}
3314
3315template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003316inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003317typename basic_string<_CharT, _Traits, _Allocator>::reference
3318basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos)
3319{
Howard Hinnant499cea12013-08-23 17:37:05 +00003320 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003321 return *(__get_pointer() + __pos);
3322}
3323
3324template <class _CharT, class _Traits, class _Allocator>
3325typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3326basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3327{
3328 if (__n >= size())
3329 this->__throw_out_of_range();
3330 return (*this)[__n];
3331}
3332
3333template <class _CharT, class _Traits, class _Allocator>
3334typename basic_string<_CharT, _Traits, _Allocator>::reference
3335basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3336{
3337 if (__n >= size())
3338 this->__throw_out_of_range();
3339 return (*this)[__n];
3340}
3341
3342template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003343inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003344typename basic_string<_CharT, _Traits, _Allocator>::reference
3345basic_string<_CharT, _Traits, _Allocator>::front()
3346{
Howard Hinnant499cea12013-08-23 17:37:05 +00003347 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003348 return *__get_pointer();
3349}
3350
3351template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003352inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003353typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3354basic_string<_CharT, _Traits, _Allocator>::front() const
3355{
Howard Hinnant499cea12013-08-23 17:37:05 +00003356 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003357 return *data();
3358}
3359
3360template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003361inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003362typename basic_string<_CharT, _Traits, _Allocator>::reference
3363basic_string<_CharT, _Traits, _Allocator>::back()
3364{
Howard Hinnant499cea12013-08-23 17:37:05 +00003365 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003366 return *(__get_pointer() + size() - 1);
3367}
3368
3369template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003370inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003371typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3372basic_string<_CharT, _Traits, _Allocator>::back() const
3373{
Howard Hinnant499cea12013-08-23 17:37:05 +00003374 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003375 return *(data() + size() - 1);
3376}
3377
3378template <class _CharT, class _Traits, class _Allocator>
3379typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003380basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003381{
3382 size_type __sz = size();
3383 if (__pos > __sz)
3384 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003385 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003386 traits_type::copy(__s, data() + __pos, __rlen);
3387 return __rlen;
3388}
3389
3390template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003391inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003392basic_string<_CharT, _Traits, _Allocator>
3393basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3394{
3395 return basic_string(*this, __pos, __n, __alloc());
3396}
3397
3398template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003399inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003400void
3401basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00003402 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3403 __is_nothrow_swappable<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003404{
Howard Hinnant499cea12013-08-23 17:37:05 +00003405#if _LIBCPP_DEBUG_LEVEL >= 2
3406 if (!__is_long())
3407 __get_db()->__invalidate_all(this);
3408 if (!__str.__is_long())
3409 __get_db()->__invalidate_all(&__str);
3410 __get_db()->swap(this, &__str);
3411#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00003412 _VSTD::swap(__r_.first(), __str.__r_.first());
Howard Hinnante32b5e22010-11-17 17:55:08 +00003413 __swap_alloc(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003414}
3415
3416// find
3417
3418template <class _Traits>
3419struct _LIBCPP_HIDDEN __traits_eq
3420{
3421 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003422 _LIBCPP_INLINE_VISIBILITY
3423 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3424 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003425};
3426
3427template<class _CharT, class _Traits, class _Allocator>
3428typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003429basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003430 size_type __pos,
3431 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003432{
Alp Tokerec34c482014-05-15 11:27:39 +00003433 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003434 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003435 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003436}
3437
3438template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003439inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003440typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003441basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3442 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003443{
Marshall Clow37025e12014-06-10 18:51:55 +00003444 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003445 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003446}
3447
3448template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003449inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003450typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003451basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003452 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003453{
Alp Tokerec34c482014-05-15 11:27:39 +00003454 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003455 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003456 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003457}
3458
3459template<class _CharT, class _Traits, class _Allocator>
3460typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003461basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3462 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003463{
Marshall Clow37025e12014-06-10 18:51:55 +00003464 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003465 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003466}
3467
3468// rfind
3469
3470template<class _CharT, class _Traits, class _Allocator>
3471typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003472basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003473 size_type __pos,
3474 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003475{
Alp Tokerec34c482014-05-15 11:27:39 +00003476 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003477 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003478 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003479}
3480
3481template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003482inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003483typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003484basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3485 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003486{
Marshall Clow37025e12014-06-10 18:51:55 +00003487 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003488 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003489}
3490
3491template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003492inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003493typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003494basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003495 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003496{
Alp Tokerec34c482014-05-15 11:27:39 +00003497 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003498 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003499 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003500}
3501
3502template<class _CharT, class _Traits, class _Allocator>
3503typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003504basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3505 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003506{
Marshall Clow37025e12014-06-10 18:51:55 +00003507 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003508 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003509}
3510
3511// find_first_of
3512
3513template<class _CharT, class _Traits, class _Allocator>
3514typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003515basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003516 size_type __pos,
3517 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003518{
Alp Tokerec34c482014-05-15 11:27:39 +00003519 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003520 return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003521 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003522}
3523
3524template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003525inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003526typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003527basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3528 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003529{
Marshall Clow37025e12014-06-10 18:51:55 +00003530 return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003531 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003532}
3533
3534template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003535inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003536typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003537basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003538 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003539{
Alp Tokerec34c482014-05-15 11:27:39 +00003540 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003541 return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003542 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003543}
3544
3545template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003546inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003547typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003548basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3549 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003550{
3551 return find(__c, __pos);
3552}
3553
3554// find_last_of
3555
3556template<class _CharT, class _Traits, class _Allocator>
3557typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003558basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003559 size_type __pos,
3560 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003561{
Alp Tokerec34c482014-05-15 11:27:39 +00003562 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003563 return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003564 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003565}
3566
3567template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003568inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003569typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003570basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3571 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003572{
Marshall Clow37025e12014-06-10 18:51:55 +00003573 return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003574 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003575}
3576
3577template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003578inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003579typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003580basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003581 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003582{
Alp Tokerec34c482014-05-15 11:27:39 +00003583 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003584 return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003585 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003586}
3587
3588template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003589inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003590typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003591basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3592 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003593{
3594 return rfind(__c, __pos);
3595}
3596
3597// find_first_not_of
3598
3599template<class _CharT, class _Traits, class _Allocator>
3600typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003601basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003602 size_type __pos,
3603 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003604{
Alp Tokerec34c482014-05-15 11:27:39 +00003605 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003606 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003607 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003608}
3609
3610template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003611inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003612typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003613basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3614 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003615{
Marshall Clow37025e12014-06-10 18:51:55 +00003616 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003617 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003618}
3619
3620template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003621inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003622typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003623basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003624 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003625{
Alp Tokerec34c482014-05-15 11:27:39 +00003626 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003627 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003628 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003629}
3630
3631template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003632inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003633typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003634basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3635 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003636{
Marshall Clow37025e12014-06-10 18:51:55 +00003637 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003638 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003639}
3640
3641// find_last_not_of
3642
3643template<class _CharT, class _Traits, class _Allocator>
3644typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003645basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003646 size_type __pos,
3647 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003648{
Alp Tokerec34c482014-05-15 11:27:39 +00003649 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003650 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003651 (data(), size(), __s, __pos, __n);
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 +00003656typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003657basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3658 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003659{
Marshall Clow37025e12014-06-10 18:51:55 +00003660 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003661 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003662}
3663
3664template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003665inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003666typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003667basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003668 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003669{
Alp Tokerec34c482014-05-15 11:27:39 +00003670 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003671 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003672 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003673}
3674
3675template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003676inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003677typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003678basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3679 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003680{
Marshall Clow37025e12014-06-10 18:51:55 +00003681 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003682 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003683}
3684
3685// compare
3686
3687template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003688inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003689int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003690basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003691{
Howard Hinnantfa06d752011-07-24 21:45:06 +00003692 size_t __lhs_sz = size();
3693 size_t __rhs_sz = __str.size();
3694 int __result = traits_type::compare(data(), __str.data(),
3695 _VSTD::min(__lhs_sz, __rhs_sz));
3696 if (__result != 0)
3697 return __result;
3698 if (__lhs_sz < __rhs_sz)
3699 return -1;
3700 if (__lhs_sz > __rhs_sz)
3701 return 1;
3702 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003703}
3704
3705template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003706inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003707int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003708basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3709 size_type __n1,
3710 const basic_string& __str) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003711{
3712 return compare(__pos1, __n1, __str.data(), __str.size());
3713}
3714
3715template <class _CharT, class _Traits, class _Allocator>
3716int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003717basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3718 size_type __n1,
3719 const basic_string& __str,
3720 size_type __pos2,
3721 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003722{
3723 size_type __sz = __str.size();
3724 if (__pos2 > __sz)
3725 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003726 return compare(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003727 __sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003728}
3729
3730template <class _CharT, class _Traits, class _Allocator>
3731int
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003732basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003733{
Alp Tokerec34c482014-05-15 11:27:39 +00003734 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003735 return compare(0, npos, __s, traits_type::length(__s));
3736}
3737
3738template <class _CharT, class _Traits, class _Allocator>
3739int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003740basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3741 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003742 const value_type* __s) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003743{
Alp Tokerec34c482014-05-15 11:27:39 +00003744 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003745 return compare(__pos1, __n1, __s, traits_type::length(__s));
3746}
3747
3748template <class _CharT, class _Traits, class _Allocator>
3749int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003750basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3751 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003752 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003753 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003754{
Alp Tokerec34c482014-05-15 11:27:39 +00003755 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003756 size_type __sz = size();
3757 if (__pos1 > __sz || __n2 == npos)
3758 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003759 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3760 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003761 if (__r == 0)
3762 {
3763 if (__rlen < __n2)
3764 __r = -1;
3765 else if (__rlen > __n2)
3766 __r = 1;
3767 }
3768 return __r;
3769}
3770
3771// __invariants
3772
3773template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003774inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003775bool
3776basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3777{
3778 if (size() > capacity())
3779 return false;
3780 if (capacity() < __min_cap - 1)
3781 return false;
3782 if (data() == 0)
3783 return false;
3784 if (data()[size()] != value_type(0))
3785 return false;
3786 return true;
3787}
3788
3789// operator==
3790
3791template<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{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003797 size_t __lhs_sz = __lhs.size();
3798 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3799 __rhs.data(),
3800 __lhs_sz) == 0;
3801}
3802
3803template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003804inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:13 +00003805bool
3806operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3807 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3808{
3809 size_t __lhs_sz = __lhs.size();
3810 if (__lhs_sz != __rhs.size())
3811 return false;
3812 const char* __lp = __lhs.data();
3813 const char* __rp = __rhs.data();
3814 if (__lhs.__is_long())
3815 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3816 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3817 if (*__lp != *__rp)
3818 return false;
3819 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003820}
3821
3822template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003823inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003824bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003825operator==(const _CharT* __lhs,
3826 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003827{
3828 return __rhs.compare(__lhs) == 0;
3829}
3830
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003831template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003832inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003833bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003834operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3835 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003836{
3837 return __lhs.compare(__rhs) == 0;
3838}
3839
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003840// operator!=
3841
Howard Hinnant324bb032010-08-22 00:02:43 +00003842template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003843inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003844bool
3845operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003846 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003847{
3848 return !(__lhs == __rhs);
3849}
3850
3851template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003852inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003853bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003854operator!=(const _CharT* __lhs,
3855 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003856{
3857 return !(__lhs == __rhs);
3858}
3859
3860template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003861inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003862bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003863operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3864 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003865{
3866 return !(__lhs == __rhs);
3867}
3868
3869// operator<
3870
3871template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003872inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003873bool
3874operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003875 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003876{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003877 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003878}
3879
3880template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003881inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003882bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003883operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3884 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003885{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003886 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003887}
3888
3889template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003890inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003891bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003892operator< (const _CharT* __lhs,
3893 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003894{
3895 return __rhs.compare(__lhs) > 0;
3896}
3897
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003898// operator>
3899
3900template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003901inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003902bool
3903operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003904 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003905{
3906 return __rhs < __lhs;
3907}
3908
3909template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003910inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003911bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003912operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3913 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003914{
3915 return __rhs < __lhs;
3916}
3917
3918template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003919inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003920bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003921operator> (const _CharT* __lhs,
3922 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003923{
3924 return __rhs < __lhs;
3925}
3926
3927// operator<=
3928
3929template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003930inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003931bool
3932operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003933 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003934{
3935 return !(__rhs < __lhs);
3936}
3937
3938template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003939inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003940bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003941operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3942 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003943{
3944 return !(__rhs < __lhs);
3945}
3946
3947template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003948inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003949bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003950operator<=(const _CharT* __lhs,
3951 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003952{
3953 return !(__rhs < __lhs);
3954}
3955
3956// operator>=
3957
3958template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003959inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003960bool
3961operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003962 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003963{
3964 return !(__lhs < __rhs);
3965}
3966
3967template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003968inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003969bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003970operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3971 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003972{
3973 return !(__lhs < __rhs);
3974}
3975
3976template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003977inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003978bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003979operator>=(const _CharT* __lhs,
3980 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003981{
3982 return !(__lhs < __rhs);
3983}
3984
3985// operator +
3986
3987template<class _CharT, class _Traits, class _Allocator>
3988basic_string<_CharT, _Traits, _Allocator>
3989operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3990 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3991{
3992 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3993 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3994 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3995 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3996 __r.append(__rhs.data(), __rhs_sz);
3997 return __r;
3998}
3999
4000template<class _CharT, class _Traits, class _Allocator>
4001basic_string<_CharT, _Traits, _Allocator>
4002operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4003{
4004 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4005 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
4006 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4007 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
4008 __r.append(__rhs.data(), __rhs_sz);
4009 return __r;
4010}
4011
4012template<class _CharT, class _Traits, class _Allocator>
4013basic_string<_CharT, _Traits, _Allocator>
4014operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4015{
4016 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4017 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4018 __r.__init(&__lhs, 1, 1 + __rhs_sz);
4019 __r.append(__rhs.data(), __rhs_sz);
4020 return __r;
4021}
4022
4023template<class _CharT, class _Traits, class _Allocator>
4024basic_string<_CharT, _Traits, _Allocator>
4025operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
4026{
4027 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4028 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4029 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
4030 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4031 __r.append(__rhs, __rhs_sz);
4032 return __r;
4033}
4034
4035template<class _CharT, class _Traits, class _Allocator>
4036basic_string<_CharT, _Traits, _Allocator>
4037operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
4038{
4039 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4040 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4041 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
4042 __r.push_back(__rhs);
4043 return __r;
4044}
4045
Howard Hinnant73d21a42010-09-04 23:28:19 +00004046#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004047
4048template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004049inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004050basic_string<_CharT, _Traits, _Allocator>
4051operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4052{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004053 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004054}
4055
4056template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004057inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004058basic_string<_CharT, _Traits, _Allocator>
4059operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4060{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004061 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004062}
4063
4064template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004065inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004066basic_string<_CharT, _Traits, _Allocator>
4067operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4068{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004069 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004070}
4071
4072template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004073inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004074basic_string<_CharT, _Traits, _Allocator>
4075operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4076{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004077 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004078}
4079
4080template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004081inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004082basic_string<_CharT, _Traits, _Allocator>
4083operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4084{
4085 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004086 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004087}
4088
4089template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004090inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004091basic_string<_CharT, _Traits, _Allocator>
4092operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
4093{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004094 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004095}
4096
4097template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004098inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004099basic_string<_CharT, _Traits, _Allocator>
4100operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
4101{
4102 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004103 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004104}
4105
Howard Hinnant73d21a42010-09-04 23:28:19 +00004106#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004107
4108// swap
4109
4110template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004111inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004112void
Howard Hinnanta6119a82011-05-29 19:57:12 +00004113swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00004114 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4115 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004116{
4117 __lhs.swap(__rhs);
4118}
4119
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004120#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
4121
4122typedef basic_string<char16_t> u16string;
4123typedef basic_string<char32_t> u32string;
4124
Howard Hinnant324bb032010-08-22 00:02:43 +00004125#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004126
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004127_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4128_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4129_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4130_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4131_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004132
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004133_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
4134_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
4135_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004136
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004137_LIBCPP_FUNC_VIS string to_string(int __val);
4138_LIBCPP_FUNC_VIS string to_string(unsigned __val);
4139_LIBCPP_FUNC_VIS string to_string(long __val);
4140_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4141_LIBCPP_FUNC_VIS string to_string(long long __val);
4142_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4143_LIBCPP_FUNC_VIS string to_string(float __val);
4144_LIBCPP_FUNC_VIS string to_string(double __val);
4145_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004146
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004147_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4148_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4149_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4150_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4151_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004152
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004153_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
4154_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
4155_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004156
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004157_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4158_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4159_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4160_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4161_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4162_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4163_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4164_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4165_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004166
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004167template<class _CharT, class _Traits, class _Allocator>
4168 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4169 basic_string<_CharT, _Traits, _Allocator>::npos;
4170
4171template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004172struct _LIBCPP_TYPE_VIS_ONLY hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004173 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
4174{
4175 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00004176 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004177};
4178
4179template<class _CharT, class _Traits, class _Allocator>
4180size_t
4181hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00004182 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004183{
Sean Huntaffd9e52011-07-29 23:31:56 +00004184 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004185}
4186
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004187template<class _CharT, class _Traits, class _Allocator>
4188basic_ostream<_CharT, _Traits>&
4189operator<<(basic_ostream<_CharT, _Traits>& __os,
4190 const basic_string<_CharT, _Traits, _Allocator>& __str);
4191
4192template<class _CharT, class _Traits, class _Allocator>
4193basic_istream<_CharT, _Traits>&
4194operator>>(basic_istream<_CharT, _Traits>& __is,
4195 basic_string<_CharT, _Traits, _Allocator>& __str);
4196
4197template<class _CharT, class _Traits, class _Allocator>
4198basic_istream<_CharT, _Traits>&
4199getline(basic_istream<_CharT, _Traits>& __is,
4200 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4201
4202template<class _CharT, class _Traits, class _Allocator>
4203inline _LIBCPP_INLINE_VISIBILITY
4204basic_istream<_CharT, _Traits>&
4205getline(basic_istream<_CharT, _Traits>& __is,
4206 basic_string<_CharT, _Traits, _Allocator>& __str);
4207
4208#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4209
4210template<class _CharT, class _Traits, class _Allocator>
4211inline _LIBCPP_INLINE_VISIBILITY
4212basic_istream<_CharT, _Traits>&
4213getline(basic_istream<_CharT, _Traits>&& __is,
4214 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4215
4216template<class _CharT, class _Traits, class _Allocator>
4217inline _LIBCPP_INLINE_VISIBILITY
4218basic_istream<_CharT, _Traits>&
4219getline(basic_istream<_CharT, _Traits>&& __is,
4220 basic_string<_CharT, _Traits, _Allocator>& __str);
4221
4222#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4223
Howard Hinnant499cea12013-08-23 17:37:05 +00004224#if _LIBCPP_DEBUG_LEVEL >= 2
4225
4226template<class _CharT, class _Traits, class _Allocator>
4227bool
4228basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4229{
4230 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
4231 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
4232}
4233
4234template<class _CharT, class _Traits, class _Allocator>
4235bool
4236basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4237{
4238 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
4239 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
4240}
4241
4242template<class _CharT, class _Traits, class _Allocator>
4243bool
4244basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4245{
4246 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4247 return this->data() <= __p && __p <= this->data() + this->size();
4248}
4249
4250template<class _CharT, class _Traits, class _Allocator>
4251bool
4252basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4253{
4254 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4255 return this->data() <= __p && __p < this->data() + this->size();
4256}
4257
4258#endif // _LIBCPP_DEBUG_LEVEL >= 2
4259
Marshall Clow15234322013-07-23 17:05:24 +00004260#if _LIBCPP_STD_VER > 11
4261// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:32 +00004262inline namespace literals
Marshall Clow15234322013-07-23 17:05:24 +00004263{
4264 inline namespace string_literals
4265 {
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004266 inline _LIBCPP_INLINE_VISIBILITY
4267 basic_string<char> operator "" s( const char *__str, size_t __len )
4268 {
4269 return basic_string<char> (__str, __len);
4270 }
Marshall Clow15234322013-07-23 17:05:24 +00004271
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004272 inline _LIBCPP_INLINE_VISIBILITY
4273 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4274 {
4275 return basic_string<wchar_t> (__str, __len);
4276 }
Marshall Clow15234322013-07-23 17:05:24 +00004277
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004278 inline _LIBCPP_INLINE_VISIBILITY
4279 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4280 {
4281 return basic_string<char16_t> (__str, __len);
4282 }
Marshall Clow15234322013-07-23 17:05:24 +00004283
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004284 inline _LIBCPP_INLINE_VISIBILITY
4285 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4286 {
4287 return basic_string<char32_t> (__str, __len);
4288 }
Marshall Clow15234322013-07-23 17:05:24 +00004289 }
4290}
4291#endif
4292
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004293_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<char>)
4294_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<wchar_t>)
Howard Hinnant499cea12013-08-23 17:37:05 +00004295_LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004296
4297_LIBCPP_END_NAMESPACE_STD
4298
4299#endif // _LIBCPP_STRING