blob: a4537793b4ded9bc56044acad241c57b0eb222a0 [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(
Marshall Clowaf961ed2015-08-18 18:57:00 +0000118 allocator_type::propagate_on_container_move_assignment::value ||
119 allocator_type::is_always_equal::value ); // C++17
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)
Marshall Clow7d914d12015-07-13 20:04:56 +0000223 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
224 allocator_traits<allocator_type>::is_always_equal::value); // C++17
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;
Marshall Clowf532a702016-03-08 15:44:30 +0000228 value_type* data() noexcept; // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000229
Howard Hinnanta6119a82011-05-29 19:57:12 +0000230 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000231
Howard Hinnanta6119a82011-05-29 19:57:12 +0000232 size_type find(const basic_string& str, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000233 size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
234 size_type find(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000235 size_type find(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000236
Howard Hinnanta6119a82011-05-29 19:57:12 +0000237 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000238 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
239 size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000240 size_type rfind(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000241
Howard Hinnanta6119a82011-05-29 19:57:12 +0000242 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000243 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
244 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000245 size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000246
Howard Hinnanta6119a82011-05-29 19:57:12 +0000247 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000248 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
249 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000250 size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000251
Howard Hinnanta6119a82011-05-29 19:57:12 +0000252 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000253 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
254 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000255 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000256
Howard Hinnanta6119a82011-05-29 19:57:12 +0000257 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000258 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
259 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000260 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000261
Howard Hinnanta6119a82011-05-29 19:57:12 +0000262 int compare(const basic_string& str) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000263 int compare(size_type pos1, size_type n1, const basic_string& str) const;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000264 int compare(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000265 size_type pos2, size_type n2=npos) const; // C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000266 int compare(const value_type* s) const noexcept;
267 int compare(size_type pos1, size_type n1, const value_type* s) const;
268 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000269
270 bool __invariants() const;
271};
272
273template<class charT, class traits, class Allocator>
274basic_string<charT, traits, Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000275operator+(const basic_string<charT, traits, Allocator>& lhs,
276 const basic_string<charT, traits, Allocator>& rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000277
278template<class charT, class traits, class Allocator>
279basic_string<charT, traits, Allocator>
280operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
281
282template<class charT, class traits, class Allocator>
283basic_string<charT, traits, Allocator>
284operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
285
286template<class charT, class traits, class Allocator>
287basic_string<charT, traits, Allocator>
288operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
289
290template<class charT, class traits, class Allocator>
291basic_string<charT, traits, Allocator>
292operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
293
294template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000295bool operator==(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000296 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000297
298template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000299bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000300
301template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000302bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000303
Howard Hinnant324bb032010-08-22 00:02:43 +0000304template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000305bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000306 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000307
308template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000309bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000310
311template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000312bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000313
314template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000315bool operator< (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000316 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000317
318template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000319bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000320
321template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000322bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000323
324template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000325bool operator> (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000326 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000327
328template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000329bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000330
331template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000332bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000333
334template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000335bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000336 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000337
338template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000339bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000340
341template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000342bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000343
344template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000345bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000346 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000347
348template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000349bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000350
351template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000352bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000353
354template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000355void swap(basic_string<charT, traits, Allocator>& lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000356 basic_string<charT, traits, Allocator>& rhs)
357 noexcept(noexcept(lhs.swap(rhs)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000358
359template<class charT, class traits, class Allocator>
360basic_istream<charT, traits>&
361operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
362
363template<class charT, class traits, class Allocator>
364basic_ostream<charT, traits>&
365operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
366
367template<class charT, class traits, class Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +0000368basic_istream<charT, traits>&
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000369getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
370 charT delim);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000371
372template<class charT, class traits, class Allocator>
373basic_istream<charT, traits>&
374getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
375
376typedef basic_string<char> string;
377typedef basic_string<wchar_t> wstring;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000378typedef basic_string<char16_t> u16string;
379typedef basic_string<char32_t> u32string;
380
381int stoi (const string& str, size_t* idx = 0, int base = 10);
382long stol (const string& str, size_t* idx = 0, int base = 10);
383unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
384long long stoll (const string& str, size_t* idx = 0, int base = 10);
385unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
386
387float stof (const string& str, size_t* idx = 0);
388double stod (const string& str, size_t* idx = 0);
389long double stold(const string& str, size_t* idx = 0);
390
391string to_string(int val);
392string to_string(unsigned val);
393string to_string(long val);
394string to_string(unsigned long val);
395string to_string(long long val);
396string to_string(unsigned long long val);
397string to_string(float val);
398string to_string(double val);
399string to_string(long double val);
400
401int stoi (const wstring& str, size_t* idx = 0, int base = 10);
402long stol (const wstring& str, size_t* idx = 0, int base = 10);
403unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
404long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
405unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
406
407float stof (const wstring& str, size_t* idx = 0);
408double stod (const wstring& str, size_t* idx = 0);
409long double stold(const wstring& str, size_t* idx = 0);
410
411wstring to_wstring(int val);
412wstring to_wstring(unsigned val);
413wstring to_wstring(long val);
414wstring to_wstring(unsigned long val);
415wstring to_wstring(long long val);
416wstring to_wstring(unsigned long long val);
417wstring to_wstring(float val);
418wstring to_wstring(double val);
419wstring to_wstring(long double val);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000420
421template <> struct hash<string>;
422template <> struct hash<u16string>;
423template <> struct hash<u32string>;
424template <> struct hash<wstring>;
425
Marshall Clow15234322013-07-23 17:05:24 +0000426basic_string<char> operator "" s( const char *str, size_t len ); // C++14
427basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
428basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
429basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
430
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000431} // std
432
433*/
434
435#include <__config>
436#include <iosfwd>
437#include <cstring>
Howard Hinnantadff4892010-05-24 17:49:41 +0000438#include <cstdio> // For EOF.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000439#include <cwchar>
440#include <algorithm>
441#include <iterator>
442#include <utility>
443#include <memory>
444#include <stdexcept>
445#include <type_traits>
446#include <initializer_list>
447#include <__functional_base>
448#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
449#include <cstdint>
450#endif
Howard Hinnant499cea12013-08-23 17:37:05 +0000451#if defined(_LIBCPP_NO_EXCEPTIONS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000452#include <cassert>
453#endif
454
Howard Hinnant66c6f972011-11-29 16:45:27 +0000455#include <__undef_min_max>
456
Eric Fiselierb9536102014-08-10 23:53:08 +0000457#include <__debug>
458
Howard Hinnant08e17472011-10-17 20:05:10 +0000459#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000460#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000461#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000462
463_LIBCPP_BEGIN_NAMESPACE_STD
464
465// fpos
466
467template <class _StateT>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000468class _LIBCPP_TYPE_VIS_ONLY fpos
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000469{
470private:
471 _StateT __st_;
472 streamoff __off_;
473public:
474 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
475
476 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
477
478 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
479 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
480
481 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
482 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
483 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
484 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
485};
486
487template <class _StateT>
488inline _LIBCPP_INLINE_VISIBILITY
489streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
490 {return streamoff(__x) - streamoff(__y);}
491
492template <class _StateT>
493inline _LIBCPP_INLINE_VISIBILITY
494bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
495 {return streamoff(__x) == streamoff(__y);}
496
497template <class _StateT>
498inline _LIBCPP_INLINE_VISIBILITY
499bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
500 {return streamoff(__x) != streamoff(__y);}
501
502// char_traits
503
504template <class _CharT>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000505struct _LIBCPP_TYPE_VIS_ONLY char_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000506{
507 typedef _CharT char_type;
508 typedef int int_type;
509 typedef streamoff off_type;
510 typedef streampos pos_type;
511 typedef mbstate_t state_type;
512
Dan Albert6d9505a2014-09-17 16:34:29 +0000513 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000514 {__c1 = __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000515 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000516 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000517 static inline _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);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000521 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000522 static size_t length(const char_type* __s);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000523 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000524 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
525 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000526 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000527 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000528 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000529 static char_type* assign(char_type* __s, size_t __n, char_type __a);
530
Dan Albert6d9505a2014-09-17 16:34:29 +0000531 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000532 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000533 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000534 {return char_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000535 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000536 {return int_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000537 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000538 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000539 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000540 {return int_type(EOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000541};
542
543template <class _CharT>
544int
545char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
546{
547 for (; __n; --__n, ++__s1, ++__s2)
548 {
549 if (lt(*__s1, *__s2))
550 return -1;
551 if (lt(*__s2, *__s1))
552 return 1;
553 }
554 return 0;
555}
556
557template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000558inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000559size_t
560char_traits<_CharT>::length(const char_type* __s)
561{
562 size_t __len = 0;
563 for (; !eq(*__s, char_type(0)); ++__s)
564 ++__len;
565 return __len;
566}
567
568template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000569inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000570const _CharT*
571char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a)
572{
573 for (; __n; --__n)
574 {
575 if (eq(*__s, __a))
576 return __s;
577 ++__s;
578 }
579 return 0;
580}
581
582template <class _CharT>
583_CharT*
584char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n)
585{
586 char_type* __r = __s1;
587 if (__s1 < __s2)
588 {
589 for (; __n; --__n, ++__s1, ++__s2)
590 assign(*__s1, *__s2);
591 }
592 else if (__s2 < __s1)
593 {
594 __s1 += __n;
595 __s2 += __n;
596 for (; __n; --__n)
597 assign(*--__s1, *--__s2);
598 }
599 return __r;
600}
601
602template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000603inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000604_CharT*
605char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
606{
Howard Hinnant499cea12013-08-23 17:37:05 +0000607 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000608 char_type* __r = __s1;
609 for (; __n; --__n, ++__s1, ++__s2)
610 assign(*__s1, *__s2);
611 return __r;
612}
613
614template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000615inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000616_CharT*
617char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
618{
619 char_type* __r = __s;
620 for (; __n; --__n, ++__s)
621 assign(*__s, __a);
622 return __r;
623}
624
625// char_traits<char>
626
627template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000628struct _LIBCPP_TYPE_VIS_ONLY char_traits<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000629{
630 typedef char char_type;
631 typedef int int_type;
632 typedef streamoff off_type;
633 typedef streampos pos_type;
634 typedef mbstate_t state_type;
635
Dan Albert6d9505a2014-09-17 16:34:29 +0000636 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000637 {__c1 = __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000638 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000639 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000640 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000641 {return (unsigned char)__c1 < (unsigned char)__c2;}
642
Dan Albert6d9505a2014-09-17 16:34:29 +0000643 static inline int compare(const char_type* __s1, const char_type* __s2, size_t __n)
Marshall Clowf2e36ef2015-02-12 23:34:52 +0000644 {return __n == 0 ? 0 : memcmp(__s1, __s2, __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000645 static inline size_t length(const char_type* __s) {return strlen(__s);}
646 static inline const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000647 {return __n == 0 ? NULL : (const char_type*) memchr(__s, to_int_type(__a), __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000648 static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000649 {return __n == 0 ? __s1 : (char_type*) memmove(__s1, __s2, __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000650 static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnant499cea12013-08-23 17:37:05 +0000651 {
652 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Marshall Clow6bcbced2015-02-13 16:04:42 +0000653 return __n == 0 ? __s1 : (char_type*)memcpy(__s1, __s2, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +0000654 }
Dan Albert6d9505a2014-09-17 16:34:29 +0000655 static inline char_type* assign(char_type* __s, size_t __n, char_type __a)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000656 {return __n == 0 ? __s : (char_type*)memset(__s, to_int_type(__a), __n);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000657
Dan Albert6d9505a2014-09-17 16:34:29 +0000658 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000659 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000660 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000661 {return char_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000662 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000663 {return int_type((unsigned char)__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000664 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000665 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000666 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000667 {return int_type(EOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000668};
669
670// char_traits<wchar_t>
671
672template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000673struct _LIBCPP_TYPE_VIS_ONLY char_traits<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000674{
675 typedef wchar_t char_type;
676 typedef wint_t int_type;
677 typedef streamoff off_type;
678 typedef streampos pos_type;
679 typedef mbstate_t state_type;
680
Dan Albert6d9505a2014-09-17 16:34:29 +0000681 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000682 {__c1 = __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000683 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000684 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000685 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000686 {return __c1 < __c2;}
687
Dan Albert6d9505a2014-09-17 16:34:29 +0000688 static inline int compare(const char_type* __s1, const char_type* __s2, size_t __n)
Marshall Clowf2e36ef2015-02-12 23:34:52 +0000689 {return __n == 0 ? 0 : wmemcmp(__s1, __s2, __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000690 static inline size_t length(const char_type* __s)
Howard Hinnanta6119a82011-05-29 19:57:12 +0000691 {return wcslen(__s);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000692 static inline const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000693 {return __n == 0 ? NULL : (const char_type*)wmemchr(__s, __a, __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000694 static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000695 {return __n == 0 ? __s1 : (char_type*)wmemmove(__s1, __s2, __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000696 static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnant499cea12013-08-23 17:37:05 +0000697 {
698 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Marshall Clow6bcbced2015-02-13 16:04:42 +0000699 return __n == 0 ? __s1 : (char_type*)wmemcpy(__s1, __s2, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +0000700 }
Dan Albert6d9505a2014-09-17 16:34:29 +0000701 static inline char_type* assign(char_type* __s, size_t __n, char_type __a)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000702 {return __n == 0 ? __s : (char_type*)wmemset(__s, __a, __n);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000703
Dan Albert6d9505a2014-09-17 16:34:29 +0000704 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000705 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000706 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000707 {return char_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000708 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000709 {return int_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000710 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000711 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000712 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000713 {return int_type(WEOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000714};
715
716#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
717
718template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000719struct _LIBCPP_TYPE_VIS_ONLY char_traits<char16_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000720{
721 typedef char16_t char_type;
722 typedef uint_least16_t int_type;
723 typedef streamoff off_type;
724 typedef u16streampos pos_type;
725 typedef mbstate_t state_type;
726
Dan Albert6d9505a2014-09-17 16:34:29 +0000727 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000728 {__c1 = __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000729 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000730 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000731 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000732 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000733
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000734 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000735 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000737 static size_t length(const char_type* __s);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000738 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000739 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000740 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000741 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000742 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000743 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000744 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000745 static char_type* assign(char_type* __s, size_t __n, char_type __a);
746
Dan Albert6d9505a2014-09-17 16:34:29 +0000747 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000748 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000749 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000750 {return char_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000751 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000752 {return int_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000753 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000754 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000755 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Marshall Clow9a3c6892015-08-04 01:38:34 +0000756 {return int_type(0xFFFF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000757};
758
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000759inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000760int
761char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
762{
763 for (; __n; --__n, ++__s1, ++__s2)
764 {
765 if (lt(*__s1, *__s2))
766 return -1;
767 if (lt(*__s2, *__s1))
768 return 1;
769 }
770 return 0;
771}
772
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000773inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000774size_t
775char_traits<char16_t>::length(const char_type* __s)
776{
777 size_t __len = 0;
778 for (; !eq(*__s, char_type(0)); ++__s)
779 ++__len;
780 return __len;
781}
782
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000783inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000784const char16_t*
785char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a)
786{
787 for (; __n; --__n)
788 {
789 if (eq(*__s, __a))
790 return __s;
791 ++__s;
792 }
793 return 0;
794}
795
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000796inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000797char16_t*
798char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
799{
800 char_type* __r = __s1;
801 if (__s1 < __s2)
802 {
803 for (; __n; --__n, ++__s1, ++__s2)
804 assign(*__s1, *__s2);
805 }
806 else if (__s2 < __s1)
807 {
808 __s1 += __n;
809 __s2 += __n;
810 for (; __n; --__n)
811 assign(*--__s1, *--__s2);
812 }
813 return __r;
814}
815
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000816inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000817char16_t*
818char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
819{
Howard Hinnant499cea12013-08-23 17:37:05 +0000820 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000821 char_type* __r = __s1;
822 for (; __n; --__n, ++__s1, ++__s2)
823 assign(*__s1, *__s2);
824 return __r;
825}
826
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000827inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000828char16_t*
829char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a)
830{
831 char_type* __r = __s;
832 for (; __n; --__n, ++__s)
833 assign(*__s, __a);
834 return __r;
835}
836
837template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000838struct _LIBCPP_TYPE_VIS_ONLY char_traits<char32_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000839{
840 typedef char32_t char_type;
841 typedef uint_least32_t int_type;
842 typedef streamoff off_type;
843 typedef u32streampos pos_type;
844 typedef mbstate_t state_type;
845
Dan Albert6d9505a2014-09-17 16:34:29 +0000846 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000847 {__c1 = __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000848 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000849 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000850 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000851 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000852
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000854 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000855 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000856 static size_t length(const char_type* __s);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000857 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000858 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000859 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000860 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000861 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000862 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000863 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000864 static char_type* assign(char_type* __s, size_t __n, char_type __a);
865
Dan Albert6d9505a2014-09-17 16:34:29 +0000866 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000867 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000868 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000869 {return char_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000870 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000871 {return int_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000872 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000873 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000874 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000875 {return int_type(0xFFFFFFFF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000876};
877
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000878inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000879int
880char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
881{
882 for (; __n; --__n, ++__s1, ++__s2)
883 {
884 if (lt(*__s1, *__s2))
885 return -1;
886 if (lt(*__s2, *__s1))
887 return 1;
888 }
889 return 0;
890}
891
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000892inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000893size_t
894char_traits<char32_t>::length(const char_type* __s)
895{
896 size_t __len = 0;
897 for (; !eq(*__s, char_type(0)); ++__s)
898 ++__len;
899 return __len;
900}
901
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000902inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000903const char32_t*
904char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a)
905{
906 for (; __n; --__n)
907 {
908 if (eq(*__s, __a))
909 return __s;
910 ++__s;
911 }
912 return 0;
913}
914
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000915inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000916char32_t*
917char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
918{
919 char_type* __r = __s1;
920 if (__s1 < __s2)
921 {
922 for (; __n; --__n, ++__s1, ++__s2)
923 assign(*__s1, *__s2);
924 }
925 else if (__s2 < __s1)
926 {
927 __s1 += __n;
928 __s2 += __n;
929 for (; __n; --__n)
930 assign(*--__s1, *--__s2);
931 }
932 return __r;
933}
934
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000935inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000936char32_t*
937char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
938{
Howard Hinnant499cea12013-08-23 17:37:05 +0000939 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000940 char_type* __r = __s1;
941 for (; __n; --__n, ++__s1, ++__s2)
942 assign(*__s1, *__s2);
943 return __r;
944}
945
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000946inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000947char32_t*
948char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a)
949{
950 char_type* __r = __s;
951 for (; __n; --__n, ++__s)
952 assign(*__s, __a);
953 return __r;
954}
955
Howard Hinnant324bb032010-08-22 00:02:43 +0000956#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000957
Marshall Clowb671fc92013-12-09 16:00:28 +0000958// helper fns for basic_string
959
Marshall Clow37025e12014-06-10 18:51:55 +0000960// __str_find
Marshall Clowb671fc92013-12-09 16:00:28 +0000961template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Marshall Clow360f3192014-06-02 02:22:49 +0000962_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +0000963__str_find(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +0000964 _CharT __c, _SizeT __pos) _NOEXCEPT
965{
966 if (__pos >= __sz)
967 return __npos;
968 const _CharT* __r = _Traits::find(__p + __pos, __sz - __pos, __c);
969 if (__r == 0)
970 return __npos;
971 return static_cast<_SizeT>(__r - __p);
972}
973
974template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
975_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +0000976__str_find(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +0000977 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
978{
979 if (__pos > __sz || __sz - __pos < __n)
980 return __npos;
981 if (__n == 0)
982 return __pos;
Marshall Clow360f3192014-06-02 02:22:49 +0000983 const _CharT* __r =
Marshall Clow37025e12014-06-10 18:51:55 +0000984 _VSTD::__search(__p + __pos, __p + __sz,
985 __s, __s + __n, _Traits::eq,
Marshall Clowf6d6b512016-03-08 15:12:52 +0000986 random_access_iterator_tag(), random_access_iterator_tag()).first;
Marshall Clow360f3192014-06-02 02:22:49 +0000987 if (__r == __p + __sz)
988 return __npos;
989 return static_cast<_SizeT>(__r - __p);
990}
991
992
Marshall Clow37025e12014-06-10 18:51:55 +0000993// __str_rfind
Marshall Clow360f3192014-06-02 02:22:49 +0000994
995template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
996_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +0000997__str_rfind(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +0000998 _CharT __c, _SizeT __pos) _NOEXCEPT
999{
1000 if (__sz < 1)
Marshall Clowd5549cc2014-07-17 15:32:20 +00001001 return __npos;
1002 if (__pos < __sz)
1003 ++__pos;
1004 else
1005 __pos = __sz;
1006 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1007 {
1008 if (_Traits::eq(*--__ps, __c))
1009 return static_cast<_SizeT>(__ps - __p);
1010 }
Marshall Clow360f3192014-06-02 02:22:49 +00001011 return __npos;
1012}
1013
1014template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1015_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001016__str_rfind(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001017 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1018{
1019 __pos = _VSTD::min(__pos, __sz);
1020 if (__n < __sz - __pos)
1021 __pos += __n;
1022 else
1023 __pos = __sz;
Marshall Clow37025e12014-06-10 18:51:55 +00001024 const _CharT* __r = _VSTD::__find_end(
1025 __p, __p + __pos, __s, __s + __n, _Traits::eq,
1026 random_access_iterator_tag(), random_access_iterator_tag());
Marshall Clow360f3192014-06-02 02:22:49 +00001027 if (__n > 0 && __r == __p + __pos)
1028 return __npos;
1029 return static_cast<_SizeT>(__r - __p);
1030}
1031
Marshall Clow37025e12014-06-10 18:51:55 +00001032// __str_find_first_of
Marshall Clow360f3192014-06-02 02:22:49 +00001033template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1034_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001035__str_find_first_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001036 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001037{
1038 if (__pos >= __sz || __n == 0)
1039 return __npos;
Marshall Clow37025e12014-06-10 18:51:55 +00001040 const _CharT* __r = _VSTD::__find_first_of_ce
Marshall Clowb671fc92013-12-09 16:00:28 +00001041 (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq );
1042 if (__r == __p + __sz)
1043 return __npos;
1044 return static_cast<_SizeT>(__r - __p);
1045}
1046
Marshall Clow360f3192014-06-02 02:22:49 +00001047
Marshall Clow37025e12014-06-10 18:51:55 +00001048// __str_find_last_of
Marshall Clowb671fc92013-12-09 16:00:28 +00001049template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Marshall Clow360f3192014-06-02 02:22:49 +00001050_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001051__str_find_last_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001052 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001053 {
1054 if (__n != 0)
1055 {
1056 if (__pos < __sz)
1057 ++__pos;
1058 else
1059 __pos = __sz;
1060 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1061 {
1062 const _CharT* __r = _Traits::find(__s, __n, *--__ps);
1063 if (__r)
1064 return static_cast<_SizeT>(__ps - __p);
1065 }
1066 }
1067 return __npos;
1068}
1069
1070
Marshall Clow37025e12014-06-10 18:51:55 +00001071// __str_find_first_not_of
Marshall Clowb671fc92013-12-09 16:00:28 +00001072template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Marshall Clow360f3192014-06-02 02:22:49 +00001073_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001074__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001075 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001076{
1077 if (__pos < __sz)
1078 {
1079 const _CharT* __pe = __p + __sz;
1080 for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
1081 if (_Traits::find(__s, __n, *__ps) == 0)
1082 return static_cast<_SizeT>(__ps - __p);
1083 }
1084 return __npos;
1085}
1086
1087
1088template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Marshall Clow360f3192014-06-02 02:22:49 +00001089_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001090__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001091 _CharT __c, _SizeT __pos) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001092{
1093 if (__pos < __sz)
1094 {
1095 const _CharT* __pe = __p + __sz;
1096 for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
1097 if (!_Traits::eq(*__ps, __c))
1098 return static_cast<_SizeT>(__ps - __p);
1099 }
1100 return __npos;
1101}
1102
1103
Marshall Clow37025e12014-06-10 18:51:55 +00001104// __str_find_last_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_last_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 ++__pos;
1112 else
1113 __pos = __sz;
1114 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1115 if (_Traits::find(__s, __n, *--__ps) == 0)
1116 return static_cast<_SizeT>(__ps - __p);
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_last_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 ++__pos;
1128 else
1129 __pos = __sz;
1130 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1131 if (!_Traits::eq(*--__ps, __c))
1132 return static_cast<_SizeT>(__ps - __p);
1133 return __npos;
1134}
1135
1136template<class _Ptr>
1137size_t _LIBCPP_INLINE_VISIBILITY __do_string_hash(_Ptr __p, _Ptr __e)
1138{
1139 typedef typename iterator_traits<_Ptr>::value_type value_type;
1140 return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));
1141}
1142
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001143// basic_string
1144
1145template<class _CharT, class _Traits, class _Allocator>
1146basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001147operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
1148 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001149
1150template<class _CharT, class _Traits, class _Allocator>
1151basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001152operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001153
1154template<class _CharT, class _Traits, class _Allocator>
1155basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001156operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001157
1158template<class _CharT, class _Traits, class _Allocator>
1159basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001160operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001161
1162template<class _CharT, class _Traits, class _Allocator>
1163basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001164operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001165
1166template <bool>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001167class _LIBCPP_TYPE_VIS_ONLY __basic_string_common
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001168{
1169protected:
1170 void __throw_length_error() const;
1171 void __throw_out_of_range() const;
1172};
1173
1174template <bool __b>
1175void
1176__basic_string_common<__b>::__throw_length_error() const
1177{
1178#ifndef _LIBCPP_NO_EXCEPTIONS
1179 throw length_error("basic_string");
1180#else
1181 assert(!"basic_string length_error");
1182#endif
1183}
1184
1185template <bool __b>
1186void
1187__basic_string_common<__b>::__throw_out_of_range() const
1188{
1189#ifndef _LIBCPP_NO_EXCEPTIONS
1190 throw out_of_range("basic_string");
1191#else
1192 assert(!"basic_string out_of_range");
1193#endif
1194}
1195
Howard Hinnante9df0a52013-08-01 18:17:34 +00001196#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +00001197#pragma warning( push )
1198#pragma warning( disable: 4231 )
Howard Hinnante9df0a52013-08-01 18:17:34 +00001199#endif // _LIBCPP_MSVC
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001200_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __basic_string_common<true>)
Howard Hinnante9df0a52013-08-01 18:17:34 +00001201#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +00001202#pragma warning( pop )
Howard Hinnante9df0a52013-08-01 18:17:34 +00001203#endif // _LIBCPP_MSVC
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001204
Marshall Clowdf9db312016-01-13 21:54:34 +00001205#ifdef _LIBCPP_NO_EXCEPTIONS
1206template <class _Iter>
1207struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
1208#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
1209template <class _Iter>
1210struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
1211#else
1212template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
1213struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
1214 noexcept(++(declval<_Iter&>())) &&
1215 is_nothrow_assignable<_Iter&, _Iter>::value &&
1216 noexcept(declval<_Iter>() == declval<_Iter>()) &&
1217 noexcept(*declval<_Iter>())
1218)) {};
1219
1220template <class _Iter>
1221struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
1222#endif
1223
1224
1225template <class _Iter>
1226struct __libcpp_string_gets_noexcept_iterator
1227 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
1228
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001229#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001230
1231template <class _CharT, size_t = sizeof(_CharT)>
1232struct __padding
1233{
1234 unsigned char __xx[sizeof(_CharT)-1];
1235};
1236
1237template <class _CharT>
1238struct __padding<_CharT, 1>
1239{
1240};
1241
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001242#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001243
Howard Hinnant324bb032010-08-22 00:02:43 +00001244template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001245class _LIBCPP_TYPE_VIS_ONLY basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001246 : private __basic_string_common<true>
1247{
1248public:
1249 typedef basic_string __self;
1250 typedef _Traits traits_type;
1251 typedef typename traits_type::char_type value_type;
1252 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001253 typedef allocator_traits<allocator_type> __alloc_traits;
1254 typedef typename __alloc_traits::size_type size_type;
1255 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001256 typedef value_type& reference;
1257 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001258 typedef typename __alloc_traits::pointer pointer;
1259 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001260
Howard Hinnant499cea12013-08-23 17:37:05 +00001261 static_assert(is_pod<value_type>::value, "Character type of basic_string must be a POD");
1262 static_assert((is_same<_CharT, value_type>::value),
1263 "traits_type::char_type must be the same type as CharT");
1264 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1265 "Allocator::value_type must be same type as value_type");
1266#if defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001267 typedef pointer iterator;
1268 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001269#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001270 typedef __wrap_iter<pointer> iterator;
1271 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001272#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001273 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1274 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001275
1276private:
Howard Hinnant15467182013-04-30 21:44:48 +00001277
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001278#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001279
1280 struct __long
1281 {
1282 pointer __data_;
1283 size_type __size_;
1284 size_type __cap_;
1285 };
1286
1287#if _LIBCPP_BIG_ENDIAN
1288 enum {__short_mask = 0x01};
1289 enum {__long_mask = 0x1ul};
1290#else // _LIBCPP_BIG_ENDIAN
1291 enum {__short_mask = 0x80};
1292 enum {__long_mask = ~(size_type(~0) >> 1)};
1293#endif // _LIBCPP_BIG_ENDIAN
1294
1295 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1296 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1297
1298 struct __short
1299 {
1300 value_type __data_[__min_cap];
1301 struct
1302 : __padding<value_type>
1303 {
1304 unsigned char __size_;
1305 };
1306 };
1307
1308#else
1309
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001310 struct __long
1311 {
1312 size_type __cap_;
1313 size_type __size_;
1314 pointer __data_;
1315 };
1316
1317#if _LIBCPP_BIG_ENDIAN
1318 enum {__short_mask = 0x80};
1319 enum {__long_mask = ~(size_type(~0) >> 1)};
Howard Hinnant324bb032010-08-22 00:02:43 +00001320#else // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001321 enum {__short_mask = 0x01};
Howard Hinnantec3773c2011-12-01 20:21:04 +00001322 enum {__long_mask = 0x1ul};
Howard Hinnant324bb032010-08-22 00:02:43 +00001323#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001324
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001325 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1326 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1327
1328 struct __short
1329 {
1330 union
1331 {
1332 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59 +00001333 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001334 };
1335 value_type __data_[__min_cap];
1336 };
1337
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001338#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001339
Howard Hinnant499cea12013-08-23 17:37:05 +00001340 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001341
Howard Hinnant499cea12013-08-23 17:37:05 +00001342 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001343
1344 struct __raw
1345 {
1346 size_type __words[__n_words];
1347 };
1348
1349 struct __rep
1350 {
1351 union
1352 {
1353 __long __l;
1354 __short __s;
1355 __raw __r;
1356 };
1357 };
1358
1359 __compressed_pair<__rep, allocator_type> __r_;
1360
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001361public:
1362 static const size_type npos = -1;
1363
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001364 _LIBCPP_INLINE_VISIBILITY basic_string()
1365 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +00001366
1367 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
1368#if _LIBCPP_STD_VER <= 14
1369 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
1370#else
1371 _NOEXCEPT;
1372#endif
1373
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001374 basic_string(const basic_string& __str);
1375 basic_string(const basic_string& __str, const allocator_type& __a);
Marshall Clow7b193f72015-06-03 19:56:43 +00001376
Howard Hinnant73d21a42010-09-04 23:28:19 +00001377#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9f193f22011-01-26 00:06:59 +00001378 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001379 basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +00001380#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001381 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +00001382#else
1383 _NOEXCEPT;
1384#endif
1385
Howard Hinnant9f193f22011-01-26 00:06:59 +00001386 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001387 basic_string(basic_string&& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001388#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001389 _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s);
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, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001392 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001393 basic_string(const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001394 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001395 basic_string(const value_type* __s, size_type __n, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001396 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001397 basic_string(size_type __n, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001398 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001399 basic_string(size_type __n, value_type __c, const allocator_type& __a);
1400 basic_string(const basic_string& __str, size_type __pos, size_type __n = npos,
1401 const allocator_type& __a = allocator_type());
1402 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001403 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001404 basic_string(_InputIterator __first, _InputIterator __last);
1405 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001406 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001407 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001408#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001409 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001410 basic_string(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001411 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001412 basic_string(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001413#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001414
1415 ~basic_string();
1416
Howard Hinnante32b5e22010-11-17 17:55:08 +00001417 basic_string& operator=(const basic_string& __str);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001418#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001419 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001420 basic_string& operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001421 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001422#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001423 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001424 basic_string& operator=(value_type __c);
Howard Hinnante3e32912011-08-12 21:56:02 +00001425#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001426 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001427 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001428#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001429
Howard Hinnant499cea12013-08-23 17:37:05 +00001430#if _LIBCPP_DEBUG_LEVEL >= 2
1431 _LIBCPP_INLINE_VISIBILITY
1432 iterator begin() _NOEXCEPT
1433 {return iterator(this, __get_pointer());}
1434 _LIBCPP_INLINE_VISIBILITY
1435 const_iterator begin() const _NOEXCEPT
1436 {return const_iterator(this, __get_pointer());}
1437 _LIBCPP_INLINE_VISIBILITY
1438 iterator end() _NOEXCEPT
1439 {return iterator(this, __get_pointer() + size());}
1440 _LIBCPP_INLINE_VISIBILITY
1441 const_iterator end() const _NOEXCEPT
1442 {return const_iterator(this, __get_pointer() + size());}
1443#else
Howard Hinnanta6119a82011-05-29 19:57:12 +00001444 _LIBCPP_INLINE_VISIBILITY
1445 iterator begin() _NOEXCEPT
1446 {return iterator(__get_pointer());}
1447 _LIBCPP_INLINE_VISIBILITY
1448 const_iterator begin() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001449 {return const_iterator(__get_pointer());}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001450 _LIBCPP_INLINE_VISIBILITY
1451 iterator end() _NOEXCEPT
1452 {return iterator(__get_pointer() + size());}
1453 _LIBCPP_INLINE_VISIBILITY
1454 const_iterator end() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001455 {return const_iterator(__get_pointer() + size());}
Howard Hinnant499cea12013-08-23 17:37:05 +00001456#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnanta6119a82011-05-29 19:57:12 +00001457 _LIBCPP_INLINE_VISIBILITY
1458 reverse_iterator rbegin() _NOEXCEPT
1459 {return reverse_iterator(end());}
1460 _LIBCPP_INLINE_VISIBILITY
1461 const_reverse_iterator rbegin() const _NOEXCEPT
1462 {return const_reverse_iterator(end());}
1463 _LIBCPP_INLINE_VISIBILITY
1464 reverse_iterator rend() _NOEXCEPT
1465 {return reverse_iterator(begin());}
1466 _LIBCPP_INLINE_VISIBILITY
1467 const_reverse_iterator rend() const _NOEXCEPT
1468 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001469
Howard Hinnanta6119a82011-05-29 19:57:12 +00001470 _LIBCPP_INLINE_VISIBILITY
1471 const_iterator cbegin() const _NOEXCEPT
1472 {return begin();}
1473 _LIBCPP_INLINE_VISIBILITY
1474 const_iterator cend() const _NOEXCEPT
1475 {return end();}
1476 _LIBCPP_INLINE_VISIBILITY
1477 const_reverse_iterator crbegin() const _NOEXCEPT
1478 {return rbegin();}
1479 _LIBCPP_INLINE_VISIBILITY
1480 const_reverse_iterator crend() const _NOEXCEPT
1481 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001482
Howard Hinnanta6119a82011-05-29 19:57:12 +00001483 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001484 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001485 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
1486 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
1487 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001488 {return (__is_long() ? __get_long_cap()
1489 : static_cast<size_type>(__min_cap)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001490
1491 void resize(size_type __n, value_type __c);
1492 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
1493
1494 void reserve(size_type res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001495 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001496 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001497 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001498 void clear() _NOEXCEPT;
1499 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001500
1501 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const;
1502 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos);
1503
1504 const_reference at(size_type __n) const;
1505 reference at(size_type __n);
1506
1507 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001508 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001509 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +00001510#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001511 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Howard Hinnante3e32912011-08-12 21:56:02 +00001512#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001513
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001514 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001515 basic_string& append(const basic_string& __str);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001516 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001517 basic_string& append(const value_type* __s, size_type __n);
1518 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001519 basic_string& append(size_type __n, value_type __c);
1520 template<class _InputIterator>
1521 typename enable_if
1522 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001523 __is_exactly_input_iterator<_InputIterator>::value
1524 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001525 basic_string&
1526 >::type
1527 append(_InputIterator __first, _InputIterator __last);
1528 template<class _ForwardIterator>
1529 typename enable_if
1530 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001531 __is_forward_iterator<_ForwardIterator>::value
1532 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001533 basic_string&
1534 >::type
1535 append(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001536#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001537 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001538 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001539#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001540
1541 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001542 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001543 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001544 _LIBCPP_INLINE_VISIBILITY reference front();
1545 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
1546 _LIBCPP_INLINE_VISIBILITY reference back();
1547 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001548
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001549 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001550 basic_string& assign(const basic_string& __str);
Howard Hinnanta6119a82011-05-29 19:57:12 +00001551#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1552 _LIBCPP_INLINE_VISIBILITY
1553 basic_string& assign(basic_string&& str)
Marshall Clow7ed093b2015-10-05 16:17:34 +00001554 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +00001555 {*this = _VSTD::move(str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001556#endif
Marshall Clowa93b5e22014-03-04 19:17:19 +00001557 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001558 basic_string& assign(const value_type* __s, size_type __n);
1559 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001560 basic_string& assign(size_type __n, value_type __c);
1561 template<class _InputIterator>
1562 typename enable_if
1563 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001564 __is_exactly_input_iterator<_InputIterator>::value
1565 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001566 basic_string&
1567 >::type
1568 assign(_InputIterator __first, _InputIterator __last);
1569 template<class _ForwardIterator>
1570 typename enable_if
1571 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001572 __is_forward_iterator<_ForwardIterator>::value
1573 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001574 basic_string&
1575 >::type
1576 assign(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001577#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001579 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001580#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001581
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001583 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001584 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001585 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1586 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001587 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1588 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001589 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001590 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1591 template<class _InputIterator>
1592 typename enable_if
1593 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001594 __is_exactly_input_iterator<_InputIterator>::value
1595 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001596 iterator
1597 >::type
1598 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1599 template<class _ForwardIterator>
1600 typename enable_if
1601 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001602 __is_forward_iterator<_ForwardIterator>::value
1603 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001604 iterator
1605 >::type
1606 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001607#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001608 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001609 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1610 {return insert(__pos, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001611#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001612
1613 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001614 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001615 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001616 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001617 iterator erase(const_iterator __first, const_iterator __last);
1618
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001619 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001620 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001621 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 +00001622 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1623 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001624 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001625 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001626 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001628 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001629 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001630 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001631 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001632 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001633 template<class _InputIterator>
1634 typename enable_if
1635 <
1636 __is_input_iterator<_InputIterator>::value,
1637 basic_string&
1638 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001639 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Howard Hinnante3e32912011-08-12 21:56:02 +00001640#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001641 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001642 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001643 {return replace(__i1, __i2, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001644#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001645
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001646 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001647 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001648 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1649
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001650 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001651 void swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00001652#if _LIBCPP_STD_VER >= 14
1653 _NOEXCEPT;
1654#else
1655 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1656 __is_nothrow_swappable<allocator_type>::value);
1657#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001658
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001659 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001660 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001661 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001662 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Marshall Clowf532a702016-03-08 15:44:30 +00001663#if _LIBCPP_STD_VER > 14
1664 _LIBCPP_INLINE_VISIBILITY
1665 value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1666#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001667
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001669 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001670
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001671 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001672 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001673 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001674 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001675 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001676 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001677
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001679 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001680 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001681 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001682 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001683 size_type rfind(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_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001687 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001688 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001689 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001690 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001691 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001692
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001693 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001694 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001695 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001697 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001698 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001699 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001700
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001701 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001702 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001703 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 +00001704 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001705 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001706 _LIBCPP_INLINE_VISIBILITY
1707 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1708
1709 _LIBCPP_INLINE_VISIBILITY
1710 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001711 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 +00001712 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001713 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001714 _LIBCPP_INLINE_VISIBILITY
1715 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1716
1717 _LIBCPP_INLINE_VISIBILITY
1718 int compare(const basic_string& __str) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001719 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001720 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clowa93b5e22014-03-04 19:17:19 +00001721 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 +00001722 int compare(const value_type* __s) const _NOEXCEPT;
1723 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1724 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001725
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001726 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:13 +00001727
1728 _LIBCPP_INLINE_VISIBILITY
1729 bool __is_long() const _NOEXCEPT
1730 {return bool(__r_.first().__s.__size_ & __short_mask);}
1731
Howard Hinnant499cea12013-08-23 17:37:05 +00001732#if _LIBCPP_DEBUG_LEVEL >= 2
1733
1734 bool __dereferenceable(const const_iterator* __i) const;
1735 bool __decrementable(const const_iterator* __i) const;
1736 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1737 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1738
1739#endif // _LIBCPP_DEBUG_LEVEL >= 2
1740
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001741private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001742 _LIBCPP_INLINE_VISIBILITY
1743 allocator_type& __alloc() _NOEXCEPT
1744 {return __r_.second();}
1745 _LIBCPP_INLINE_VISIBILITY
1746 const allocator_type& __alloc() const _NOEXCEPT
1747 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001748
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001749#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001750
Howard Hinnanta6119a82011-05-29 19:57:12 +00001751 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001752 void __set_short_size(size_type __s) _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001753# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001754 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:48 +00001755# else
1756 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1757# endif
1758
Howard Hinnanta6119a82011-05-29 19:57:12 +00001759 _LIBCPP_INLINE_VISIBILITY
1760 size_type __get_short_size() const _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001761# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001762 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:48 +00001763# else
1764 {return __r_.first().__s.__size_;}
1765# endif
1766
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001767#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001768
1769 _LIBCPP_INLINE_VISIBILITY
1770 void __set_short_size(size_type __s) _NOEXCEPT
1771# if _LIBCPP_BIG_ENDIAN
1772 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1773# else
1774 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1775# endif
1776
1777 _LIBCPP_INLINE_VISIBILITY
1778 size_type __get_short_size() const _NOEXCEPT
1779# if _LIBCPP_BIG_ENDIAN
1780 {return __r_.first().__s.__size_;}
1781# else
1782 {return __r_.first().__s.__size_ >> 1;}
1783# endif
1784
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001785#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001786
Howard Hinnanta6119a82011-05-29 19:57:12 +00001787 _LIBCPP_INLINE_VISIBILITY
1788 void __set_long_size(size_type __s) _NOEXCEPT
1789 {__r_.first().__l.__size_ = __s;}
1790 _LIBCPP_INLINE_VISIBILITY
1791 size_type __get_long_size() const _NOEXCEPT
1792 {return __r_.first().__l.__size_;}
1793 _LIBCPP_INLINE_VISIBILITY
1794 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001795 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1796
Howard Hinnanta6119a82011-05-29 19:57:12 +00001797 _LIBCPP_INLINE_VISIBILITY
1798 void __set_long_cap(size_type __s) _NOEXCEPT
1799 {__r_.first().__l.__cap_ = __long_mask | __s;}
1800 _LIBCPP_INLINE_VISIBILITY
1801 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001802 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001803
Howard Hinnanta6119a82011-05-29 19:57:12 +00001804 _LIBCPP_INLINE_VISIBILITY
1805 void __set_long_pointer(pointer __p) _NOEXCEPT
1806 {__r_.first().__l.__data_ = __p;}
1807 _LIBCPP_INLINE_VISIBILITY
1808 pointer __get_long_pointer() _NOEXCEPT
1809 {return __r_.first().__l.__data_;}
1810 _LIBCPP_INLINE_VISIBILITY
1811 const_pointer __get_long_pointer() const _NOEXCEPT
1812 {return __r_.first().__l.__data_;}
1813 _LIBCPP_INLINE_VISIBILITY
1814 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001815 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001816 _LIBCPP_INLINE_VISIBILITY
1817 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001818 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001819 _LIBCPP_INLINE_VISIBILITY
1820 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001821 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001822 _LIBCPP_INLINE_VISIBILITY
1823 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001824 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1825
Howard Hinnanta6119a82011-05-29 19:57:12 +00001826 _LIBCPP_INLINE_VISIBILITY
1827 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001828 {
1829 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1830 for (unsigned __i = 0; __i < __n_words; ++__i)
1831 __a[__i] = 0;
1832 }
1833
1834 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001835 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:20 +00001836 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001837 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001838 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001839 static _LIBCPP_INLINE_VISIBILITY
1840 size_type __recommend(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001841 {return (__s < __min_cap ? static_cast<size_type>(__min_cap) :
Howard Hinnant7f764502013-08-14 18:00:20 +00001842 __align_it<sizeof(value_type) < __alignment ?
Howard Hinnanta6119a82011-05-29 19:57:12 +00001843 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001844
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001845 void __init(const value_type* __s, size_type __sz, size_type __reserve);
1846 void __init(const value_type* __s, size_type __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001847 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001848
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001849 template <class _InputIterator>
1850 typename enable_if
1851 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001852 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001853 void
1854 >::type
1855 __init(_InputIterator __first, _InputIterator __last);
1856
1857 template <class _ForwardIterator>
1858 typename enable_if
1859 <
1860 __is_forward_iterator<_ForwardIterator>::value,
1861 void
1862 >::type
1863 __init(_ForwardIterator __first, _ForwardIterator __last);
1864
1865 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001866 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001867 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1868 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001869 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001870
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001871 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001872 void __erase_to_end(size_type __pos);
1873
Howard Hinnante32b5e22010-11-17 17:55:08 +00001874 _LIBCPP_INLINE_VISIBILITY
1875 void __copy_assign_alloc(const basic_string& __str)
1876 {__copy_assign_alloc(__str, integral_constant<bool,
1877 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1878
1879 _LIBCPP_INLINE_VISIBILITY
1880 void __copy_assign_alloc(const basic_string& __str, true_type)
1881 {
1882 if (__alloc() != __str.__alloc())
1883 {
1884 clear();
1885 shrink_to_fit();
1886 }
1887 __alloc() = __str.__alloc();
1888 }
1889
1890 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001891 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001892 {}
1893
1894#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001895 _LIBCPP_INLINE_VISIBILITY
Marshall Clowaf961ed2015-08-18 18:57:00 +00001896 void __move_assign(basic_string& __str, false_type)
1897 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001899 void __move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001900#if _LIBCPP_STD_VER > 14
1901 _NOEXCEPT;
1902#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001903 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001904#endif
Marshall Clowaf961ed2015-08-18 18:57:00 +00001905#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00001906
1907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001908 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001909 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001910 _NOEXCEPT_(
1911 !__alloc_traits::propagate_on_container_move_assignment::value ||
1912 is_nothrow_move_assignable<allocator_type>::value)
1913 {__move_assign_alloc(__str, integral_constant<bool,
1914 __alloc_traits::propagate_on_container_move_assignment::value>());}
1915
1916 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001917 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001918 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1919 {
1920 __alloc() = _VSTD::move(__c.__alloc());
1921 }
1922
1923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001924 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001925 _NOEXCEPT
1926 {}
1927
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001928 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1929 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001930
1931 friend basic_string operator+<>(const basic_string&, const basic_string&);
1932 friend basic_string operator+<>(const value_type*, const basic_string&);
1933 friend basic_string operator+<>(value_type, const basic_string&);
1934 friend basic_string operator+<>(const basic_string&, const value_type*);
1935 friend basic_string operator+<>(const basic_string&, value_type);
1936};
1937
1938template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001939inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001940void
1941basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1942{
Howard Hinnant499cea12013-08-23 17:37:05 +00001943#if _LIBCPP_DEBUG_LEVEL >= 2
1944 __get_db()->__invalidate_all(this);
1945#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001946}
1947
1948template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001949inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001950void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001951basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant499cea12013-08-23 17:37:05 +00001952#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantec3773c2011-12-01 20:21:04 +00001953 __pos
1954#endif
1955 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001956{
Howard Hinnant499cea12013-08-23 17:37:05 +00001957#if _LIBCPP_DEBUG_LEVEL >= 2
1958 __c_node* __c = __get_db()->__find_c_and_lock(this);
1959 if (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001960 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001961 const_pointer __new_last = __get_pointer() + __pos;
1962 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001963 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001964 --__p;
1965 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1966 if (__i->base() > __new_last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001967 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001968 (*__p)->__c_ = nullptr;
1969 if (--__c->end_ != __p)
1970 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001971 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001972 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001973 __get_db()->unlock();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001974 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001975#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001976}
1977
1978template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001979inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001980basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowc912c0c2015-06-04 02:05:41 +00001981 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001982{
Howard Hinnant499cea12013-08-23 17:37:05 +00001983#if _LIBCPP_DEBUG_LEVEL >= 2
1984 __get_db()->__insert_c(this);
1985#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001986 __zero();
1987}
1988
1989template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001990inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001991basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiselier692177d2015-07-18 20:40:46 +00001992#if _LIBCPP_STD_VER <= 14
1993 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1994#else
1995 _NOEXCEPT
1996#endif
1997: __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001998{
Howard Hinnant499cea12013-08-23 17:37:05 +00001999#if _LIBCPP_DEBUG_LEVEL >= 2
2000 __get_db()->__insert_c(this);
2001#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002002 __zero();
2003}
2004
2005template <class _CharT, class _Traits, class _Allocator>
2006void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002007basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002008{
2009 if (__reserve > max_size())
2010 this->__throw_length_error();
2011 pointer __p;
2012 if (__reserve < __min_cap)
2013 {
2014 __set_short_size(__sz);
2015 __p = __get_short_pointer();
2016 }
2017 else
2018 {
2019 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002020 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002021 __set_long_pointer(__p);
2022 __set_long_cap(__cap+1);
2023 __set_long_size(__sz);
2024 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002025 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002026 traits_type::assign(__p[__sz], value_type());
2027}
2028
2029template <class _CharT, class _Traits, class _Allocator>
2030void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002031basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002032{
2033 if (__sz > max_size())
2034 this->__throw_length_error();
2035 pointer __p;
2036 if (__sz < __min_cap)
2037 {
2038 __set_short_size(__sz);
2039 __p = __get_short_pointer();
2040 }
2041 else
2042 {
2043 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002044 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002045 __set_long_pointer(__p);
2046 __set_long_cap(__cap+1);
2047 __set_long_size(__sz);
2048 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002049 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002050 traits_type::assign(__p[__sz], value_type());
2051}
2052
2053template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002054inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002055basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002056{
Howard Hinnant499cea12013-08-23 17:37:05 +00002057 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002058 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00002059#if _LIBCPP_DEBUG_LEVEL >= 2
2060 __get_db()->__insert_c(this);
2061#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002062}
2063
2064template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002065inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002066basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002067 : __r_(__a)
2068{
Howard Hinnant499cea12013-08-23 17:37:05 +00002069 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002070 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00002071#if _LIBCPP_DEBUG_LEVEL >= 2
2072 __get_db()->__insert_c(this);
2073#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002074}
2075
2076template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002077inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002078basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002079{
Howard Hinnant499cea12013-08-23 17:37:05 +00002080 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002081 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00002082#if _LIBCPP_DEBUG_LEVEL >= 2
2083 __get_db()->__insert_c(this);
2084#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002085}
2086
2087template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002088inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002089basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002090 : __r_(__a)
2091{
Howard Hinnant499cea12013-08-23 17:37:05 +00002092 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002093 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00002094#if _LIBCPP_DEBUG_LEVEL >= 2
2095 __get_db()->__insert_c(this);
2096#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002097}
2098
2099template <class _CharT, class _Traits, class _Allocator>
2100basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002101 : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002102{
2103 if (!__str.__is_long())
2104 __r_.first().__r = __str.__r_.first().__r;
2105 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002106 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00002107#if _LIBCPP_DEBUG_LEVEL >= 2
2108 __get_db()->__insert_c(this);
2109#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002110}
2111
2112template <class _CharT, class _Traits, class _Allocator>
2113basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
2114 : __r_(__a)
2115{
2116 if (!__str.__is_long())
2117 __r_.first().__r = __str.__r_.first().__r;
2118 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002119 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00002120#if _LIBCPP_DEBUG_LEVEL >= 2
2121 __get_db()->__insert_c(this);
2122#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002123}
2124
Howard Hinnant73d21a42010-09-04 23:28:19 +00002125#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002126
2127template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002128inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002129basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +00002130#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002131 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clow7b193f72015-06-03 19:56:43 +00002132#else
2133 _NOEXCEPT
2134#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00002135 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002136{
2137 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:05 +00002138#if _LIBCPP_DEBUG_LEVEL >= 2
2139 __get_db()->__insert_c(this);
2140 if (__is_long())
2141 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002142#endif
2143}
2144
2145template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002146inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002147basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002148 : __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002149{
Marshall Clowd5549cc2014-07-17 15:32:20 +00002150 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002151 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd5549cc2014-07-17 15:32:20 +00002152 else
2153 {
2154 __r_.first().__r = __str.__r_.first().__r;
2155 __str.__zero();
2156 }
Howard Hinnant499cea12013-08-23 17:37:05 +00002157#if _LIBCPP_DEBUG_LEVEL >= 2
2158 __get_db()->__insert_c(this);
2159 if (__is_long())
2160 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002161#endif
2162}
2163
Howard Hinnant73d21a42010-09-04 23:28:19 +00002164#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002165
2166template <class _CharT, class _Traits, class _Allocator>
2167void
2168basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
2169{
2170 if (__n > max_size())
2171 this->__throw_length_error();
2172 pointer __p;
2173 if (__n < __min_cap)
2174 {
2175 __set_short_size(__n);
2176 __p = __get_short_pointer();
2177 }
2178 else
2179 {
2180 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002181 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002182 __set_long_pointer(__p);
2183 __set_long_cap(__cap+1);
2184 __set_long_size(__n);
2185 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002186 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002187 traits_type::assign(__p[__n], value_type());
2188}
2189
2190template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002191inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002192basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
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
2200template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002201inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002202basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
2203 : __r_(__a)
2204{
2205 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00002206#if _LIBCPP_DEBUG_LEVEL >= 2
2207 __get_db()->__insert_c(this);
2208#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002209}
2210
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002211template <class _CharT, class _Traits, class _Allocator>
2212basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
2213 const allocator_type& __a)
2214 : __r_(__a)
2215{
2216 size_type __str_sz = __str.size();
2217 if (__pos > __str_sz)
2218 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002219 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant499cea12013-08-23 17:37:05 +00002220#if _LIBCPP_DEBUG_LEVEL >= 2
2221 __get_db()->__insert_c(this);
2222#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002223}
2224
2225template <class _CharT, class _Traits, class _Allocator>
2226template <class _InputIterator>
2227typename enable_if
2228<
Marshall Clowdf9db312016-01-13 21:54:34 +00002229 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002230 void
2231>::type
2232basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2233{
2234 __zero();
2235#ifndef _LIBCPP_NO_EXCEPTIONS
2236 try
2237 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002238#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002239 for (; __first != __last; ++__first)
2240 push_back(*__first);
2241#ifndef _LIBCPP_NO_EXCEPTIONS
2242 }
2243 catch (...)
2244 {
2245 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002246 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002247 throw;
2248 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002249#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002250}
2251
2252template <class _CharT, class _Traits, class _Allocator>
2253template <class _ForwardIterator>
2254typename enable_if
2255<
2256 __is_forward_iterator<_ForwardIterator>::value,
2257 void
2258>::type
2259basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2260{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002261 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002262 if (__sz > max_size())
2263 this->__throw_length_error();
2264 pointer __p;
2265 if (__sz < __min_cap)
2266 {
2267 __set_short_size(__sz);
2268 __p = __get_short_pointer();
2269 }
2270 else
2271 {
2272 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002273 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002274 __set_long_pointer(__p);
2275 __set_long_cap(__cap+1);
2276 __set_long_size(__sz);
2277 }
Eric Fiselierb9919752014-10-27 19:28:20 +00002278 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002279 traits_type::assign(*__p, *__first);
2280 traits_type::assign(*__p, value_type());
2281}
2282
2283template <class _CharT, class _Traits, class _Allocator>
2284template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002285inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002286basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2287{
2288 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002289#if _LIBCPP_DEBUG_LEVEL >= 2
2290 __get_db()->__insert_c(this);
2291#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002292}
2293
2294template <class _CharT, class _Traits, class _Allocator>
2295template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002296inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002297basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2298 const allocator_type& __a)
2299 : __r_(__a)
2300{
2301 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002302#if _LIBCPP_DEBUG_LEVEL >= 2
2303 __get_db()->__insert_c(this);
2304#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002305}
2306
Howard Hinnante3e32912011-08-12 21:56:02 +00002307#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2308
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002309template <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)
2312{
2313 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002314#if _LIBCPP_DEBUG_LEVEL >= 2
2315 __get_db()->__insert_c(this);
2316#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002317}
2318
2319template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002320inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002321basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
2322 : __r_(__a)
2323{
2324 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002325#if _LIBCPP_DEBUG_LEVEL >= 2
2326 __get_db()->__insert_c(this);
2327#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002328}
2329
Howard Hinnante3e32912011-08-12 21:56:02 +00002330#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2331
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002332template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002333basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2334{
Howard Hinnant499cea12013-08-23 17:37:05 +00002335#if _LIBCPP_DEBUG_LEVEL >= 2
2336 __get_db()->__erase_c(this);
2337#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002338 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002339 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002340}
2341
2342template <class _CharT, class _Traits, class _Allocator>
2343void
2344basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2345 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002346 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 +00002347{
2348 size_type __ms = max_size();
2349 if (__delta_cap > __ms - __old_cap - 1)
2350 this->__throw_length_error();
2351 pointer __old_p = __get_pointer();
2352 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002353 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002354 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002355 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002356 __invalidate_all_iterators();
2357 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002358 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2359 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002360 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002361 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002362 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2363 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002364 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2365 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002366 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002367 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002368 __set_long_pointer(__p);
2369 __set_long_cap(__cap+1);
2370 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2371 __set_long_size(__old_sz);
2372 traits_type::assign(__p[__old_sz], value_type());
2373}
2374
2375template <class _CharT, class _Traits, class _Allocator>
2376void
2377basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2378 size_type __n_copy, size_type __n_del, size_type __n_add)
2379{
2380 size_type __ms = max_size();
Marshall Clowecc8d7b2013-11-06 14:24:38 +00002381 if (__delta_cap > __ms - __old_cap)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002382 this->__throw_length_error();
2383 pointer __old_p = __get_pointer();
2384 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002385 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002386 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002387 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002388 __invalidate_all_iterators();
2389 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002390 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2391 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002392 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2393 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002394 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2395 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
2396 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002397 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002398 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002399 __set_long_pointer(__p);
2400 __set_long_cap(__cap+1);
2401}
2402
2403// assign
2404
2405template <class _CharT, class _Traits, class _Allocator>
2406basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002407basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002408{
Alp Tokerec34c482014-05-15 11:27:39 +00002409 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002410 size_type __cap = capacity();
2411 if (__cap >= __n)
2412 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002413 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002414 traits_type::move(__p, __s, __n);
2415 traits_type::assign(__p[__n], value_type());
2416 __set_size(__n);
2417 __invalidate_iterators_past(__n);
2418 }
2419 else
2420 {
2421 size_type __sz = size();
2422 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2423 }
2424 return *this;
2425}
2426
2427template <class _CharT, class _Traits, class _Allocator>
2428basic_string<_CharT, _Traits, _Allocator>&
2429basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2430{
2431 size_type __cap = capacity();
2432 if (__cap < __n)
2433 {
2434 size_type __sz = size();
2435 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2436 }
2437 else
2438 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002439 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002440 traits_type::assign(__p, __n, __c);
2441 traits_type::assign(__p[__n], value_type());
2442 __set_size(__n);
2443 return *this;
2444}
2445
2446template <class _CharT, class _Traits, class _Allocator>
2447basic_string<_CharT, _Traits, _Allocator>&
2448basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2449{
2450 pointer __p;
2451 if (__is_long())
2452 {
2453 __p = __get_long_pointer();
2454 __set_long_size(1);
2455 }
2456 else
2457 {
2458 __p = __get_short_pointer();
2459 __set_short_size(1);
2460 }
2461 traits_type::assign(*__p, __c);
2462 traits_type::assign(*++__p, value_type());
2463 __invalidate_iterators_past(1);
2464 return *this;
2465}
2466
2467template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00002468basic_string<_CharT, _Traits, _Allocator>&
2469basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2470{
2471 if (this != &__str)
2472 {
2473 __copy_assign_alloc(__str);
2474 assign(__str);
2475 }
2476 return *this;
2477}
2478
2479#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2480
2481template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002482inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002483void
2484basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002485 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002486{
2487 if (__alloc() != __str.__alloc())
2488 assign(__str);
2489 else
2490 __move_assign(__str, true_type());
2491}
2492
2493template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002494inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002495void
2496basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002497#if _LIBCPP_STD_VER > 14
2498 _NOEXCEPT
2499#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002500 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002501#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00002502{
2503 clear();
2504 shrink_to_fit();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00002505 __r_.first() = __str.__r_.first();
2506 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002507 __str.__zero();
2508}
2509
2510template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002511inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002512basic_string<_CharT, _Traits, _Allocator>&
2513basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002514 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnante32b5e22010-11-17 17:55:08 +00002515{
2516 __move_assign(__str, integral_constant<bool,
2517 __alloc_traits::propagate_on_container_move_assignment::value>());
2518 return *this;
2519}
2520
2521#endif
2522
2523template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002524template<class _InputIterator>
2525typename enable_if
2526<
Marshall Clowdf9db312016-01-13 21:54:34 +00002527 __is_exactly_input_iterator <_InputIterator>::value
2528 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002529 basic_string<_CharT, _Traits, _Allocator>&
2530>::type
2531basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2532{
Marshall Clowdf9db312016-01-13 21:54:34 +00002533 basic_string __temp(__first, __last, __alloc());
2534 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002535 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002536}
2537
2538template <class _CharT, class _Traits, class _Allocator>
2539template<class _ForwardIterator>
2540typename enable_if
2541<
Marshall Clowdf9db312016-01-13 21:54:34 +00002542 __is_forward_iterator<_ForwardIterator>::value
2543 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002544 basic_string<_CharT, _Traits, _Allocator>&
2545>::type
2546basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2547{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002548 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002549 size_type __cap = capacity();
2550 if (__cap < __n)
2551 {
2552 size_type __sz = size();
2553 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2554 }
2555 else
2556 __invalidate_iterators_past(__n);
2557 pointer __p = __get_pointer();
2558 for (; __first != __last; ++__first, ++__p)
2559 traits_type::assign(*__p, *__first);
2560 traits_type::assign(*__p, value_type());
2561 __set_size(__n);
2562 return *this;
2563}
2564
2565template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002566inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002567basic_string<_CharT, _Traits, _Allocator>&
2568basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str)
2569{
2570 return assign(__str.data(), __str.size());
2571}
2572
2573template <class _CharT, class _Traits, class _Allocator>
2574basic_string<_CharT, _Traits, _Allocator>&
2575basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2576{
2577 size_type __sz = __str.size();
2578 if (__pos > __sz)
2579 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002580 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002581}
2582
2583template <class _CharT, class _Traits, class _Allocator>
2584basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002585basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002586{
Alp Tokerec34c482014-05-15 11:27:39 +00002587 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002588 return assign(__s, traits_type::length(__s));
2589}
2590
2591// append
2592
2593template <class _CharT, class _Traits, class _Allocator>
2594basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002595basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002596{
Alp Tokerec34c482014-05-15 11:27:39 +00002597 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002598 size_type __cap = capacity();
2599 size_type __sz = size();
2600 if (__cap - __sz >= __n)
2601 {
2602 if (__n)
2603 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002604 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002605 traits_type::copy(__p + __sz, __s, __n);
2606 __sz += __n;
2607 __set_size(__sz);
2608 traits_type::assign(__p[__sz], value_type());
2609 }
2610 }
2611 else
2612 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2613 return *this;
2614}
2615
2616template <class _CharT, class _Traits, class _Allocator>
2617basic_string<_CharT, _Traits, _Allocator>&
2618basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2619{
2620 if (__n)
2621 {
2622 size_type __cap = capacity();
2623 size_type __sz = size();
2624 if (__cap - __sz < __n)
2625 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2626 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002627 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002628 __sz += __n;
2629 __set_size(__sz);
2630 traits_type::assign(__p[__sz], value_type());
2631 }
2632 return *this;
2633}
2634
2635template <class _CharT, class _Traits, class _Allocator>
2636void
2637basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2638{
Howard Hinnant15467182013-04-30 21:44:48 +00002639 bool __is_short = !__is_long();
2640 size_type __cap;
2641 size_type __sz;
2642 if (__is_short)
2643 {
2644 __cap = __min_cap - 1;
2645 __sz = __get_short_size();
2646 }
2647 else
2648 {
2649 __cap = __get_long_cap() - 1;
2650 __sz = __get_long_size();
2651 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002652 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002653 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002654 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002655 __is_short = !__is_long();
2656 }
2657 pointer __p;
2658 if (__is_short)
2659 {
2660 __p = __get_short_pointer() + __sz;
2661 __set_short_size(__sz+1);
2662 }
2663 else
2664 {
2665 __p = __get_long_pointer() + __sz;
2666 __set_long_size(__sz+1);
2667 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002668 traits_type::assign(*__p, __c);
2669 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002670}
2671
2672template <class _CharT, class _Traits, class _Allocator>
2673template<class _InputIterator>
2674typename enable_if
2675<
Marshall Clowdf9db312016-01-13 21:54:34 +00002676 __is_exactly_input_iterator<_InputIterator>::value
2677 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002678 basic_string<_CharT, _Traits, _Allocator>&
2679>::type
2680basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
2681{
Marshall Clowdf9db312016-01-13 21:54:34 +00002682 basic_string __temp (__first, __last, __alloc());
2683 append(__temp.data(), __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002684 return *this;
2685}
2686
2687template <class _CharT, class _Traits, class _Allocator>
2688template<class _ForwardIterator>
2689typename enable_if
2690<
Marshall Clowdf9db312016-01-13 21:54:34 +00002691 __is_forward_iterator<_ForwardIterator>::value
2692 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002693 basic_string<_CharT, _Traits, _Allocator>&
2694>::type
2695basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
2696{
2697 size_type __sz = size();
2698 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002699 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002700 if (__n)
2701 {
2702 if (__cap - __sz < __n)
2703 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2704 pointer __p = __get_pointer() + __sz;
2705 for (; __first != __last; ++__p, ++__first)
2706 traits_type::assign(*__p, *__first);
2707 traits_type::assign(*__p, value_type());
2708 __set_size(__sz + __n);
2709 }
2710 return *this;
2711}
2712
2713template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002714inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002715basic_string<_CharT, _Traits, _Allocator>&
2716basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2717{
2718 return append(__str.data(), __str.size());
2719}
2720
2721template <class _CharT, class _Traits, class _Allocator>
2722basic_string<_CharT, _Traits, _Allocator>&
2723basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2724{
2725 size_type __sz = __str.size();
2726 if (__pos > __sz)
2727 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002728 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002729}
2730
2731template <class _CharT, class _Traits, class _Allocator>
2732basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002733basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002734{
Alp Tokerec34c482014-05-15 11:27:39 +00002735 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002736 return append(__s, traits_type::length(__s));
2737}
2738
2739// insert
2740
2741template <class _CharT, class _Traits, class _Allocator>
2742basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002743basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002744{
Alp Tokerec34c482014-05-15 11:27:39 +00002745 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002746 size_type __sz = size();
2747 if (__pos > __sz)
2748 this->__throw_out_of_range();
2749 size_type __cap = capacity();
2750 if (__cap - __sz >= __n)
2751 {
2752 if (__n)
2753 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002754 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002755 size_type __n_move = __sz - __pos;
2756 if (__n_move != 0)
2757 {
2758 if (__p + __pos <= __s && __s < __p + __sz)
2759 __s += __n;
2760 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2761 }
2762 traits_type::move(__p + __pos, __s, __n);
2763 __sz += __n;
2764 __set_size(__sz);
2765 traits_type::assign(__p[__sz], value_type());
2766 }
2767 }
2768 else
2769 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2770 return *this;
2771}
2772
2773template <class _CharT, class _Traits, class _Allocator>
2774basic_string<_CharT, _Traits, _Allocator>&
2775basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2776{
2777 size_type __sz = size();
2778 if (__pos > __sz)
2779 this->__throw_out_of_range();
2780 if (__n)
2781 {
2782 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002783 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002784 if (__cap - __sz >= __n)
2785 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002786 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002787 size_type __n_move = __sz - __pos;
2788 if (__n_move != 0)
2789 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2790 }
2791 else
2792 {
2793 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002794 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002795 }
2796 traits_type::assign(__p + __pos, __n, __c);
2797 __sz += __n;
2798 __set_size(__sz);
2799 traits_type::assign(__p[__sz], value_type());
2800 }
2801 return *this;
2802}
2803
2804template <class _CharT, class _Traits, class _Allocator>
2805template<class _InputIterator>
2806typename enable_if
2807<
Marshall Clowdf9db312016-01-13 21:54:34 +00002808 __is_exactly_input_iterator<_InputIterator>::value
2809 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2810 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002811>::type
2812basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2813{
Howard Hinnant499cea12013-08-23 17:37:05 +00002814#if _LIBCPP_DEBUG_LEVEL >= 2
2815 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2816 "string::insert(iterator, range) called with an iterator not"
2817 " referring to this string");
2818#endif
Marshall Clowdf9db312016-01-13 21:54:34 +00002819 basic_string __temp(__first, __last, __alloc());
2820 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002821}
2822
2823template <class _CharT, class _Traits, class _Allocator>
2824template<class _ForwardIterator>
2825typename enable_if
2826<
Marshall Clowdf9db312016-01-13 21:54:34 +00002827 __is_forward_iterator<_ForwardIterator>::value
2828 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002829 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2830>::type
2831basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2832{
Howard Hinnant499cea12013-08-23 17:37:05 +00002833#if _LIBCPP_DEBUG_LEVEL >= 2
2834 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2835 "string::insert(iterator, range) called with an iterator not"
2836 " referring to this string");
2837#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002838 size_type __ip = static_cast<size_type>(__pos - begin());
2839 size_type __sz = size();
2840 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002841 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002842 if (__n)
2843 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002844 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002845 if (__cap - __sz >= __n)
2846 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002847 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002848 size_type __n_move = __sz - __ip;
2849 if (__n_move != 0)
2850 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2851 }
2852 else
2853 {
2854 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002855 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002856 }
2857 __sz += __n;
2858 __set_size(__sz);
2859 traits_type::assign(__p[__sz], value_type());
2860 for (__p += __ip; __first != __last; ++__p, ++__first)
2861 traits_type::assign(*__p, *__first);
2862 }
2863 return begin() + __ip;
2864}
2865
2866template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002867inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002868basic_string<_CharT, _Traits, _Allocator>&
2869basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2870{
2871 return insert(__pos1, __str.data(), __str.size());
2872}
2873
2874template <class _CharT, class _Traits, class _Allocator>
2875basic_string<_CharT, _Traits, _Allocator>&
2876basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2877 size_type __pos2, size_type __n)
2878{
2879 size_type __str_sz = __str.size();
2880 if (__pos2 > __str_sz)
2881 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002882 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002883}
2884
2885template <class _CharT, class _Traits, class _Allocator>
2886basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002887basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002888{
Alp Tokerec34c482014-05-15 11:27:39 +00002889 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002890 return insert(__pos, __s, traits_type::length(__s));
2891}
2892
2893template <class _CharT, class _Traits, class _Allocator>
2894typename basic_string<_CharT, _Traits, _Allocator>::iterator
2895basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2896{
2897 size_type __ip = static_cast<size_type>(__pos - begin());
2898 size_type __sz = size();
2899 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002900 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002901 if (__cap == __sz)
2902 {
2903 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002904 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002905 }
2906 else
2907 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002908 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002909 size_type __n_move = __sz - __ip;
2910 if (__n_move != 0)
2911 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2912 }
2913 traits_type::assign(__p[__ip], __c);
2914 traits_type::assign(__p[++__sz], value_type());
2915 __set_size(__sz);
2916 return begin() + static_cast<difference_type>(__ip);
2917}
2918
2919template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002920inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002921typename basic_string<_CharT, _Traits, _Allocator>::iterator
2922basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2923{
Howard Hinnant499cea12013-08-23 17:37:05 +00002924#if _LIBCPP_DEBUG_LEVEL >= 2
2925 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2926 "string::insert(iterator, n, value) called with an iterator not"
2927 " referring to this string");
2928#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002929 difference_type __p = __pos - begin();
2930 insert(static_cast<size_type>(__p), __n, __c);
2931 return begin() + __p;
2932}
2933
2934// replace
2935
2936template <class _CharT, class _Traits, class _Allocator>
2937basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002938basic_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 +00002939{
Alp Tokerec34c482014-05-15 11:27:39 +00002940 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002941 size_type __sz = size();
2942 if (__pos > __sz)
2943 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002944 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002945 size_type __cap = capacity();
2946 if (__cap - __sz + __n1 >= __n2)
2947 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002948 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002949 if (__n1 != __n2)
2950 {
2951 size_type __n_move = __sz - __pos - __n1;
2952 if (__n_move != 0)
2953 {
2954 if (__n1 > __n2)
2955 {
2956 traits_type::move(__p + __pos, __s, __n2);
2957 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2958 goto __finish;
2959 }
2960 if (__p + __pos < __s && __s < __p + __sz)
2961 {
2962 if (__p + __pos + __n1 <= __s)
2963 __s += __n2 - __n1;
2964 else // __p + __pos < __s < __p + __pos + __n1
2965 {
2966 traits_type::move(__p + __pos, __s, __n1);
2967 __pos += __n1;
2968 __s += __n2;
2969 __n2 -= __n1;
2970 __n1 = 0;
2971 }
2972 }
2973 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2974 }
2975 }
2976 traits_type::move(__p + __pos, __s, __n2);
2977__finish:
2978 __sz += __n2 - __n1;
2979 __set_size(__sz);
2980 __invalidate_iterators_past(__sz);
2981 traits_type::assign(__p[__sz], value_type());
2982 }
2983 else
2984 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2985 return *this;
2986}
2987
2988template <class _CharT, class _Traits, class _Allocator>
2989basic_string<_CharT, _Traits, _Allocator>&
2990basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
2991{
2992 size_type __sz = size();
2993 if (__pos > __sz)
2994 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002995 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002996 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002997 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002998 if (__cap - __sz + __n1 >= __n2)
2999 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003000 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003001 if (__n1 != __n2)
3002 {
3003 size_type __n_move = __sz - __pos - __n1;
3004 if (__n_move != 0)
3005 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
3006 }
3007 }
3008 else
3009 {
3010 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003011 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003012 }
3013 traits_type::assign(__p + __pos, __n2, __c);
3014 __sz += __n2 - __n1;
3015 __set_size(__sz);
3016 __invalidate_iterators_past(__sz);
3017 traits_type::assign(__p[__sz], value_type());
3018 return *this;
3019}
3020
3021template <class _CharT, class _Traits, class _Allocator>
3022template<class _InputIterator>
3023typename enable_if
3024<
3025 __is_input_iterator<_InputIterator>::value,
3026 basic_string<_CharT, _Traits, _Allocator>&
3027>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00003028basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003029 _InputIterator __j1, _InputIterator __j2)
3030{
Marshall Clowdf9db312016-01-13 21:54:34 +00003031 basic_string __temp(__j1, __j2, __alloc());
3032 return this->replace(__i1, __i2, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003033}
3034
3035template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003036inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003037basic_string<_CharT, _Traits, _Allocator>&
3038basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
3039{
3040 return replace(__pos1, __n1, __str.data(), __str.size());
3041}
3042
3043template <class _CharT, class _Traits, class _Allocator>
3044basic_string<_CharT, _Traits, _Allocator>&
3045basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
3046 size_type __pos2, size_type __n2)
3047{
3048 size_type __str_sz = __str.size();
3049 if (__pos2 > __str_sz)
3050 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003051 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003052}
3053
3054template <class _CharT, class _Traits, class _Allocator>
3055basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003056basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003057{
Alp Tokerec34c482014-05-15 11:27:39 +00003058 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003059 return replace(__pos, __n1, __s, traits_type::length(__s));
3060}
3061
3062template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003063inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003064basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00003065basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003066{
3067 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
3068 __str.data(), __str.size());
3069}
3070
3071template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003072inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003073basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003074basic_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 +00003075{
3076 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
3077}
3078
3079template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003080inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003081basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003082basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003083{
3084 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
3085}
3086
3087template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003088inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003089basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00003090basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003091{
3092 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
3093}
3094
3095// erase
3096
3097template <class _CharT, class _Traits, class _Allocator>
3098basic_string<_CharT, _Traits, _Allocator>&
3099basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
3100{
3101 size_type __sz = size();
3102 if (__pos > __sz)
3103 this->__throw_out_of_range();
3104 if (__n)
3105 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003106 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00003107 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003108 size_type __n_move = __sz - __pos - __n;
3109 if (__n_move != 0)
3110 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
3111 __sz -= __n;
3112 __set_size(__sz);
3113 __invalidate_iterators_past(__sz);
3114 traits_type::assign(__p[__sz], value_type());
3115 }
3116 return *this;
3117}
3118
3119template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003120inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003121typename basic_string<_CharT, _Traits, _Allocator>::iterator
3122basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
3123{
Howard Hinnant499cea12013-08-23 17:37:05 +00003124#if _LIBCPP_DEBUG_LEVEL >= 2
3125 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
3126 "string::erase(iterator) called with an iterator not"
3127 " referring to this string");
3128#endif
3129 _LIBCPP_ASSERT(__pos != end(),
3130 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003131 iterator __b = begin();
3132 size_type __r = static_cast<size_type>(__pos - __b);
3133 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00003134 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003135}
3136
3137template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003138inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003139typename basic_string<_CharT, _Traits, _Allocator>::iterator
3140basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
3141{
Howard Hinnant499cea12013-08-23 17:37:05 +00003142#if _LIBCPP_DEBUG_LEVEL >= 2
3143 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
3144 "string::erase(iterator, iterator) called with an iterator not"
3145 " referring to this string");
3146#endif
3147 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003148 iterator __b = begin();
3149 size_type __r = static_cast<size_type>(__first - __b);
3150 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00003151 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003152}
3153
3154template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003155inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003156void
3157basic_string<_CharT, _Traits, _Allocator>::pop_back()
3158{
Howard Hinnant499cea12013-08-23 17:37:05 +00003159 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003160 size_type __sz;
3161 if (__is_long())
3162 {
3163 __sz = __get_long_size() - 1;
3164 __set_long_size(__sz);
3165 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3166 }
3167 else
3168 {
3169 __sz = __get_short_size() - 1;
3170 __set_short_size(__sz);
3171 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3172 }
3173 __invalidate_iterators_past(__sz);
3174}
3175
3176template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003177inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003178void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003179basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003180{
3181 __invalidate_all_iterators();
3182 if (__is_long())
3183 {
3184 traits_type::assign(*__get_long_pointer(), value_type());
3185 __set_long_size(0);
3186 }
3187 else
3188 {
3189 traits_type::assign(*__get_short_pointer(), value_type());
3190 __set_short_size(0);
3191 }
3192}
3193
3194template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003195inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003196void
3197basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3198{
3199 if (__is_long())
3200 {
3201 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3202 __set_long_size(__pos);
3203 }
3204 else
3205 {
3206 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3207 __set_short_size(__pos);
3208 }
3209 __invalidate_iterators_past(__pos);
3210}
3211
3212template <class _CharT, class _Traits, class _Allocator>
3213void
3214basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3215{
3216 size_type __sz = size();
3217 if (__n > __sz)
3218 append(__n - __sz, __c);
3219 else
3220 __erase_to_end(__n);
3221}
3222
3223template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003224inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003225typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003226basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003227{
Howard Hinnante32b5e22010-11-17 17:55:08 +00003228 size_type __m = __alloc_traits::max_size(__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003229#if _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:08 +00003230 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003231#else
Marshall Clow09f85502013-10-31 17:23:08 +00003232 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003233#endif
3234}
3235
3236template <class _CharT, class _Traits, class _Allocator>
3237void
3238basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
3239{
3240 if (__res_arg > max_size())
3241 this->__throw_length_error();
3242 size_type __cap = capacity();
3243 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003244 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003245 __res_arg = __recommend(__res_arg);
3246 if (__res_arg != __cap)
3247 {
3248 pointer __new_data, __p;
3249 bool __was_long, __now_long;
3250 if (__res_arg == __min_cap - 1)
3251 {
3252 __was_long = true;
3253 __now_long = false;
3254 __new_data = __get_short_pointer();
3255 __p = __get_long_pointer();
3256 }
3257 else
3258 {
3259 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003260 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003261 else
3262 {
3263 #ifndef _LIBCPP_NO_EXCEPTIONS
3264 try
3265 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003266 #endif // _LIBCPP_NO_EXCEPTIONS
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 #ifndef _LIBCPP_NO_EXCEPTIONS
3269 }
3270 catch (...)
3271 {
3272 return;
3273 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003274 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003275 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003276 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00003277 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003278 }
3279 __now_long = true;
3280 __was_long = __is_long();
3281 __p = __get_pointer();
3282 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003283 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
3284 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003285 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003286 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003287 if (__now_long)
3288 {
3289 __set_long_cap(__res_arg+1);
3290 __set_long_size(__sz);
3291 __set_long_pointer(__new_data);
3292 }
3293 else
3294 __set_short_size(__sz);
3295 __invalidate_all_iterators();
3296 }
3297}
3298
3299template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003300inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003301typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3302basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const
3303{
Howard Hinnant499cea12013-08-23 17:37:05 +00003304 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003305 return *(data() + __pos);
3306}
3307
3308template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003309inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003310typename basic_string<_CharT, _Traits, _Allocator>::reference
3311basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos)
3312{
Howard Hinnant499cea12013-08-23 17:37:05 +00003313 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003314 return *(__get_pointer() + __pos);
3315}
3316
3317template <class _CharT, class _Traits, class _Allocator>
3318typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3319basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3320{
3321 if (__n >= size())
3322 this->__throw_out_of_range();
3323 return (*this)[__n];
3324}
3325
3326template <class _CharT, class _Traits, class _Allocator>
3327typename basic_string<_CharT, _Traits, _Allocator>::reference
3328basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3329{
3330 if (__n >= size())
3331 this->__throw_out_of_range();
3332 return (*this)[__n];
3333}
3334
3335template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003336inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003337typename basic_string<_CharT, _Traits, _Allocator>::reference
3338basic_string<_CharT, _Traits, _Allocator>::front()
3339{
Howard Hinnant499cea12013-08-23 17:37:05 +00003340 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003341 return *__get_pointer();
3342}
3343
3344template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003345inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003346typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3347basic_string<_CharT, _Traits, _Allocator>::front() const
3348{
Howard Hinnant499cea12013-08-23 17:37:05 +00003349 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003350 return *data();
3351}
3352
3353template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003354inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003355typename basic_string<_CharT, _Traits, _Allocator>::reference
3356basic_string<_CharT, _Traits, _Allocator>::back()
3357{
Howard Hinnant499cea12013-08-23 17:37:05 +00003358 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003359 return *(__get_pointer() + size() - 1);
3360}
3361
3362template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003363inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003364typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3365basic_string<_CharT, _Traits, _Allocator>::back() const
3366{
Howard Hinnant499cea12013-08-23 17:37:05 +00003367 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003368 return *(data() + size() - 1);
3369}
3370
3371template <class _CharT, class _Traits, class _Allocator>
3372typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003373basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003374{
3375 size_type __sz = size();
3376 if (__pos > __sz)
3377 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003378 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003379 traits_type::copy(__s, data() + __pos, __rlen);
3380 return __rlen;
3381}
3382
3383template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003384inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003385basic_string<_CharT, _Traits, _Allocator>
3386basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3387{
3388 return basic_string(*this, __pos, __n, __alloc());
3389}
3390
3391template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003392inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003393void
3394basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00003395#if _LIBCPP_STD_VER >= 14
3396 _NOEXCEPT
3397#else
3398 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3399 __is_nothrow_swappable<allocator_type>::value)
3400#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003401{
Howard Hinnant499cea12013-08-23 17:37:05 +00003402#if _LIBCPP_DEBUG_LEVEL >= 2
3403 if (!__is_long())
3404 __get_db()->__invalidate_all(this);
3405 if (!__str.__is_long())
3406 __get_db()->__invalidate_all(&__str);
3407 __get_db()->swap(this, &__str);
3408#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00003409 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow7d914d12015-07-13 20:04:56 +00003410 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003411}
3412
3413// find
3414
3415template <class _Traits>
3416struct _LIBCPP_HIDDEN __traits_eq
3417{
3418 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003419 _LIBCPP_INLINE_VISIBILITY
3420 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3421 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003422};
3423
3424template<class _CharT, class _Traits, class _Allocator>
3425typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003426basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003427 size_type __pos,
3428 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003429{
Alp Tokerec34c482014-05-15 11:27:39 +00003430 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003431 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003432 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003433}
3434
3435template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003436inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003437typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003438basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3439 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003440{
Marshall Clow37025e12014-06-10 18:51:55 +00003441 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003442 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003443}
3444
3445template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003446inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003447typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003448basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003449 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003450{
Alp Tokerec34c482014-05-15 11:27:39 +00003451 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003452 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003453 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003454}
3455
3456template<class _CharT, class _Traits, class _Allocator>
3457typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003458basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3459 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003460{
Marshall Clow37025e12014-06-10 18:51:55 +00003461 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003462 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003463}
3464
3465// rfind
3466
3467template<class _CharT, class _Traits, class _Allocator>
3468typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003469basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003470 size_type __pos,
3471 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003472{
Alp Tokerec34c482014-05-15 11:27:39 +00003473 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003474 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003475 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003476}
3477
3478template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003479inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003480typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003481basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3482 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003483{
Marshall Clow37025e12014-06-10 18:51:55 +00003484 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003485 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003486}
3487
3488template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003489inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003490typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003491basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003492 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003493{
Alp Tokerec34c482014-05-15 11:27:39 +00003494 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003495 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003496 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003497}
3498
3499template<class _CharT, class _Traits, class _Allocator>
3500typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003501basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3502 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003503{
Marshall Clow37025e12014-06-10 18:51:55 +00003504 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003505 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003506}
3507
3508// find_first_of
3509
3510template<class _CharT, class _Traits, class _Allocator>
3511typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003512basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003513 size_type __pos,
3514 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003515{
Alp Tokerec34c482014-05-15 11:27:39 +00003516 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003517 return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003518 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003519}
3520
3521template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003522inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003523typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003524basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3525 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003526{
Marshall Clow37025e12014-06-10 18:51:55 +00003527 return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003528 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003529}
3530
3531template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003532inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003533typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003534basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003535 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003536{
Alp Tokerec34c482014-05-15 11:27:39 +00003537 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003538 return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003539 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003540}
3541
3542template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003543inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003544typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003545basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3546 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003547{
3548 return find(__c, __pos);
3549}
3550
3551// find_last_of
3552
3553template<class _CharT, class _Traits, class _Allocator>
3554typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003555basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003556 size_type __pos,
3557 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003558{
Alp Tokerec34c482014-05-15 11:27:39 +00003559 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003560 return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003561 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003562}
3563
3564template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003565inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003566typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003567basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3568 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003569{
Marshall Clow37025e12014-06-10 18:51:55 +00003570 return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003571 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003572}
3573
3574template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003575inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003576typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003577basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003578 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003579{
Alp Tokerec34c482014-05-15 11:27:39 +00003580 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003581 return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003582 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003583}
3584
3585template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003586inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003587typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003588basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3589 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003590{
3591 return rfind(__c, __pos);
3592}
3593
3594// find_first_not_of
3595
3596template<class _CharT, class _Traits, class _Allocator>
3597typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003598basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003599 size_type __pos,
3600 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003601{
Alp Tokerec34c482014-05-15 11:27:39 +00003602 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003603 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003604 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003605}
3606
3607template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003608inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003609typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003610basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3611 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003612{
Marshall Clow37025e12014-06-10 18:51:55 +00003613 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003614 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003615}
3616
3617template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003618inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003619typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003620basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003621 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003622{
Alp Tokerec34c482014-05-15 11:27:39 +00003623 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003624 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003625 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003626}
3627
3628template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003629inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003630typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003631basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3632 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003633{
Marshall Clow37025e12014-06-10 18:51:55 +00003634 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003635 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003636}
3637
3638// find_last_not_of
3639
3640template<class _CharT, class _Traits, class _Allocator>
3641typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003642basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003643 size_type __pos,
3644 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003645{
Alp Tokerec34c482014-05-15 11:27:39 +00003646 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003647 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003648 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003649}
3650
3651template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003652inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003653typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003654basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3655 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003656{
Marshall Clow37025e12014-06-10 18:51:55 +00003657 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003658 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003659}
3660
3661template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003662inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003663typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003664basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003665 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003666{
Alp Tokerec34c482014-05-15 11:27:39 +00003667 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003668 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003669 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003670}
3671
3672template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003673inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003674typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003675basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3676 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003677{
Marshall Clow37025e12014-06-10 18:51:55 +00003678 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003679 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003680}
3681
3682// compare
3683
3684template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003685inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003686int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003687basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003688{
Howard Hinnantfa06d752011-07-24 21:45:06 +00003689 size_t __lhs_sz = size();
3690 size_t __rhs_sz = __str.size();
3691 int __result = traits_type::compare(data(), __str.data(),
3692 _VSTD::min(__lhs_sz, __rhs_sz));
3693 if (__result != 0)
3694 return __result;
3695 if (__lhs_sz < __rhs_sz)
3696 return -1;
3697 if (__lhs_sz > __rhs_sz)
3698 return 1;
3699 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003700}
3701
3702template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003703inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003704int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003705basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3706 size_type __n1,
3707 const basic_string& __str) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003708{
3709 return compare(__pos1, __n1, __str.data(), __str.size());
3710}
3711
3712template <class _CharT, class _Traits, class _Allocator>
3713int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003714basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3715 size_type __n1,
3716 const basic_string& __str,
3717 size_type __pos2,
3718 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003719{
3720 size_type __sz = __str.size();
3721 if (__pos2 > __sz)
3722 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003723 return compare(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003724 __sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003725}
3726
3727template <class _CharT, class _Traits, class _Allocator>
3728int
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003729basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003730{
Alp Tokerec34c482014-05-15 11:27:39 +00003731 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003732 return compare(0, npos, __s, traits_type::length(__s));
3733}
3734
3735template <class _CharT, class _Traits, class _Allocator>
3736int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003737basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3738 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003739 const value_type* __s) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003740{
Alp Tokerec34c482014-05-15 11:27:39 +00003741 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003742 return compare(__pos1, __n1, __s, traits_type::length(__s));
3743}
3744
3745template <class _CharT, class _Traits, class _Allocator>
3746int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003747basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3748 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003749 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003750 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003751{
Alp Tokerec34c482014-05-15 11:27:39 +00003752 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003753 size_type __sz = size();
3754 if (__pos1 > __sz || __n2 == npos)
3755 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003756 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3757 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003758 if (__r == 0)
3759 {
3760 if (__rlen < __n2)
3761 __r = -1;
3762 else if (__rlen > __n2)
3763 __r = 1;
3764 }
3765 return __r;
3766}
3767
3768// __invariants
3769
3770template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003771inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003772bool
3773basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3774{
3775 if (size() > capacity())
3776 return false;
3777 if (capacity() < __min_cap - 1)
3778 return false;
3779 if (data() == 0)
3780 return false;
3781 if (data()[size()] != value_type(0))
3782 return false;
3783 return true;
3784}
3785
3786// operator==
3787
3788template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003789inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003790bool
3791operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003792 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003793{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003794 size_t __lhs_sz = __lhs.size();
3795 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3796 __rhs.data(),
3797 __lhs_sz) == 0;
3798}
3799
3800template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003801inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:13 +00003802bool
3803operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3804 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3805{
3806 size_t __lhs_sz = __lhs.size();
3807 if (__lhs_sz != __rhs.size())
3808 return false;
3809 const char* __lp = __lhs.data();
3810 const char* __rp = __rhs.data();
3811 if (__lhs.__is_long())
3812 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3813 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3814 if (*__lp != *__rp)
3815 return false;
3816 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003817}
3818
3819template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003820inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003821bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003822operator==(const _CharT* __lhs,
3823 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003824{
Eric Fiselier4f241822015-08-28 03:02:37 +00003825 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3826 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3827 size_t __lhs_len = _Traits::length(__lhs);
3828 if (__lhs_len != __rhs.size()) return false;
3829 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003830}
3831
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003832template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003833inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003834bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003835operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3836 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003837{
Eric Fiselier4f241822015-08-28 03:02:37 +00003838 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3839 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3840 size_t __rhs_len = _Traits::length(__rhs);
3841 if (__rhs_len != __lhs.size()) return false;
3842 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003843}
3844
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003845// operator!=
3846
Howard Hinnant324bb032010-08-22 00:02:43 +00003847template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003848inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003849bool
3850operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003851 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003852{
3853 return !(__lhs == __rhs);
3854}
3855
3856template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003857inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003858bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003859operator!=(const _CharT* __lhs,
3860 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003861{
3862 return !(__lhs == __rhs);
3863}
3864
3865template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003866inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003867bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003868operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3869 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003870{
3871 return !(__lhs == __rhs);
3872}
3873
3874// operator<
3875
3876template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003877inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003878bool
3879operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003880 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003881{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003882 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003883}
3884
3885template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003886inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003887bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003888operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3889 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003890{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003891 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003892}
3893
3894template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003895inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003896bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003897operator< (const _CharT* __lhs,
3898 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003899{
3900 return __rhs.compare(__lhs) > 0;
3901}
3902
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003903// operator>
3904
3905template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003906inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003907bool
3908operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003909 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003910{
3911 return __rhs < __lhs;
3912}
3913
3914template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003915inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003916bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003917operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3918 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003919{
3920 return __rhs < __lhs;
3921}
3922
3923template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003924inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003925bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003926operator> (const _CharT* __lhs,
3927 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003928{
3929 return __rhs < __lhs;
3930}
3931
3932// operator<=
3933
3934template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003935inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003936bool
3937operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003938 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003939{
3940 return !(__rhs < __lhs);
3941}
3942
3943template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003944inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003945bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003946operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3947 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003948{
3949 return !(__rhs < __lhs);
3950}
3951
3952template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003953inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003954bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003955operator<=(const _CharT* __lhs,
3956 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003957{
3958 return !(__rhs < __lhs);
3959}
3960
3961// operator>=
3962
3963template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003964inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003965bool
3966operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003967 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003968{
3969 return !(__lhs < __rhs);
3970}
3971
3972template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003973inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003974bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003975operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3976 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003977{
3978 return !(__lhs < __rhs);
3979}
3980
3981template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003982inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003983bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003984operator>=(const _CharT* __lhs,
3985 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003986{
3987 return !(__lhs < __rhs);
3988}
3989
3990// operator +
3991
3992template<class _CharT, class _Traits, class _Allocator>
3993basic_string<_CharT, _Traits, _Allocator>
3994operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3995 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3996{
3997 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3998 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3999 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4000 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4001 __r.append(__rhs.data(), __rhs_sz);
4002 return __r;
4003}
4004
4005template<class _CharT, class _Traits, class _Allocator>
4006basic_string<_CharT, _Traits, _Allocator>
4007operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4008{
4009 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4010 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
4011 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4012 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
4013 __r.append(__rhs.data(), __rhs_sz);
4014 return __r;
4015}
4016
4017template<class _CharT, class _Traits, class _Allocator>
4018basic_string<_CharT, _Traits, _Allocator>
4019operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4020{
4021 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4022 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4023 __r.__init(&__lhs, 1, 1 + __rhs_sz);
4024 __r.append(__rhs.data(), __rhs_sz);
4025 return __r;
4026}
4027
4028template<class _CharT, class _Traits, class _Allocator>
4029basic_string<_CharT, _Traits, _Allocator>
4030operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
4031{
4032 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4033 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4034 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
4035 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4036 __r.append(__rhs, __rhs_sz);
4037 return __r;
4038}
4039
4040template<class _CharT, class _Traits, class _Allocator>
4041basic_string<_CharT, _Traits, _Allocator>
4042operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
4043{
4044 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4045 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4046 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
4047 __r.push_back(__rhs);
4048 return __r;
4049}
4050
Howard Hinnant73d21a42010-09-04 23:28:19 +00004051#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004052
4053template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004054inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004055basic_string<_CharT, _Traits, _Allocator>
4056operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4057{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004058 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004059}
4060
4061template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004062inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004063basic_string<_CharT, _Traits, _Allocator>
4064operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4065{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004066 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004067}
4068
4069template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004070inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004071basic_string<_CharT, _Traits, _Allocator>
4072operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4073{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004074 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004075}
4076
4077template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004078inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004079basic_string<_CharT, _Traits, _Allocator>
4080operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4081{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004082 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004083}
4084
4085template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004086inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004087basic_string<_CharT, _Traits, _Allocator>
4088operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4089{
4090 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004091 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004092}
4093
4094template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004095inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004096basic_string<_CharT, _Traits, _Allocator>
4097operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
4098{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004099 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004100}
4101
4102template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004103inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004104basic_string<_CharT, _Traits, _Allocator>
4105operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
4106{
4107 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004108 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004109}
4110
Howard Hinnant73d21a42010-09-04 23:28:19 +00004111#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004112
4113// swap
4114
4115template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004116inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004117void
Howard Hinnanta6119a82011-05-29 19:57:12 +00004118swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00004119 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4120 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004121{
4122 __lhs.swap(__rhs);
4123}
4124
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004125#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
4126
4127typedef basic_string<char16_t> u16string;
4128typedef basic_string<char32_t> u32string;
4129
Howard Hinnant324bb032010-08-22 00:02:43 +00004130#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004131
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004132_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4133_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4134_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4135_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4136_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004137
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004138_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
4139_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
4140_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004141
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004142_LIBCPP_FUNC_VIS string to_string(int __val);
4143_LIBCPP_FUNC_VIS string to_string(unsigned __val);
4144_LIBCPP_FUNC_VIS string to_string(long __val);
4145_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4146_LIBCPP_FUNC_VIS string to_string(long long __val);
4147_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4148_LIBCPP_FUNC_VIS string to_string(float __val);
4149_LIBCPP_FUNC_VIS string to_string(double __val);
4150_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004151
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004152_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4153_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4154_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4155_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4156_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004157
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004158_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
4159_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
4160_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004161
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004162_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4163_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4164_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4165_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4166_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4167_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4168_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4169_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4170_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004171
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004172template<class _CharT, class _Traits, class _Allocator>
4173 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4174 basic_string<_CharT, _Traits, _Allocator>::npos;
4175
4176template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004177struct _LIBCPP_TYPE_VIS_ONLY hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004178 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
4179{
4180 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00004181 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004182};
4183
4184template<class _CharT, class _Traits, class _Allocator>
4185size_t
4186hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00004187 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004188{
Sean Huntaffd9e52011-07-29 23:31:56 +00004189 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004190}
4191
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004192template<class _CharT, class _Traits, class _Allocator>
4193basic_ostream<_CharT, _Traits>&
4194operator<<(basic_ostream<_CharT, _Traits>& __os,
4195 const basic_string<_CharT, _Traits, _Allocator>& __str);
4196
4197template<class _CharT, class _Traits, class _Allocator>
4198basic_istream<_CharT, _Traits>&
4199operator>>(basic_istream<_CharT, _Traits>& __is,
4200 basic_string<_CharT, _Traits, _Allocator>& __str);
4201
4202template<class _CharT, class _Traits, class _Allocator>
4203basic_istream<_CharT, _Traits>&
4204getline(basic_istream<_CharT, _Traits>& __is,
4205 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4206
4207template<class _CharT, class _Traits, class _Allocator>
4208inline _LIBCPP_INLINE_VISIBILITY
4209basic_istream<_CharT, _Traits>&
4210getline(basic_istream<_CharT, _Traits>& __is,
4211 basic_string<_CharT, _Traits, _Allocator>& __str);
4212
4213#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4214
4215template<class _CharT, class _Traits, class _Allocator>
4216inline _LIBCPP_INLINE_VISIBILITY
4217basic_istream<_CharT, _Traits>&
4218getline(basic_istream<_CharT, _Traits>&& __is,
4219 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4220
4221template<class _CharT, class _Traits, class _Allocator>
4222inline _LIBCPP_INLINE_VISIBILITY
4223basic_istream<_CharT, _Traits>&
4224getline(basic_istream<_CharT, _Traits>&& __is,
4225 basic_string<_CharT, _Traits, _Allocator>& __str);
4226
4227#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4228
Howard Hinnant499cea12013-08-23 17:37:05 +00004229#if _LIBCPP_DEBUG_LEVEL >= 2
4230
4231template<class _CharT, class _Traits, class _Allocator>
4232bool
4233basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4234{
4235 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
4236 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
4237}
4238
4239template<class _CharT, class _Traits, class _Allocator>
4240bool
4241basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4242{
4243 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
4244 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
4245}
4246
4247template<class _CharT, class _Traits, class _Allocator>
4248bool
4249basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4250{
4251 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4252 return this->data() <= __p && __p <= this->data() + this->size();
4253}
4254
4255template<class _CharT, class _Traits, class _Allocator>
4256bool
4257basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4258{
4259 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4260 return this->data() <= __p && __p < this->data() + this->size();
4261}
4262
4263#endif // _LIBCPP_DEBUG_LEVEL >= 2
4264
Marshall Clow15234322013-07-23 17:05:24 +00004265#if _LIBCPP_STD_VER > 11
4266// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:32 +00004267inline namespace literals
Marshall Clow15234322013-07-23 17:05:24 +00004268{
4269 inline namespace string_literals
4270 {
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004271 inline _LIBCPP_INLINE_VISIBILITY
4272 basic_string<char> operator "" s( const char *__str, size_t __len )
4273 {
4274 return basic_string<char> (__str, __len);
4275 }
Marshall Clow15234322013-07-23 17:05:24 +00004276
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004277 inline _LIBCPP_INLINE_VISIBILITY
4278 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4279 {
4280 return basic_string<wchar_t> (__str, __len);
4281 }
Marshall Clow15234322013-07-23 17:05:24 +00004282
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004283 inline _LIBCPP_INLINE_VISIBILITY
4284 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4285 {
4286 return basic_string<char16_t> (__str, __len);
4287 }
Marshall Clow15234322013-07-23 17:05:24 +00004288
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004289 inline _LIBCPP_INLINE_VISIBILITY
4290 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4291 {
4292 return basic_string<char32_t> (__str, __len);
4293 }
Marshall Clow15234322013-07-23 17:05:24 +00004294 }
4295}
4296#endif
4297
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004298_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<char>)
4299_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<wchar_t>)
Howard Hinnant499cea12013-08-23 17:37:05 +00004300_LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004301
4302_LIBCPP_END_NAMESPACE_STD
4303
4304#endif // _LIBCPP_STRING