blob: 91502441e0c0ddfb47787182ca4f28efe30064e5 [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;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000228
Howard Hinnanta6119a82011-05-29 19:57:12 +0000229 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000230
Howard Hinnanta6119a82011-05-29 19:57:12 +0000231 size_type find(const basic_string& str, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000232 size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
233 size_type find(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000234 size_type find(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000235
Howard Hinnanta6119a82011-05-29 19:57:12 +0000236 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000237 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
238 size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000239 size_type rfind(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000240
Howard Hinnanta6119a82011-05-29 19:57:12 +0000241 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000242 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
243 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000244 size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000245
Howard Hinnanta6119a82011-05-29 19:57:12 +0000246 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000247 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
248 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000249 size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000250
Howard Hinnanta6119a82011-05-29 19:57:12 +0000251 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000252 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
253 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000254 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000255
Howard Hinnanta6119a82011-05-29 19:57:12 +0000256 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000257 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
258 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000259 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000260
Howard Hinnanta6119a82011-05-29 19:57:12 +0000261 int compare(const basic_string& str) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000262 int compare(size_type pos1, size_type n1, const basic_string& str) const;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000263 int compare(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000264 size_type pos2, size_type n2=npos) const; // C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000265 int compare(const value_type* s) const noexcept;
266 int compare(size_type pos1, size_type n1, const value_type* s) const;
267 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000268
269 bool __invariants() const;
270};
271
272template<class charT, class traits, class Allocator>
273basic_string<charT, traits, Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000274operator+(const basic_string<charT, traits, Allocator>& lhs,
275 const basic_string<charT, traits, Allocator>& rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000276
277template<class charT, class traits, class Allocator>
278basic_string<charT, traits, Allocator>
279operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
280
281template<class charT, class traits, class Allocator>
282basic_string<charT, traits, Allocator>
283operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
284
285template<class charT, class traits, class Allocator>
286basic_string<charT, traits, Allocator>
287operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
288
289template<class charT, class traits, class Allocator>
290basic_string<charT, traits, Allocator>
291operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
292
293template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000294bool operator==(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000295 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000296
297template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000298bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000299
300template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000301bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000302
Howard Hinnant324bb032010-08-22 00:02:43 +0000303template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000304bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000305 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000306
307template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000308bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000309
310template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000311bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000312
313template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000314bool operator< (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000315 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000316
317template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000318bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000319
320template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000321bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000322
323template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000324bool operator> (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000325 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000326
327template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000328bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000329
330template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000331bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000332
333template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000334bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000335 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000336
337template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000338bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000339
340template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000341bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000342
343template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000344bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000345 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000346
347template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000348bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000349
350template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000351bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000352
353template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000354void swap(basic_string<charT, traits, Allocator>& lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000355 basic_string<charT, traits, Allocator>& rhs)
356 noexcept(noexcept(lhs.swap(rhs)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000357
358template<class charT, class traits, class Allocator>
359basic_istream<charT, traits>&
360operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
361
362template<class charT, class traits, class Allocator>
363basic_ostream<charT, traits>&
364operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
365
366template<class charT, class traits, class Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +0000367basic_istream<charT, traits>&
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000368getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
369 charT delim);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000370
371template<class charT, class traits, class Allocator>
372basic_istream<charT, traits>&
373getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
374
375typedef basic_string<char> string;
376typedef basic_string<wchar_t> wstring;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000377typedef basic_string<char16_t> u16string;
378typedef basic_string<char32_t> u32string;
379
380int stoi (const string& str, size_t* idx = 0, int base = 10);
381long stol (const string& str, size_t* idx = 0, int base = 10);
382unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
383long long stoll (const string& str, size_t* idx = 0, int base = 10);
384unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
385
386float stof (const string& str, size_t* idx = 0);
387double stod (const string& str, size_t* idx = 0);
388long double stold(const string& str, size_t* idx = 0);
389
390string to_string(int val);
391string to_string(unsigned val);
392string to_string(long val);
393string to_string(unsigned long val);
394string to_string(long long val);
395string to_string(unsigned long long val);
396string to_string(float val);
397string to_string(double val);
398string to_string(long double val);
399
400int stoi (const wstring& str, size_t* idx = 0, int base = 10);
401long stol (const wstring& str, size_t* idx = 0, int base = 10);
402unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
403long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
404unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
405
406float stof (const wstring& str, size_t* idx = 0);
407double stod (const wstring& str, size_t* idx = 0);
408long double stold(const wstring& str, size_t* idx = 0);
409
410wstring to_wstring(int val);
411wstring to_wstring(unsigned val);
412wstring to_wstring(long val);
413wstring to_wstring(unsigned long val);
414wstring to_wstring(long long val);
415wstring to_wstring(unsigned long long val);
416wstring to_wstring(float val);
417wstring to_wstring(double val);
418wstring to_wstring(long double val);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000419
420template <> struct hash<string>;
421template <> struct hash<u16string>;
422template <> struct hash<u32string>;
423template <> struct hash<wstring>;
424
Marshall Clow15234322013-07-23 17:05:24 +0000425basic_string<char> operator "" s( const char *str, size_t len ); // C++14
426basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
427basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
428basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
429
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000430} // std
431
432*/
433
434#include <__config>
435#include <iosfwd>
436#include <cstring>
Howard Hinnantadff4892010-05-24 17:49:41 +0000437#include <cstdio> // For EOF.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000438#include <cwchar>
439#include <algorithm>
440#include <iterator>
441#include <utility>
442#include <memory>
443#include <stdexcept>
444#include <type_traits>
445#include <initializer_list>
446#include <__functional_base>
447#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
448#include <cstdint>
449#endif
Howard Hinnant499cea12013-08-23 17:37:05 +0000450#if defined(_LIBCPP_NO_EXCEPTIONS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000451#include <cassert>
452#endif
453
Howard Hinnant66c6f972011-11-29 16:45:27 +0000454#include <__undef_min_max>
455
Eric Fiselierb9536102014-08-10 23:53:08 +0000456#include <__debug>
457
Howard Hinnant08e17472011-10-17 20:05:10 +0000458#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000459#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000460#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000461
462_LIBCPP_BEGIN_NAMESPACE_STD
463
464// fpos
465
466template <class _StateT>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000467class _LIBCPP_TYPE_VIS_ONLY fpos
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000468{
469private:
470 _StateT __st_;
471 streamoff __off_;
472public:
473 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
474
475 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
476
477 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
478 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
479
480 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
481 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
482 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
483 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
484};
485
486template <class _StateT>
487inline _LIBCPP_INLINE_VISIBILITY
488streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
489 {return streamoff(__x) - streamoff(__y);}
490
491template <class _StateT>
492inline _LIBCPP_INLINE_VISIBILITY
493bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
494 {return streamoff(__x) == streamoff(__y);}
495
496template <class _StateT>
497inline _LIBCPP_INLINE_VISIBILITY
498bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
499 {return streamoff(__x) != streamoff(__y);}
500
501// char_traits
502
503template <class _CharT>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000504struct _LIBCPP_TYPE_VIS_ONLY char_traits
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000505{
506 typedef _CharT char_type;
507 typedef int int_type;
508 typedef streamoff off_type;
509 typedef streampos pos_type;
510 typedef mbstate_t state_type;
511
Dan Albert6d9505a2014-09-17 16:34:29 +0000512 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000513 {__c1 = __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000514 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000515 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000516 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000517 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000518
519 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000520 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000521 static size_t length(const char_type* __s);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000522 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000523 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
524 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000525 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000526 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000527 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000528 static char_type* assign(char_type* __s, size_t __n, char_type __a);
529
Dan Albert6d9505a2014-09-17 16:34:29 +0000530 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000531 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000532 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000533 {return char_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000534 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000535 {return int_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000536 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000537 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000538 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000539 {return int_type(EOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000540};
541
542template <class _CharT>
543int
544char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
545{
546 for (; __n; --__n, ++__s1, ++__s2)
547 {
548 if (lt(*__s1, *__s2))
549 return -1;
550 if (lt(*__s2, *__s1))
551 return 1;
552 }
553 return 0;
554}
555
556template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000557inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000558size_t
559char_traits<_CharT>::length(const char_type* __s)
560{
561 size_t __len = 0;
562 for (; !eq(*__s, char_type(0)); ++__s)
563 ++__len;
564 return __len;
565}
566
567template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000568inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000569const _CharT*
570char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a)
571{
572 for (; __n; --__n)
573 {
574 if (eq(*__s, __a))
575 return __s;
576 ++__s;
577 }
578 return 0;
579}
580
581template <class _CharT>
582_CharT*
583char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n)
584{
585 char_type* __r = __s1;
586 if (__s1 < __s2)
587 {
588 for (; __n; --__n, ++__s1, ++__s2)
589 assign(*__s1, *__s2);
590 }
591 else if (__s2 < __s1)
592 {
593 __s1 += __n;
594 __s2 += __n;
595 for (; __n; --__n)
596 assign(*--__s1, *--__s2);
597 }
598 return __r;
599}
600
601template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000602inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000603_CharT*
604char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
605{
Howard Hinnant499cea12013-08-23 17:37:05 +0000606 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000607 char_type* __r = __s1;
608 for (; __n; --__n, ++__s1, ++__s2)
609 assign(*__s1, *__s2);
610 return __r;
611}
612
613template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000614inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000615_CharT*
616char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
617{
618 char_type* __r = __s;
619 for (; __n; --__n, ++__s)
620 assign(*__s, __a);
621 return __r;
622}
623
624// char_traits<char>
625
626template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000627struct _LIBCPP_TYPE_VIS_ONLY char_traits<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000628{
629 typedef char char_type;
630 typedef int int_type;
631 typedef streamoff off_type;
632 typedef streampos pos_type;
633 typedef mbstate_t state_type;
634
Dan Albert6d9505a2014-09-17 16:34:29 +0000635 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000636 {__c1 = __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000637 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000638 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000639 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000640 {return (unsigned char)__c1 < (unsigned char)__c2;}
641
Dan Albert6d9505a2014-09-17 16:34:29 +0000642 static inline int compare(const char_type* __s1, const char_type* __s2, size_t __n)
Marshall Clowf2e36ef2015-02-12 23:34:52 +0000643 {return __n == 0 ? 0 : memcmp(__s1, __s2, __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000644 static inline size_t length(const char_type* __s) {return strlen(__s);}
645 static inline const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000646 {return __n == 0 ? NULL : (const char_type*) memchr(__s, to_int_type(__a), __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000647 static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000648 {return __n == 0 ? __s1 : (char_type*) memmove(__s1, __s2, __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000649 static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnant499cea12013-08-23 17:37:05 +0000650 {
651 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Marshall Clow6bcbced2015-02-13 16:04:42 +0000652 return __n == 0 ? __s1 : (char_type*)memcpy(__s1, __s2, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +0000653 }
Dan Albert6d9505a2014-09-17 16:34:29 +0000654 static inline char_type* assign(char_type* __s, size_t __n, char_type __a)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000655 {return __n == 0 ? __s : (char_type*)memset(__s, to_int_type(__a), __n);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000656
Dan Albert6d9505a2014-09-17 16:34:29 +0000657 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000658 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000659 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000660 {return char_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000661 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000662 {return int_type((unsigned char)__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000663 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000664 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000665 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000666 {return int_type(EOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000667};
668
669// char_traits<wchar_t>
670
671template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000672struct _LIBCPP_TYPE_VIS_ONLY char_traits<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000673{
674 typedef wchar_t char_type;
675 typedef wint_t int_type;
676 typedef streamoff off_type;
677 typedef streampos pos_type;
678 typedef mbstate_t state_type;
679
Dan Albert6d9505a2014-09-17 16:34:29 +0000680 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000681 {__c1 = __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000682 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000683 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000684 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000685 {return __c1 < __c2;}
686
Dan Albert6d9505a2014-09-17 16:34:29 +0000687 static inline int compare(const char_type* __s1, const char_type* __s2, size_t __n)
Marshall Clowf2e36ef2015-02-12 23:34:52 +0000688 {return __n == 0 ? 0 : wmemcmp(__s1, __s2, __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000689 static inline size_t length(const char_type* __s)
Howard Hinnanta6119a82011-05-29 19:57:12 +0000690 {return wcslen(__s);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000691 static inline const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000692 {return __n == 0 ? NULL : (const char_type*)wmemchr(__s, __a, __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000693 static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000694 {return __n == 0 ? __s1 : (char_type*)wmemmove(__s1, __s2, __n);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000695 static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
Howard Hinnant499cea12013-08-23 17:37:05 +0000696 {
697 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Marshall Clow6bcbced2015-02-13 16:04:42 +0000698 return __n == 0 ? __s1 : (char_type*)wmemcpy(__s1, __s2, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +0000699 }
Dan Albert6d9505a2014-09-17 16:34:29 +0000700 static inline char_type* assign(char_type* __s, size_t __n, char_type __a)
Marshall Clow6bcbced2015-02-13 16:04:42 +0000701 {return __n == 0 ? __s : (char_type*)wmemset(__s, __a, __n);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000702
Dan Albert6d9505a2014-09-17 16:34:29 +0000703 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000704 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000705 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000706 {return char_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000707 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000708 {return int_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000709 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000710 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000711 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000712 {return int_type(WEOF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000713};
714
715#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
716
717template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000718struct _LIBCPP_TYPE_VIS_ONLY char_traits<char16_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000719{
720 typedef char16_t char_type;
721 typedef uint_least16_t int_type;
722 typedef streamoff off_type;
723 typedef u16streampos pos_type;
724 typedef mbstate_t state_type;
725
Dan Albert6d9505a2014-09-17 16:34:29 +0000726 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000727 {__c1 = __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000728 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000729 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000730 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000731 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000732
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000733 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000734 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000735 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000736 static size_t length(const char_type* __s);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000737 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000738 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000739 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000740 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000741 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000742 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000743 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000744 static char_type* assign(char_type* __s, size_t __n, char_type __a);
745
Dan Albert6d9505a2014-09-17 16:34:29 +0000746 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000747 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000748 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000749 {return char_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000750 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000751 {return int_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000752 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000753 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000754 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Marshall Clow9a3c6892015-08-04 01:38:34 +0000755 {return int_type(0xFFFF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000756};
757
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000758inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000759int
760char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
761{
762 for (; __n; --__n, ++__s1, ++__s2)
763 {
764 if (lt(*__s1, *__s2))
765 return -1;
766 if (lt(*__s2, *__s1))
767 return 1;
768 }
769 return 0;
770}
771
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000772inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000773size_t
774char_traits<char16_t>::length(const char_type* __s)
775{
776 size_t __len = 0;
777 for (; !eq(*__s, char_type(0)); ++__s)
778 ++__len;
779 return __len;
780}
781
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000782inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000783const char16_t*
784char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a)
785{
786 for (; __n; --__n)
787 {
788 if (eq(*__s, __a))
789 return __s;
790 ++__s;
791 }
792 return 0;
793}
794
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000795inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000796char16_t*
797char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
798{
799 char_type* __r = __s1;
800 if (__s1 < __s2)
801 {
802 for (; __n; --__n, ++__s1, ++__s2)
803 assign(*__s1, *__s2);
804 }
805 else if (__s2 < __s1)
806 {
807 __s1 += __n;
808 __s2 += __n;
809 for (; __n; --__n)
810 assign(*--__s1, *--__s2);
811 }
812 return __r;
813}
814
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000815inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000816char16_t*
817char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
818{
Howard Hinnant499cea12013-08-23 17:37:05 +0000819 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000820 char_type* __r = __s1;
821 for (; __n; --__n, ++__s1, ++__s2)
822 assign(*__s1, *__s2);
823 return __r;
824}
825
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000826inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000827char16_t*
828char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a)
829{
830 char_type* __r = __s;
831 for (; __n; --__n, ++__s)
832 assign(*__s, __a);
833 return __r;
834}
835
836template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000837struct _LIBCPP_TYPE_VIS_ONLY char_traits<char32_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000838{
839 typedef char32_t char_type;
840 typedef uint_least32_t int_type;
841 typedef streamoff off_type;
842 typedef u32streampos pos_type;
843 typedef mbstate_t state_type;
844
Dan Albert6d9505a2014-09-17 16:34:29 +0000845 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000846 {__c1 = __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000847 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000848 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000849 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000850 {return __c1 < __c2;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000851
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000852 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000853 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000854 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000855 static size_t length(const char_type* __s);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000857 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000858 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000859 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000861 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000862 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000863 static char_type* assign(char_type* __s, size_t __n, char_type __a);
864
Dan Albert6d9505a2014-09-17 16:34:29 +0000865 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000866 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000867 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000868 {return char_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000869 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000870 {return int_type(__c);}
Dan Albert6d9505a2014-09-17 16:34:29 +0000871 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000872 {return __c1 == __c2;}
Dan Albert6d9505a2014-09-17 16:34:29 +0000873 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
Howard Hinnanta6119a82011-05-29 19:57:12 +0000874 {return int_type(0xFFFFFFFF);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000875};
876
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000877inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000878int
879char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
880{
881 for (; __n; --__n, ++__s1, ++__s2)
882 {
883 if (lt(*__s1, *__s2))
884 return -1;
885 if (lt(*__s2, *__s1))
886 return 1;
887 }
888 return 0;
889}
890
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000891inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000892size_t
893char_traits<char32_t>::length(const char_type* __s)
894{
895 size_t __len = 0;
896 for (; !eq(*__s, char_type(0)); ++__s)
897 ++__len;
898 return __len;
899}
900
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000901inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000902const char32_t*
903char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a)
904{
905 for (; __n; --__n)
906 {
907 if (eq(*__s, __a))
908 return __s;
909 ++__s;
910 }
911 return 0;
912}
913
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000914inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000915char32_t*
916char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
917{
918 char_type* __r = __s1;
919 if (__s1 < __s2)
920 {
921 for (; __n; --__n, ++__s1, ++__s2)
922 assign(*__s1, *__s2);
923 }
924 else if (__s2 < __s1)
925 {
926 __s1 += __n;
927 __s2 += __n;
928 for (; __n; --__n)
929 assign(*--__s1, *--__s2);
930 }
931 return __r;
932}
933
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000934inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000935char32_t*
936char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
937{
Howard Hinnant499cea12013-08-23 17:37:05 +0000938 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000939 char_type* __r = __s1;
940 for (; __n; --__n, ++__s1, ++__s2)
941 assign(*__s1, *__s2);
942 return __r;
943}
944
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +0000945inline
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000946char32_t*
947char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a)
948{
949 char_type* __r = __s;
950 for (; __n; --__n, ++__s)
951 assign(*__s, __a);
952 return __r;
953}
954
Howard Hinnant324bb032010-08-22 00:02:43 +0000955#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000956
Marshall Clowb671fc92013-12-09 16:00:28 +0000957// helper fns for basic_string
958
Marshall Clow37025e12014-06-10 18:51:55 +0000959// __str_find
Marshall Clowb671fc92013-12-09 16:00:28 +0000960template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Marshall Clow360f3192014-06-02 02:22:49 +0000961_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +0000962__str_find(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +0000963 _CharT __c, _SizeT __pos) _NOEXCEPT
964{
965 if (__pos >= __sz)
966 return __npos;
967 const _CharT* __r = _Traits::find(__p + __pos, __sz - __pos, __c);
968 if (__r == 0)
969 return __npos;
970 return static_cast<_SizeT>(__r - __p);
971}
972
973template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
974_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +0000975__str_find(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +0000976 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
977{
978 if (__pos > __sz || __sz - __pos < __n)
979 return __npos;
980 if (__n == 0)
981 return __pos;
Marshall Clow360f3192014-06-02 02:22:49 +0000982 const _CharT* __r =
Marshall Clow37025e12014-06-10 18:51:55 +0000983 _VSTD::__search(__p + __pos, __p + __sz,
984 __s, __s + __n, _Traits::eq,
985 random_access_iterator_tag(), random_access_iterator_tag());
Marshall Clow360f3192014-06-02 02:22:49 +0000986 if (__r == __p + __sz)
987 return __npos;
988 return static_cast<_SizeT>(__r - __p);
989}
990
991
Marshall Clow37025e12014-06-10 18:51:55 +0000992// __str_rfind
Marshall Clow360f3192014-06-02 02:22:49 +0000993
994template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
995_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +0000996__str_rfind(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +0000997 _CharT __c, _SizeT __pos) _NOEXCEPT
998{
999 if (__sz < 1)
Marshall Clowd5549cc2014-07-17 15:32:20 +00001000 return __npos;
1001 if (__pos < __sz)
1002 ++__pos;
1003 else
1004 __pos = __sz;
1005 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1006 {
1007 if (_Traits::eq(*--__ps, __c))
1008 return static_cast<_SizeT>(__ps - __p);
1009 }
Marshall Clow360f3192014-06-02 02:22:49 +00001010 return __npos;
1011}
1012
1013template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1014_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001015__str_rfind(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001016 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1017{
1018 __pos = _VSTD::min(__pos, __sz);
1019 if (__n < __sz - __pos)
1020 __pos += __n;
1021 else
1022 __pos = __sz;
Marshall Clow37025e12014-06-10 18:51:55 +00001023 const _CharT* __r = _VSTD::__find_end(
1024 __p, __p + __pos, __s, __s + __n, _Traits::eq,
1025 random_access_iterator_tag(), random_access_iterator_tag());
Marshall Clow360f3192014-06-02 02:22:49 +00001026 if (__n > 0 && __r == __p + __pos)
1027 return __npos;
1028 return static_cast<_SizeT>(__r - __p);
1029}
1030
Marshall Clow37025e12014-06-10 18:51:55 +00001031// __str_find_first_of
Marshall Clow360f3192014-06-02 02:22:49 +00001032template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1033_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001034__str_find_first_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001035 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001036{
1037 if (__pos >= __sz || __n == 0)
1038 return __npos;
Marshall Clow37025e12014-06-10 18:51:55 +00001039 const _CharT* __r = _VSTD::__find_first_of_ce
Marshall Clowb671fc92013-12-09 16:00:28 +00001040 (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq );
1041 if (__r == __p + __sz)
1042 return __npos;
1043 return static_cast<_SizeT>(__r - __p);
1044}
1045
Marshall Clow360f3192014-06-02 02:22:49 +00001046
Marshall Clow37025e12014-06-10 18:51:55 +00001047// __str_find_last_of
Marshall Clowb671fc92013-12-09 16:00:28 +00001048template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Marshall Clow360f3192014-06-02 02:22:49 +00001049_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001050__str_find_last_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001051 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001052 {
1053 if (__n != 0)
1054 {
1055 if (__pos < __sz)
1056 ++__pos;
1057 else
1058 __pos = __sz;
1059 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1060 {
1061 const _CharT* __r = _Traits::find(__s, __n, *--__ps);
1062 if (__r)
1063 return static_cast<_SizeT>(__ps - __p);
1064 }
1065 }
1066 return __npos;
1067}
1068
1069
Marshall Clow37025e12014-06-10 18:51:55 +00001070// __str_find_first_not_of
Marshall Clowb671fc92013-12-09 16:00:28 +00001071template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Marshall Clow360f3192014-06-02 02:22:49 +00001072_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001073__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001074 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001075{
1076 if (__pos < __sz)
1077 {
1078 const _CharT* __pe = __p + __sz;
1079 for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
1080 if (_Traits::find(__s, __n, *__ps) == 0)
1081 return static_cast<_SizeT>(__ps - __p);
1082 }
1083 return __npos;
1084}
1085
1086
1087template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Marshall Clow360f3192014-06-02 02:22:49 +00001088_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001089__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001090 _CharT __c, _SizeT __pos) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001091{
1092 if (__pos < __sz)
1093 {
1094 const _CharT* __pe = __p + __sz;
1095 for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
1096 if (!_Traits::eq(*__ps, __c))
1097 return static_cast<_SizeT>(__ps - __p);
1098 }
1099 return __npos;
1100}
1101
1102
Marshall Clow37025e12014-06-10 18:51:55 +00001103// __str_find_last_not_of
Marshall Clowb671fc92013-12-09 16:00:28 +00001104template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Marshall Clow360f3192014-06-02 02:22:49 +00001105_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001106__str_find_last_not_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001107 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001108{
1109 if (__pos < __sz)
1110 ++__pos;
1111 else
1112 __pos = __sz;
1113 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1114 if (_Traits::find(__s, __n, *--__ps) == 0)
1115 return static_cast<_SizeT>(__ps - __p);
1116 return __npos;
1117}
1118
1119
1120template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
Marshall Clow360f3192014-06-02 02:22:49 +00001121_SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow37025e12014-06-10 18:51:55 +00001122__str_find_last_not_of(const _CharT *__p, _SizeT __sz,
Marshall Clow360f3192014-06-02 02:22:49 +00001123 _CharT __c, _SizeT __pos) _NOEXCEPT
Marshall Clowb671fc92013-12-09 16:00:28 +00001124{
1125 if (__pos < __sz)
1126 ++__pos;
1127 else
1128 __pos = __sz;
1129 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1130 if (!_Traits::eq(*--__ps, __c))
1131 return static_cast<_SizeT>(__ps - __p);
1132 return __npos;
1133}
1134
1135template<class _Ptr>
1136size_t _LIBCPP_INLINE_VISIBILITY __do_string_hash(_Ptr __p, _Ptr __e)
1137{
1138 typedef typename iterator_traits<_Ptr>::value_type value_type;
1139 return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));
1140}
1141
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001142// basic_string
1143
1144template<class _CharT, class _Traits, class _Allocator>
1145basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001146operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
1147 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001148
1149template<class _CharT, class _Traits, class _Allocator>
1150basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001151operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001152
1153template<class _CharT, class _Traits, class _Allocator>
1154basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001155operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001156
1157template<class _CharT, class _Traits, class _Allocator>
1158basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001159operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001160
1161template<class _CharT, class _Traits, class _Allocator>
1162basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00001163operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001164
1165template <bool>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001166class _LIBCPP_TYPE_VIS_ONLY __basic_string_common
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001167{
1168protected:
1169 void __throw_length_error() const;
1170 void __throw_out_of_range() const;
1171};
1172
1173template <bool __b>
1174void
1175__basic_string_common<__b>::__throw_length_error() const
1176{
1177#ifndef _LIBCPP_NO_EXCEPTIONS
1178 throw length_error("basic_string");
1179#else
1180 assert(!"basic_string length_error");
1181#endif
1182}
1183
1184template <bool __b>
1185void
1186__basic_string_common<__b>::__throw_out_of_range() const
1187{
1188#ifndef _LIBCPP_NO_EXCEPTIONS
1189 throw out_of_range("basic_string");
1190#else
1191 assert(!"basic_string out_of_range");
1192#endif
1193}
1194
Howard Hinnante9df0a52013-08-01 18:17:34 +00001195#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +00001196#pragma warning( push )
1197#pragma warning( disable: 4231 )
Howard Hinnante9df0a52013-08-01 18:17:34 +00001198#endif // _LIBCPP_MSVC
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001199_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __basic_string_common<true>)
Howard Hinnante9df0a52013-08-01 18:17:34 +00001200#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +00001201#pragma warning( pop )
Howard Hinnante9df0a52013-08-01 18:17:34 +00001202#endif // _LIBCPP_MSVC
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001203
Marshall Clowdf9db312016-01-13 21:54:34 +00001204#ifdef _LIBCPP_NO_EXCEPTIONS
1205template <class _Iter>
1206struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
1207#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
1208template <class _Iter>
1209struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
1210#else
1211template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
1212struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
1213 noexcept(++(declval<_Iter&>())) &&
1214 is_nothrow_assignable<_Iter&, _Iter>::value &&
1215 noexcept(declval<_Iter>() == declval<_Iter>()) &&
1216 noexcept(*declval<_Iter>())
1217)) {};
1218
1219template <class _Iter>
1220struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
1221#endif
1222
1223
1224template <class _Iter>
1225struct __libcpp_string_gets_noexcept_iterator
1226 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
1227
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001228#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001229
1230template <class _CharT, size_t = sizeof(_CharT)>
1231struct __padding
1232{
1233 unsigned char __xx[sizeof(_CharT)-1];
1234};
1235
1236template <class _CharT>
1237struct __padding<_CharT, 1>
1238{
1239};
1240
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001241#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001242
Howard Hinnant324bb032010-08-22 00:02:43 +00001243template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001244class _LIBCPP_TYPE_VIS_ONLY basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001245 : private __basic_string_common<true>
1246{
1247public:
1248 typedef basic_string __self;
1249 typedef _Traits traits_type;
1250 typedef typename traits_type::char_type value_type;
1251 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001252 typedef allocator_traits<allocator_type> __alloc_traits;
1253 typedef typename __alloc_traits::size_type size_type;
1254 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001255 typedef value_type& reference;
1256 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001257 typedef typename __alloc_traits::pointer pointer;
1258 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001259
Howard Hinnant499cea12013-08-23 17:37:05 +00001260 static_assert(is_pod<value_type>::value, "Character type of basic_string must be a POD");
1261 static_assert((is_same<_CharT, value_type>::value),
1262 "traits_type::char_type must be the same type as CharT");
1263 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1264 "Allocator::value_type must be same type as value_type");
1265#if defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001266 typedef pointer iterator;
1267 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001268#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001269 typedef __wrap_iter<pointer> iterator;
1270 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +00001271#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001272 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1273 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001274
1275private:
Howard Hinnant15467182013-04-30 21:44:48 +00001276
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001277#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001278
1279 struct __long
1280 {
1281 pointer __data_;
1282 size_type __size_;
1283 size_type __cap_;
1284 };
1285
1286#if _LIBCPP_BIG_ENDIAN
1287 enum {__short_mask = 0x01};
1288 enum {__long_mask = 0x1ul};
1289#else // _LIBCPP_BIG_ENDIAN
1290 enum {__short_mask = 0x80};
1291 enum {__long_mask = ~(size_type(~0) >> 1)};
1292#endif // _LIBCPP_BIG_ENDIAN
1293
1294 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1295 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1296
1297 struct __short
1298 {
1299 value_type __data_[__min_cap];
1300 struct
1301 : __padding<value_type>
1302 {
1303 unsigned char __size_;
1304 };
1305 };
1306
1307#else
1308
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001309 struct __long
1310 {
1311 size_type __cap_;
1312 size_type __size_;
1313 pointer __data_;
1314 };
1315
1316#if _LIBCPP_BIG_ENDIAN
1317 enum {__short_mask = 0x80};
1318 enum {__long_mask = ~(size_type(~0) >> 1)};
Howard Hinnant324bb032010-08-22 00:02:43 +00001319#else // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001320 enum {__short_mask = 0x01};
Howard Hinnantec3773c2011-12-01 20:21:04 +00001321 enum {__long_mask = 0x1ul};
Howard Hinnant324bb032010-08-22 00:02:43 +00001322#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001323
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001324 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1325 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1326
1327 struct __short
1328 {
1329 union
1330 {
1331 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59 +00001332 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001333 };
1334 value_type __data_[__min_cap];
1335 };
1336
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001337#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001338
Howard Hinnant499cea12013-08-23 17:37:05 +00001339 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001340
Howard Hinnant499cea12013-08-23 17:37:05 +00001341 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001342
1343 struct __raw
1344 {
1345 size_type __words[__n_words];
1346 };
1347
1348 struct __rep
1349 {
1350 union
1351 {
1352 __long __l;
1353 __short __s;
1354 __raw __r;
1355 };
1356 };
1357
1358 __compressed_pair<__rep, allocator_type> __r_;
1359
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001360public:
1361 static const size_type npos = -1;
1362
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001363 _LIBCPP_INLINE_VISIBILITY basic_string()
1364 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +00001365
1366 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
1367#if _LIBCPP_STD_VER <= 14
1368 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
1369#else
1370 _NOEXCEPT;
1371#endif
1372
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001373 basic_string(const basic_string& __str);
1374 basic_string(const basic_string& __str, const allocator_type& __a);
Marshall Clow7b193f72015-06-03 19:56:43 +00001375
Howard Hinnant73d21a42010-09-04 23:28:19 +00001376#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9f193f22011-01-26 00:06:59 +00001377 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001378 basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +00001379#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001380 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +00001381#else
1382 _NOEXCEPT;
1383#endif
1384
Howard Hinnant9f193f22011-01-26 00:06:59 +00001385 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001386 basic_string(basic_string&& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001387#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001388 _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001389 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001390 basic_string(const value_type* __s, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001391 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001392 basic_string(const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001393 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001394 basic_string(const value_type* __s, size_type __n, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001395 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001396 basic_string(size_type __n, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001397 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001398 basic_string(size_type __n, value_type __c, const allocator_type& __a);
1399 basic_string(const basic_string& __str, size_type __pos, size_type __n = npos,
1400 const allocator_type& __a = allocator_type());
1401 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001402 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001403 basic_string(_InputIterator __first, _InputIterator __last);
1404 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001405 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001406 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001407#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001408 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001409 basic_string(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001410 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001411 basic_string(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +00001412#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001413
1414 ~basic_string();
1415
Howard Hinnante32b5e22010-11-17 17:55:08 +00001416 basic_string& operator=(const basic_string& __str);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001417#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001418 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001419 basic_string& operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001420 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001421#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001422 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001423 basic_string& operator=(value_type __c);
Howard Hinnante3e32912011-08-12 21:56:02 +00001424#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001425 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001426 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001427#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001428
Howard Hinnant499cea12013-08-23 17:37:05 +00001429#if _LIBCPP_DEBUG_LEVEL >= 2
1430 _LIBCPP_INLINE_VISIBILITY
1431 iterator begin() _NOEXCEPT
1432 {return iterator(this, __get_pointer());}
1433 _LIBCPP_INLINE_VISIBILITY
1434 const_iterator begin() const _NOEXCEPT
1435 {return const_iterator(this, __get_pointer());}
1436 _LIBCPP_INLINE_VISIBILITY
1437 iterator end() _NOEXCEPT
1438 {return iterator(this, __get_pointer() + size());}
1439 _LIBCPP_INLINE_VISIBILITY
1440 const_iterator end() const _NOEXCEPT
1441 {return const_iterator(this, __get_pointer() + size());}
1442#else
Howard Hinnanta6119a82011-05-29 19:57:12 +00001443 _LIBCPP_INLINE_VISIBILITY
1444 iterator begin() _NOEXCEPT
1445 {return iterator(__get_pointer());}
1446 _LIBCPP_INLINE_VISIBILITY
1447 const_iterator begin() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001448 {return const_iterator(__get_pointer());}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001449 _LIBCPP_INLINE_VISIBILITY
1450 iterator end() _NOEXCEPT
1451 {return iterator(__get_pointer() + size());}
1452 _LIBCPP_INLINE_VISIBILITY
1453 const_iterator end() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001454 {return const_iterator(__get_pointer() + size());}
Howard Hinnant499cea12013-08-23 17:37:05 +00001455#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnanta6119a82011-05-29 19:57:12 +00001456 _LIBCPP_INLINE_VISIBILITY
1457 reverse_iterator rbegin() _NOEXCEPT
1458 {return reverse_iterator(end());}
1459 _LIBCPP_INLINE_VISIBILITY
1460 const_reverse_iterator rbegin() const _NOEXCEPT
1461 {return const_reverse_iterator(end());}
1462 _LIBCPP_INLINE_VISIBILITY
1463 reverse_iterator rend() _NOEXCEPT
1464 {return reverse_iterator(begin());}
1465 _LIBCPP_INLINE_VISIBILITY
1466 const_reverse_iterator rend() const _NOEXCEPT
1467 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001468
Howard Hinnanta6119a82011-05-29 19:57:12 +00001469 _LIBCPP_INLINE_VISIBILITY
1470 const_iterator cbegin() const _NOEXCEPT
1471 {return begin();}
1472 _LIBCPP_INLINE_VISIBILITY
1473 const_iterator cend() const _NOEXCEPT
1474 {return end();}
1475 _LIBCPP_INLINE_VISIBILITY
1476 const_reverse_iterator crbegin() const _NOEXCEPT
1477 {return rbegin();}
1478 _LIBCPP_INLINE_VISIBILITY
1479 const_reverse_iterator crend() const _NOEXCEPT
1480 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001481
Howard Hinnanta6119a82011-05-29 19:57:12 +00001482 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001483 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001484 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
1485 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
1486 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001487 {return (__is_long() ? __get_long_cap()
1488 : static_cast<size_type>(__min_cap)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001489
1490 void resize(size_type __n, value_type __c);
1491 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
1492
1493 void reserve(size_type res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001495 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001496 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001497 void clear() _NOEXCEPT;
1498 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001499
1500 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const;
1501 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos);
1502
1503 const_reference at(size_type __n) const;
1504 reference at(size_type __n);
1505
1506 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001507 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001508 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +00001509#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001510 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Howard Hinnante3e32912011-08-12 21:56:02 +00001511#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001512
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001513 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001514 basic_string& append(const basic_string& __str);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001515 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001516 basic_string& append(const value_type* __s, size_type __n);
1517 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001518 basic_string& append(size_type __n, value_type __c);
1519 template<class _InputIterator>
1520 typename enable_if
1521 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001522 __is_exactly_input_iterator<_InputIterator>::value
1523 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001524 basic_string&
1525 >::type
1526 append(_InputIterator __first, _InputIterator __last);
1527 template<class _ForwardIterator>
1528 typename enable_if
1529 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001530 __is_forward_iterator<_ForwardIterator>::value
1531 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001532 basic_string&
1533 >::type
1534 append(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001535#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001536 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001537 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001538#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001539
1540 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001541 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001542 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001543 _LIBCPP_INLINE_VISIBILITY reference front();
1544 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
1545 _LIBCPP_INLINE_VISIBILITY reference back();
1546 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001547
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001548 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001549 basic_string& assign(const basic_string& __str);
Howard Hinnanta6119a82011-05-29 19:57:12 +00001550#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1551 _LIBCPP_INLINE_VISIBILITY
1552 basic_string& assign(basic_string&& str)
Marshall Clow7ed093b2015-10-05 16:17:34 +00001553 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +00001554 {*this = _VSTD::move(str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001555#endif
Marshall Clowa93b5e22014-03-04 19:17:19 +00001556 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001557 basic_string& assign(const value_type* __s, size_type __n);
1558 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001559 basic_string& assign(size_type __n, value_type __c);
1560 template<class _InputIterator>
1561 typename enable_if
1562 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001563 __is_exactly_input_iterator<_InputIterator>::value
1564 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001565 basic_string&
1566 >::type
1567 assign(_InputIterator __first, _InputIterator __last);
1568 template<class _ForwardIterator>
1569 typename enable_if
1570 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001571 __is_forward_iterator<_ForwardIterator>::value
1572 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001573 basic_string&
1574 >::type
1575 assign(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001576#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001578 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001579#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001580
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001581 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001582 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001583 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001584 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1585 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001586 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1587 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001588 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001589 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1590 template<class _InputIterator>
1591 typename enable_if
1592 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001593 __is_exactly_input_iterator<_InputIterator>::value
1594 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001595 iterator
1596 >::type
1597 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1598 template<class _ForwardIterator>
1599 typename enable_if
1600 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001601 __is_forward_iterator<_ForwardIterator>::value
1602 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001603 iterator
1604 >::type
1605 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001606#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001608 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1609 {return insert(__pos, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001610#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001611
1612 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001613 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001614 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001615 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001616 iterator erase(const_iterator __first, const_iterator __last);
1617
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001618 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001619 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001620 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 +00001621 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1622 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001623 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001625 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001626 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001627 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001628 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001629 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001631 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001632 template<class _InputIterator>
1633 typename enable_if
1634 <
1635 __is_input_iterator<_InputIterator>::value,
1636 basic_string&
1637 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001638 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Howard Hinnante3e32912011-08-12 21:56:02 +00001639#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001640 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001641 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001642 {return replace(__i1, __i2, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001643#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001644
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001645 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001646 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001647 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1648
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001649 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001650 void swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00001651#if _LIBCPP_STD_VER >= 14
1652 _NOEXCEPT;
1653#else
1654 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1655 __is_nothrow_swappable<allocator_type>::value);
1656#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001657
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001658 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001659 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001660 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001661 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001662
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001663 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001664 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001665
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001666 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001667 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001668 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001669 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001670 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001671 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001672
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001673 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001674 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001675 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001676 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001677 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001678 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001679
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001681 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001682 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001683 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001684 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001685 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001686 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001687
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001688 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001689 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001690 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001691 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001692 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001693 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001694 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001695
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001697 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001698 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 +00001699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001700 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001701 _LIBCPP_INLINE_VISIBILITY
1702 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1703
1704 _LIBCPP_INLINE_VISIBILITY
1705 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001706 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 +00001707 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001708 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001709 _LIBCPP_INLINE_VISIBILITY
1710 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1711
1712 _LIBCPP_INLINE_VISIBILITY
1713 int compare(const basic_string& __str) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001714 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001715 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clowa93b5e22014-03-04 19:17:19 +00001716 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 +00001717 int compare(const value_type* __s) const _NOEXCEPT;
1718 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1719 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001720
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001721 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:13 +00001722
1723 _LIBCPP_INLINE_VISIBILITY
1724 bool __is_long() const _NOEXCEPT
1725 {return bool(__r_.first().__s.__size_ & __short_mask);}
1726
Howard Hinnant499cea12013-08-23 17:37:05 +00001727#if _LIBCPP_DEBUG_LEVEL >= 2
1728
1729 bool __dereferenceable(const const_iterator* __i) const;
1730 bool __decrementable(const const_iterator* __i) const;
1731 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1732 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1733
1734#endif // _LIBCPP_DEBUG_LEVEL >= 2
1735
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001736private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001737 _LIBCPP_INLINE_VISIBILITY
1738 allocator_type& __alloc() _NOEXCEPT
1739 {return __r_.second();}
1740 _LIBCPP_INLINE_VISIBILITY
1741 const allocator_type& __alloc() const _NOEXCEPT
1742 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001743
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001744#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001745
Howard Hinnanta6119a82011-05-29 19:57:12 +00001746 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001747 void __set_short_size(size_type __s) _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001748# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001749 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:48 +00001750# else
1751 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1752# endif
1753
Howard Hinnanta6119a82011-05-29 19:57:12 +00001754 _LIBCPP_INLINE_VISIBILITY
1755 size_type __get_short_size() const _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001756# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001757 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:48 +00001758# else
1759 {return __r_.first().__s.__size_;}
1760# endif
1761
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001762#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001763
1764 _LIBCPP_INLINE_VISIBILITY
1765 void __set_short_size(size_type __s) _NOEXCEPT
1766# if _LIBCPP_BIG_ENDIAN
1767 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1768# else
1769 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1770# endif
1771
1772 _LIBCPP_INLINE_VISIBILITY
1773 size_type __get_short_size() const _NOEXCEPT
1774# if _LIBCPP_BIG_ENDIAN
1775 {return __r_.first().__s.__size_;}
1776# else
1777 {return __r_.first().__s.__size_ >> 1;}
1778# endif
1779
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001780#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001781
Howard Hinnanta6119a82011-05-29 19:57:12 +00001782 _LIBCPP_INLINE_VISIBILITY
1783 void __set_long_size(size_type __s) _NOEXCEPT
1784 {__r_.first().__l.__size_ = __s;}
1785 _LIBCPP_INLINE_VISIBILITY
1786 size_type __get_long_size() const _NOEXCEPT
1787 {return __r_.first().__l.__size_;}
1788 _LIBCPP_INLINE_VISIBILITY
1789 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001790 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1791
Howard Hinnanta6119a82011-05-29 19:57:12 +00001792 _LIBCPP_INLINE_VISIBILITY
1793 void __set_long_cap(size_type __s) _NOEXCEPT
1794 {__r_.first().__l.__cap_ = __long_mask | __s;}
1795 _LIBCPP_INLINE_VISIBILITY
1796 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001797 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001798
Howard Hinnanta6119a82011-05-29 19:57:12 +00001799 _LIBCPP_INLINE_VISIBILITY
1800 void __set_long_pointer(pointer __p) _NOEXCEPT
1801 {__r_.first().__l.__data_ = __p;}
1802 _LIBCPP_INLINE_VISIBILITY
1803 pointer __get_long_pointer() _NOEXCEPT
1804 {return __r_.first().__l.__data_;}
1805 _LIBCPP_INLINE_VISIBILITY
1806 const_pointer __get_long_pointer() const _NOEXCEPT
1807 {return __r_.first().__l.__data_;}
1808 _LIBCPP_INLINE_VISIBILITY
1809 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001810 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001811 _LIBCPP_INLINE_VISIBILITY
1812 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001813 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001814 _LIBCPP_INLINE_VISIBILITY
1815 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001816 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001817 _LIBCPP_INLINE_VISIBILITY
1818 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001819 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1820
Howard Hinnanta6119a82011-05-29 19:57:12 +00001821 _LIBCPP_INLINE_VISIBILITY
1822 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001823 {
1824 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1825 for (unsigned __i = 0; __i < __n_words; ++__i)
1826 __a[__i] = 0;
1827 }
1828
1829 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001830 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:20 +00001831 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001832 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001833 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001834 static _LIBCPP_INLINE_VISIBILITY
1835 size_type __recommend(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001836 {return (__s < __min_cap ? static_cast<size_type>(__min_cap) :
Howard Hinnant7f764502013-08-14 18:00:20 +00001837 __align_it<sizeof(value_type) < __alignment ?
Howard Hinnanta6119a82011-05-29 19:57:12 +00001838 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001839
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001840 void __init(const value_type* __s, size_type __sz, size_type __reserve);
1841 void __init(const value_type* __s, size_type __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001842 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001843
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001844 template <class _InputIterator>
1845 typename enable_if
1846 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001847 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001848 void
1849 >::type
1850 __init(_InputIterator __first, _InputIterator __last);
1851
1852 template <class _ForwardIterator>
1853 typename enable_if
1854 <
1855 __is_forward_iterator<_ForwardIterator>::value,
1856 void
1857 >::type
1858 __init(_ForwardIterator __first, _ForwardIterator __last);
1859
1860 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001861 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001862 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1863 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001864 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001865
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001866 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001867 void __erase_to_end(size_type __pos);
1868
Howard Hinnante32b5e22010-11-17 17:55:08 +00001869 _LIBCPP_INLINE_VISIBILITY
1870 void __copy_assign_alloc(const basic_string& __str)
1871 {__copy_assign_alloc(__str, integral_constant<bool,
1872 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1873
1874 _LIBCPP_INLINE_VISIBILITY
1875 void __copy_assign_alloc(const basic_string& __str, true_type)
1876 {
1877 if (__alloc() != __str.__alloc())
1878 {
1879 clear();
1880 shrink_to_fit();
1881 }
1882 __alloc() = __str.__alloc();
1883 }
1884
1885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001886 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001887 {}
1888
1889#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001890 _LIBCPP_INLINE_VISIBILITY
Marshall Clowaf961ed2015-08-18 18:57:00 +00001891 void __move_assign(basic_string& __str, false_type)
1892 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001893 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001894 void __move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001895#if _LIBCPP_STD_VER > 14
1896 _NOEXCEPT;
1897#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001898 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001899#endif
Marshall Clowaf961ed2015-08-18 18:57:00 +00001900#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00001901
1902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001903 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001904 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001905 _NOEXCEPT_(
1906 !__alloc_traits::propagate_on_container_move_assignment::value ||
1907 is_nothrow_move_assignable<allocator_type>::value)
1908 {__move_assign_alloc(__str, integral_constant<bool,
1909 __alloc_traits::propagate_on_container_move_assignment::value>());}
1910
1911 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001912 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001913 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1914 {
1915 __alloc() = _VSTD::move(__c.__alloc());
1916 }
1917
1918 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001919 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001920 _NOEXCEPT
1921 {}
1922
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001923 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1924 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001925
1926 friend basic_string operator+<>(const basic_string&, const basic_string&);
1927 friend basic_string operator+<>(const value_type*, const basic_string&);
1928 friend basic_string operator+<>(value_type, const basic_string&);
1929 friend basic_string operator+<>(const basic_string&, const value_type*);
1930 friend basic_string operator+<>(const basic_string&, value_type);
1931};
1932
1933template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001934inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001935void
1936basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1937{
Howard Hinnant499cea12013-08-23 17:37:05 +00001938#if _LIBCPP_DEBUG_LEVEL >= 2
1939 __get_db()->__invalidate_all(this);
1940#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001941}
1942
1943template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001944inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001945void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001946basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant499cea12013-08-23 17:37:05 +00001947#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantec3773c2011-12-01 20:21:04 +00001948 __pos
1949#endif
1950 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001951{
Howard Hinnant499cea12013-08-23 17:37:05 +00001952#if _LIBCPP_DEBUG_LEVEL >= 2
1953 __c_node* __c = __get_db()->__find_c_and_lock(this);
1954 if (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001955 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001956 const_pointer __new_last = __get_pointer() + __pos;
1957 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001958 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001959 --__p;
1960 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1961 if (__i->base() > __new_last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001962 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001963 (*__p)->__c_ = nullptr;
1964 if (--__c->end_ != __p)
1965 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001966 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001967 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001968 __get_db()->unlock();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001969 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001970#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001971}
1972
1973template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001974inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001975basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowc912c0c2015-06-04 02:05:41 +00001976 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001977{
Howard Hinnant499cea12013-08-23 17:37:05 +00001978#if _LIBCPP_DEBUG_LEVEL >= 2
1979 __get_db()->__insert_c(this);
1980#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001981 __zero();
1982}
1983
1984template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001985inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001986basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiselier692177d2015-07-18 20:40:46 +00001987#if _LIBCPP_STD_VER <= 14
1988 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1989#else
1990 _NOEXCEPT
1991#endif
1992: __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001993{
Howard Hinnant499cea12013-08-23 17:37:05 +00001994#if _LIBCPP_DEBUG_LEVEL >= 2
1995 __get_db()->__insert_c(this);
1996#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001997 __zero();
1998}
1999
2000template <class _CharT, class _Traits, class _Allocator>
2001void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002002basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002003{
2004 if (__reserve > max_size())
2005 this->__throw_length_error();
2006 pointer __p;
2007 if (__reserve < __min_cap)
2008 {
2009 __set_short_size(__sz);
2010 __p = __get_short_pointer();
2011 }
2012 else
2013 {
2014 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002015 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002016 __set_long_pointer(__p);
2017 __set_long_cap(__cap+1);
2018 __set_long_size(__sz);
2019 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002020 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002021 traits_type::assign(__p[__sz], value_type());
2022}
2023
2024template <class _CharT, class _Traits, class _Allocator>
2025void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002026basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002027{
2028 if (__sz > max_size())
2029 this->__throw_length_error();
2030 pointer __p;
2031 if (__sz < __min_cap)
2032 {
2033 __set_short_size(__sz);
2034 __p = __get_short_pointer();
2035 }
2036 else
2037 {
2038 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002039 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002040 __set_long_pointer(__p);
2041 __set_long_cap(__cap+1);
2042 __set_long_size(__sz);
2043 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002044 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002045 traits_type::assign(__p[__sz], value_type());
2046}
2047
2048template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002049inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002050basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002051{
Howard Hinnant499cea12013-08-23 17:37:05 +00002052 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002053 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00002054#if _LIBCPP_DEBUG_LEVEL >= 2
2055 __get_db()->__insert_c(this);
2056#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002057}
2058
2059template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002060inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002061basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002062 : __r_(__a)
2063{
Howard Hinnant499cea12013-08-23 17:37:05 +00002064 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002065 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00002066#if _LIBCPP_DEBUG_LEVEL >= 2
2067 __get_db()->__insert_c(this);
2068#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002069}
2070
2071template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002072inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002073basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002074{
Howard Hinnant499cea12013-08-23 17:37:05 +00002075 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002076 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00002077#if _LIBCPP_DEBUG_LEVEL >= 2
2078 __get_db()->__insert_c(this);
2079#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002080}
2081
2082template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002083inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002084basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002085 : __r_(__a)
2086{
Howard Hinnant499cea12013-08-23 17:37:05 +00002087 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002088 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00002089#if _LIBCPP_DEBUG_LEVEL >= 2
2090 __get_db()->__insert_c(this);
2091#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002092}
2093
2094template <class _CharT, class _Traits, class _Allocator>
2095basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002096 : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002097{
2098 if (!__str.__is_long())
2099 __r_.first().__r = __str.__r_.first().__r;
2100 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002101 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00002102#if _LIBCPP_DEBUG_LEVEL >= 2
2103 __get_db()->__insert_c(this);
2104#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002105}
2106
2107template <class _CharT, class _Traits, class _Allocator>
2108basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
2109 : __r_(__a)
2110{
2111 if (!__str.__is_long())
2112 __r_.first().__r = __str.__r_.first().__r;
2113 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002114 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00002115#if _LIBCPP_DEBUG_LEVEL >= 2
2116 __get_db()->__insert_c(this);
2117#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002118}
2119
Howard Hinnant73d21a42010-09-04 23:28:19 +00002120#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002121
2122template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002123inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002124basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +00002125#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002126 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clow7b193f72015-06-03 19:56:43 +00002127#else
2128 _NOEXCEPT
2129#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00002130 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002131{
2132 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:05 +00002133#if _LIBCPP_DEBUG_LEVEL >= 2
2134 __get_db()->__insert_c(this);
2135 if (__is_long())
2136 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002137#endif
2138}
2139
2140template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002141inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002142basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002143 : __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002144{
Marshall Clowd5549cc2014-07-17 15:32:20 +00002145 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002146 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd5549cc2014-07-17 15:32:20 +00002147 else
2148 {
2149 __r_.first().__r = __str.__r_.first().__r;
2150 __str.__zero();
2151 }
Howard Hinnant499cea12013-08-23 17:37:05 +00002152#if _LIBCPP_DEBUG_LEVEL >= 2
2153 __get_db()->__insert_c(this);
2154 if (__is_long())
2155 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002156#endif
2157}
2158
Howard Hinnant73d21a42010-09-04 23:28:19 +00002159#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002160
2161template <class _CharT, class _Traits, class _Allocator>
2162void
2163basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
2164{
2165 if (__n > max_size())
2166 this->__throw_length_error();
2167 pointer __p;
2168 if (__n < __min_cap)
2169 {
2170 __set_short_size(__n);
2171 __p = __get_short_pointer();
2172 }
2173 else
2174 {
2175 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002176 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002177 __set_long_pointer(__p);
2178 __set_long_cap(__cap+1);
2179 __set_long_size(__n);
2180 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002181 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002182 traits_type::assign(__p[__n], value_type());
2183}
2184
2185template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002186inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002187basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
2188{
2189 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00002190#if _LIBCPP_DEBUG_LEVEL >= 2
2191 __get_db()->__insert_c(this);
2192#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002193}
2194
2195template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002196inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002197basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
2198 : __r_(__a)
2199{
2200 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00002201#if _LIBCPP_DEBUG_LEVEL >= 2
2202 __get_db()->__insert_c(this);
2203#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002204}
2205
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002206template <class _CharT, class _Traits, class _Allocator>
2207basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
2208 const allocator_type& __a)
2209 : __r_(__a)
2210{
2211 size_type __str_sz = __str.size();
2212 if (__pos > __str_sz)
2213 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002214 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant499cea12013-08-23 17:37:05 +00002215#if _LIBCPP_DEBUG_LEVEL >= 2
2216 __get_db()->__insert_c(this);
2217#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002218}
2219
2220template <class _CharT, class _Traits, class _Allocator>
2221template <class _InputIterator>
2222typename enable_if
2223<
Marshall Clowdf9db312016-01-13 21:54:34 +00002224 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002225 void
2226>::type
2227basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2228{
2229 __zero();
2230#ifndef _LIBCPP_NO_EXCEPTIONS
2231 try
2232 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002233#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002234 for (; __first != __last; ++__first)
2235 push_back(*__first);
2236#ifndef _LIBCPP_NO_EXCEPTIONS
2237 }
2238 catch (...)
2239 {
2240 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002241 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002242 throw;
2243 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002244#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002245}
2246
2247template <class _CharT, class _Traits, class _Allocator>
2248template <class _ForwardIterator>
2249typename enable_if
2250<
2251 __is_forward_iterator<_ForwardIterator>::value,
2252 void
2253>::type
2254basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2255{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002256 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002257 if (__sz > max_size())
2258 this->__throw_length_error();
2259 pointer __p;
2260 if (__sz < __min_cap)
2261 {
2262 __set_short_size(__sz);
2263 __p = __get_short_pointer();
2264 }
2265 else
2266 {
2267 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002268 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002269 __set_long_pointer(__p);
2270 __set_long_cap(__cap+1);
2271 __set_long_size(__sz);
2272 }
Eric Fiselierb9919752014-10-27 19:28:20 +00002273 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002274 traits_type::assign(*__p, *__first);
2275 traits_type::assign(*__p, value_type());
2276}
2277
2278template <class _CharT, class _Traits, class _Allocator>
2279template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002280inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002281basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2282{
2283 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002284#if _LIBCPP_DEBUG_LEVEL >= 2
2285 __get_db()->__insert_c(this);
2286#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002287}
2288
2289template <class _CharT, class _Traits, class _Allocator>
2290template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002291inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002292basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2293 const allocator_type& __a)
2294 : __r_(__a)
2295{
2296 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00002297#if _LIBCPP_DEBUG_LEVEL >= 2
2298 __get_db()->__insert_c(this);
2299#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002300}
2301
Howard Hinnante3e32912011-08-12 21:56:02 +00002302#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2303
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002304template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002305inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002306basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
2307{
2308 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002309#if _LIBCPP_DEBUG_LEVEL >= 2
2310 __get_db()->__insert_c(this);
2311#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002312}
2313
2314template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002315inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002316basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
2317 : __r_(__a)
2318{
2319 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00002320#if _LIBCPP_DEBUG_LEVEL >= 2
2321 __get_db()->__insert_c(this);
2322#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002323}
2324
Howard Hinnante3e32912011-08-12 21:56:02 +00002325#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2326
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002327template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002328basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2329{
Howard Hinnant499cea12013-08-23 17:37:05 +00002330#if _LIBCPP_DEBUG_LEVEL >= 2
2331 __get_db()->__erase_c(this);
2332#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002333 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00002334 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002335}
2336
2337template <class _CharT, class _Traits, class _Allocator>
2338void
2339basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2340 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002341 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 +00002342{
2343 size_type __ms = max_size();
2344 if (__delta_cap > __ms - __old_cap - 1)
2345 this->__throw_length_error();
2346 pointer __old_p = __get_pointer();
2347 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002348 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002349 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002350 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002351 __invalidate_all_iterators();
2352 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002353 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2354 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002355 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002356 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002357 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2358 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002359 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2360 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002361 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002362 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002363 __set_long_pointer(__p);
2364 __set_long_cap(__cap+1);
2365 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2366 __set_long_size(__old_sz);
2367 traits_type::assign(__p[__old_sz], value_type());
2368}
2369
2370template <class _CharT, class _Traits, class _Allocator>
2371void
2372basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2373 size_type __n_copy, size_type __n_del, size_type __n_add)
2374{
2375 size_type __ms = max_size();
Marshall Clowecc8d7b2013-11-06 14:24:38 +00002376 if (__delta_cap > __ms - __old_cap)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002377 this->__throw_length_error();
2378 pointer __old_p = __get_pointer();
2379 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00002380 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002381 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00002382 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002383 __invalidate_all_iterators();
2384 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002385 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2386 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002387 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2388 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002389 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2390 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
2391 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002392 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002393 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002394 __set_long_pointer(__p);
2395 __set_long_cap(__cap+1);
2396}
2397
2398// assign
2399
2400template <class _CharT, class _Traits, class _Allocator>
2401basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002402basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002403{
Alp Tokerec34c482014-05-15 11:27:39 +00002404 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002405 size_type __cap = capacity();
2406 if (__cap >= __n)
2407 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002408 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002409 traits_type::move(__p, __s, __n);
2410 traits_type::assign(__p[__n], value_type());
2411 __set_size(__n);
2412 __invalidate_iterators_past(__n);
2413 }
2414 else
2415 {
2416 size_type __sz = size();
2417 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2418 }
2419 return *this;
2420}
2421
2422template <class _CharT, class _Traits, class _Allocator>
2423basic_string<_CharT, _Traits, _Allocator>&
2424basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2425{
2426 size_type __cap = capacity();
2427 if (__cap < __n)
2428 {
2429 size_type __sz = size();
2430 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2431 }
2432 else
2433 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002434 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002435 traits_type::assign(__p, __n, __c);
2436 traits_type::assign(__p[__n], value_type());
2437 __set_size(__n);
2438 return *this;
2439}
2440
2441template <class _CharT, class _Traits, class _Allocator>
2442basic_string<_CharT, _Traits, _Allocator>&
2443basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2444{
2445 pointer __p;
2446 if (__is_long())
2447 {
2448 __p = __get_long_pointer();
2449 __set_long_size(1);
2450 }
2451 else
2452 {
2453 __p = __get_short_pointer();
2454 __set_short_size(1);
2455 }
2456 traits_type::assign(*__p, __c);
2457 traits_type::assign(*++__p, value_type());
2458 __invalidate_iterators_past(1);
2459 return *this;
2460}
2461
2462template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00002463basic_string<_CharT, _Traits, _Allocator>&
2464basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2465{
2466 if (this != &__str)
2467 {
2468 __copy_assign_alloc(__str);
2469 assign(__str);
2470 }
2471 return *this;
2472}
2473
2474#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2475
2476template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002477inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002478void
2479basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002480 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002481{
2482 if (__alloc() != __str.__alloc())
2483 assign(__str);
2484 else
2485 __move_assign(__str, true_type());
2486}
2487
2488template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002489inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002490void
2491basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002492#if _LIBCPP_STD_VER > 14
2493 _NOEXCEPT
2494#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002495 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002496#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00002497{
2498 clear();
2499 shrink_to_fit();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00002500 __r_.first() = __str.__r_.first();
2501 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002502 __str.__zero();
2503}
2504
2505template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002506inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002507basic_string<_CharT, _Traits, _Allocator>&
2508basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002509 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnante32b5e22010-11-17 17:55:08 +00002510{
2511 __move_assign(__str, integral_constant<bool,
2512 __alloc_traits::propagate_on_container_move_assignment::value>());
2513 return *this;
2514}
2515
2516#endif
2517
2518template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002519template<class _InputIterator>
2520typename enable_if
2521<
Marshall Clowdf9db312016-01-13 21:54:34 +00002522 __is_exactly_input_iterator <_InputIterator>::value
2523 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002524 basic_string<_CharT, _Traits, _Allocator>&
2525>::type
2526basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2527{
Marshall Clowdf9db312016-01-13 21:54:34 +00002528 basic_string __temp(__first, __last, __alloc());
2529 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002530 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002531}
2532
2533template <class _CharT, class _Traits, class _Allocator>
2534template<class _ForwardIterator>
2535typename enable_if
2536<
Marshall Clowdf9db312016-01-13 21:54:34 +00002537 __is_forward_iterator<_ForwardIterator>::value
2538 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002539 basic_string<_CharT, _Traits, _Allocator>&
2540>::type
2541basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2542{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002543 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002544 size_type __cap = capacity();
2545 if (__cap < __n)
2546 {
2547 size_type __sz = size();
2548 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2549 }
2550 else
2551 __invalidate_iterators_past(__n);
2552 pointer __p = __get_pointer();
2553 for (; __first != __last; ++__first, ++__p)
2554 traits_type::assign(*__p, *__first);
2555 traits_type::assign(*__p, value_type());
2556 __set_size(__n);
2557 return *this;
2558}
2559
2560template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002561inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002562basic_string<_CharT, _Traits, _Allocator>&
2563basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str)
2564{
2565 return assign(__str.data(), __str.size());
2566}
2567
2568template <class _CharT, class _Traits, class _Allocator>
2569basic_string<_CharT, _Traits, _Allocator>&
2570basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2571{
2572 size_type __sz = __str.size();
2573 if (__pos > __sz)
2574 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002575 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002576}
2577
2578template <class _CharT, class _Traits, class _Allocator>
2579basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002580basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002581{
Alp Tokerec34c482014-05-15 11:27:39 +00002582 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002583 return assign(__s, traits_type::length(__s));
2584}
2585
2586// append
2587
2588template <class _CharT, class _Traits, class _Allocator>
2589basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002590basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002591{
Alp Tokerec34c482014-05-15 11:27:39 +00002592 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002593 size_type __cap = capacity();
2594 size_type __sz = size();
2595 if (__cap - __sz >= __n)
2596 {
2597 if (__n)
2598 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002599 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002600 traits_type::copy(__p + __sz, __s, __n);
2601 __sz += __n;
2602 __set_size(__sz);
2603 traits_type::assign(__p[__sz], value_type());
2604 }
2605 }
2606 else
2607 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2608 return *this;
2609}
2610
2611template <class _CharT, class _Traits, class _Allocator>
2612basic_string<_CharT, _Traits, _Allocator>&
2613basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2614{
2615 if (__n)
2616 {
2617 size_type __cap = capacity();
2618 size_type __sz = size();
2619 if (__cap - __sz < __n)
2620 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2621 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002622 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002623 __sz += __n;
2624 __set_size(__sz);
2625 traits_type::assign(__p[__sz], value_type());
2626 }
2627 return *this;
2628}
2629
2630template <class _CharT, class _Traits, class _Allocator>
2631void
2632basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2633{
Howard Hinnant15467182013-04-30 21:44:48 +00002634 bool __is_short = !__is_long();
2635 size_type __cap;
2636 size_type __sz;
2637 if (__is_short)
2638 {
2639 __cap = __min_cap - 1;
2640 __sz = __get_short_size();
2641 }
2642 else
2643 {
2644 __cap = __get_long_cap() - 1;
2645 __sz = __get_long_size();
2646 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002647 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002648 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002649 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002650 __is_short = !__is_long();
2651 }
2652 pointer __p;
2653 if (__is_short)
2654 {
2655 __p = __get_short_pointer() + __sz;
2656 __set_short_size(__sz+1);
2657 }
2658 else
2659 {
2660 __p = __get_long_pointer() + __sz;
2661 __set_long_size(__sz+1);
2662 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002663 traits_type::assign(*__p, __c);
2664 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002665}
2666
2667template <class _CharT, class _Traits, class _Allocator>
2668template<class _InputIterator>
2669typename enable_if
2670<
Marshall Clowdf9db312016-01-13 21:54:34 +00002671 __is_exactly_input_iterator<_InputIterator>::value
2672 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002673 basic_string<_CharT, _Traits, _Allocator>&
2674>::type
2675basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
2676{
Marshall Clowdf9db312016-01-13 21:54:34 +00002677 basic_string __temp (__first, __last, __alloc());
2678 append(__temp.data(), __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002679 return *this;
2680}
2681
2682template <class _CharT, class _Traits, class _Allocator>
2683template<class _ForwardIterator>
2684typename enable_if
2685<
Marshall Clowdf9db312016-01-13 21:54:34 +00002686 __is_forward_iterator<_ForwardIterator>::value
2687 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002688 basic_string<_CharT, _Traits, _Allocator>&
2689>::type
2690basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
2691{
2692 size_type __sz = size();
2693 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002694 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002695 if (__n)
2696 {
2697 if (__cap - __sz < __n)
2698 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2699 pointer __p = __get_pointer() + __sz;
2700 for (; __first != __last; ++__p, ++__first)
2701 traits_type::assign(*__p, *__first);
2702 traits_type::assign(*__p, value_type());
2703 __set_size(__sz + __n);
2704 }
2705 return *this;
2706}
2707
2708template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002709inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002710basic_string<_CharT, _Traits, _Allocator>&
2711basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2712{
2713 return append(__str.data(), __str.size());
2714}
2715
2716template <class _CharT, class _Traits, class _Allocator>
2717basic_string<_CharT, _Traits, _Allocator>&
2718basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2719{
2720 size_type __sz = __str.size();
2721 if (__pos > __sz)
2722 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002723 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002724}
2725
2726template <class _CharT, class _Traits, class _Allocator>
2727basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002728basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002729{
Alp Tokerec34c482014-05-15 11:27:39 +00002730 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002731 return append(__s, traits_type::length(__s));
2732}
2733
2734// insert
2735
2736template <class _CharT, class _Traits, class _Allocator>
2737basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002738basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002739{
Alp Tokerec34c482014-05-15 11:27:39 +00002740 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002741 size_type __sz = size();
2742 if (__pos > __sz)
2743 this->__throw_out_of_range();
2744 size_type __cap = capacity();
2745 if (__cap - __sz >= __n)
2746 {
2747 if (__n)
2748 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002749 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002750 size_type __n_move = __sz - __pos;
2751 if (__n_move != 0)
2752 {
2753 if (__p + __pos <= __s && __s < __p + __sz)
2754 __s += __n;
2755 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2756 }
2757 traits_type::move(__p + __pos, __s, __n);
2758 __sz += __n;
2759 __set_size(__sz);
2760 traits_type::assign(__p[__sz], value_type());
2761 }
2762 }
2763 else
2764 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2765 return *this;
2766}
2767
2768template <class _CharT, class _Traits, class _Allocator>
2769basic_string<_CharT, _Traits, _Allocator>&
2770basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2771{
2772 size_type __sz = size();
2773 if (__pos > __sz)
2774 this->__throw_out_of_range();
2775 if (__n)
2776 {
2777 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002778 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002779 if (__cap - __sz >= __n)
2780 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002781 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002782 size_type __n_move = __sz - __pos;
2783 if (__n_move != 0)
2784 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2785 }
2786 else
2787 {
2788 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002789 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002790 }
2791 traits_type::assign(__p + __pos, __n, __c);
2792 __sz += __n;
2793 __set_size(__sz);
2794 traits_type::assign(__p[__sz], value_type());
2795 }
2796 return *this;
2797}
2798
2799template <class _CharT, class _Traits, class _Allocator>
2800template<class _InputIterator>
2801typename enable_if
2802<
Marshall Clowdf9db312016-01-13 21:54:34 +00002803 __is_exactly_input_iterator<_InputIterator>::value
2804 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2805 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002806>::type
2807basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2808{
Howard Hinnant499cea12013-08-23 17:37:05 +00002809#if _LIBCPP_DEBUG_LEVEL >= 2
2810 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2811 "string::insert(iterator, range) called with an iterator not"
2812 " referring to this string");
2813#endif
Marshall Clowdf9db312016-01-13 21:54:34 +00002814 basic_string __temp(__first, __last, __alloc());
2815 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002816}
2817
2818template <class _CharT, class _Traits, class _Allocator>
2819template<class _ForwardIterator>
2820typename enable_if
2821<
Marshall Clowdf9db312016-01-13 21:54:34 +00002822 __is_forward_iterator<_ForwardIterator>::value
2823 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002824 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2825>::type
2826basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2827{
Howard Hinnant499cea12013-08-23 17:37:05 +00002828#if _LIBCPP_DEBUG_LEVEL >= 2
2829 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2830 "string::insert(iterator, range) called with an iterator not"
2831 " referring to this string");
2832#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002833 size_type __ip = static_cast<size_type>(__pos - begin());
2834 size_type __sz = size();
2835 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002836 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002837 if (__n)
2838 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002839 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002840 if (__cap - __sz >= __n)
2841 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002842 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002843 size_type __n_move = __sz - __ip;
2844 if (__n_move != 0)
2845 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2846 }
2847 else
2848 {
2849 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002850 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002851 }
2852 __sz += __n;
2853 __set_size(__sz);
2854 traits_type::assign(__p[__sz], value_type());
2855 for (__p += __ip; __first != __last; ++__p, ++__first)
2856 traits_type::assign(*__p, *__first);
2857 }
2858 return begin() + __ip;
2859}
2860
2861template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002862inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002863basic_string<_CharT, _Traits, _Allocator>&
2864basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2865{
2866 return insert(__pos1, __str.data(), __str.size());
2867}
2868
2869template <class _CharT, class _Traits, class _Allocator>
2870basic_string<_CharT, _Traits, _Allocator>&
2871basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2872 size_type __pos2, size_type __n)
2873{
2874 size_type __str_sz = __str.size();
2875 if (__pos2 > __str_sz)
2876 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002877 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002878}
2879
2880template <class _CharT, class _Traits, class _Allocator>
2881basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002882basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002883{
Alp Tokerec34c482014-05-15 11:27:39 +00002884 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002885 return insert(__pos, __s, traits_type::length(__s));
2886}
2887
2888template <class _CharT, class _Traits, class _Allocator>
2889typename basic_string<_CharT, _Traits, _Allocator>::iterator
2890basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2891{
2892 size_type __ip = static_cast<size_type>(__pos - begin());
2893 size_type __sz = size();
2894 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002895 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002896 if (__cap == __sz)
2897 {
2898 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002899 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002900 }
2901 else
2902 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002903 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002904 size_type __n_move = __sz - __ip;
2905 if (__n_move != 0)
2906 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2907 }
2908 traits_type::assign(__p[__ip], __c);
2909 traits_type::assign(__p[++__sz], value_type());
2910 __set_size(__sz);
2911 return begin() + static_cast<difference_type>(__ip);
2912}
2913
2914template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002915inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002916typename basic_string<_CharT, _Traits, _Allocator>::iterator
2917basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2918{
Howard Hinnant499cea12013-08-23 17:37:05 +00002919#if _LIBCPP_DEBUG_LEVEL >= 2
2920 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2921 "string::insert(iterator, n, value) called with an iterator not"
2922 " referring to this string");
2923#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002924 difference_type __p = __pos - begin();
2925 insert(static_cast<size_type>(__p), __n, __c);
2926 return begin() + __p;
2927}
2928
2929// replace
2930
2931template <class _CharT, class _Traits, class _Allocator>
2932basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002933basic_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 +00002934{
Alp Tokerec34c482014-05-15 11:27:39 +00002935 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002936 size_type __sz = size();
2937 if (__pos > __sz)
2938 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002939 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002940 size_type __cap = capacity();
2941 if (__cap - __sz + __n1 >= __n2)
2942 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002943 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002944 if (__n1 != __n2)
2945 {
2946 size_type __n_move = __sz - __pos - __n1;
2947 if (__n_move != 0)
2948 {
2949 if (__n1 > __n2)
2950 {
2951 traits_type::move(__p + __pos, __s, __n2);
2952 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2953 goto __finish;
2954 }
2955 if (__p + __pos < __s && __s < __p + __sz)
2956 {
2957 if (__p + __pos + __n1 <= __s)
2958 __s += __n2 - __n1;
2959 else // __p + __pos < __s < __p + __pos + __n1
2960 {
2961 traits_type::move(__p + __pos, __s, __n1);
2962 __pos += __n1;
2963 __s += __n2;
2964 __n2 -= __n1;
2965 __n1 = 0;
2966 }
2967 }
2968 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2969 }
2970 }
2971 traits_type::move(__p + __pos, __s, __n2);
2972__finish:
2973 __sz += __n2 - __n1;
2974 __set_size(__sz);
2975 __invalidate_iterators_past(__sz);
2976 traits_type::assign(__p[__sz], value_type());
2977 }
2978 else
2979 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2980 return *this;
2981}
2982
2983template <class _CharT, class _Traits, class _Allocator>
2984basic_string<_CharT, _Traits, _Allocator>&
2985basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
2986{
2987 size_type __sz = size();
2988 if (__pos > __sz)
2989 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002990 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002991 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002992 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002993 if (__cap - __sz + __n1 >= __n2)
2994 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002995 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002996 if (__n1 != __n2)
2997 {
2998 size_type __n_move = __sz - __pos - __n1;
2999 if (__n_move != 0)
3000 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
3001 }
3002 }
3003 else
3004 {
3005 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003006 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003007 }
3008 traits_type::assign(__p + __pos, __n2, __c);
3009 __sz += __n2 - __n1;
3010 __set_size(__sz);
3011 __invalidate_iterators_past(__sz);
3012 traits_type::assign(__p[__sz], value_type());
3013 return *this;
3014}
3015
3016template <class _CharT, class _Traits, class _Allocator>
3017template<class _InputIterator>
3018typename enable_if
3019<
3020 __is_input_iterator<_InputIterator>::value,
3021 basic_string<_CharT, _Traits, _Allocator>&
3022>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00003023basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003024 _InputIterator __j1, _InputIterator __j2)
3025{
Marshall Clowdf9db312016-01-13 21:54:34 +00003026 basic_string __temp(__j1, __j2, __alloc());
3027 return this->replace(__i1, __i2, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003028}
3029
3030template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003031inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003032basic_string<_CharT, _Traits, _Allocator>&
3033basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
3034{
3035 return replace(__pos1, __n1, __str.data(), __str.size());
3036}
3037
3038template <class _CharT, class _Traits, class _Allocator>
3039basic_string<_CharT, _Traits, _Allocator>&
3040basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
3041 size_type __pos2, size_type __n2)
3042{
3043 size_type __str_sz = __str.size();
3044 if (__pos2 > __str_sz)
3045 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003046 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003047}
3048
3049template <class _CharT, class _Traits, class _Allocator>
3050basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003051basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003052{
Alp Tokerec34c482014-05-15 11:27:39 +00003053 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003054 return replace(__pos, __n1, __s, traits_type::length(__s));
3055}
3056
3057template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003058inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003059basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00003060basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003061{
3062 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
3063 __str.data(), __str.size());
3064}
3065
3066template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003067inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003068basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003069basic_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 +00003070{
3071 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
3072}
3073
3074template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003075inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003076basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003077basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003078{
3079 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
3080}
3081
3082template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003083inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003084basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00003085basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003086{
3087 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
3088}
3089
3090// erase
3091
3092template <class _CharT, class _Traits, class _Allocator>
3093basic_string<_CharT, _Traits, _Allocator>&
3094basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
3095{
3096 size_type __sz = size();
3097 if (__pos > __sz)
3098 this->__throw_out_of_range();
3099 if (__n)
3100 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003101 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00003102 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003103 size_type __n_move = __sz - __pos - __n;
3104 if (__n_move != 0)
3105 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
3106 __sz -= __n;
3107 __set_size(__sz);
3108 __invalidate_iterators_past(__sz);
3109 traits_type::assign(__p[__sz], value_type());
3110 }
3111 return *this;
3112}
3113
3114template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003115inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003116typename basic_string<_CharT, _Traits, _Allocator>::iterator
3117basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
3118{
Howard Hinnant499cea12013-08-23 17:37:05 +00003119#if _LIBCPP_DEBUG_LEVEL >= 2
3120 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
3121 "string::erase(iterator) called with an iterator not"
3122 " referring to this string");
3123#endif
3124 _LIBCPP_ASSERT(__pos != end(),
3125 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003126 iterator __b = begin();
3127 size_type __r = static_cast<size_type>(__pos - __b);
3128 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00003129 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003130}
3131
3132template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003133inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003134typename basic_string<_CharT, _Traits, _Allocator>::iterator
3135basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
3136{
Howard Hinnant499cea12013-08-23 17:37:05 +00003137#if _LIBCPP_DEBUG_LEVEL >= 2
3138 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
3139 "string::erase(iterator, iterator) called with an iterator not"
3140 " referring to this string");
3141#endif
3142 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003143 iterator __b = begin();
3144 size_type __r = static_cast<size_type>(__first - __b);
3145 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00003146 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003147}
3148
3149template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003150inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003151void
3152basic_string<_CharT, _Traits, _Allocator>::pop_back()
3153{
Howard Hinnant499cea12013-08-23 17:37:05 +00003154 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003155 size_type __sz;
3156 if (__is_long())
3157 {
3158 __sz = __get_long_size() - 1;
3159 __set_long_size(__sz);
3160 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3161 }
3162 else
3163 {
3164 __sz = __get_short_size() - 1;
3165 __set_short_size(__sz);
3166 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3167 }
3168 __invalidate_iterators_past(__sz);
3169}
3170
3171template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003172inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003173void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003174basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003175{
3176 __invalidate_all_iterators();
3177 if (__is_long())
3178 {
3179 traits_type::assign(*__get_long_pointer(), value_type());
3180 __set_long_size(0);
3181 }
3182 else
3183 {
3184 traits_type::assign(*__get_short_pointer(), value_type());
3185 __set_short_size(0);
3186 }
3187}
3188
3189template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003190inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003191void
3192basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3193{
3194 if (__is_long())
3195 {
3196 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3197 __set_long_size(__pos);
3198 }
3199 else
3200 {
3201 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3202 __set_short_size(__pos);
3203 }
3204 __invalidate_iterators_past(__pos);
3205}
3206
3207template <class _CharT, class _Traits, class _Allocator>
3208void
3209basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3210{
3211 size_type __sz = size();
3212 if (__n > __sz)
3213 append(__n - __sz, __c);
3214 else
3215 __erase_to_end(__n);
3216}
3217
3218template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003219inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003220typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003221basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003222{
Howard Hinnante32b5e22010-11-17 17:55:08 +00003223 size_type __m = __alloc_traits::max_size(__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003224#if _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:08 +00003225 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003226#else
Marshall Clow09f85502013-10-31 17:23:08 +00003227 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003228#endif
3229}
3230
3231template <class _CharT, class _Traits, class _Allocator>
3232void
3233basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
3234{
3235 if (__res_arg > max_size())
3236 this->__throw_length_error();
3237 size_type __cap = capacity();
3238 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003239 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003240 __res_arg = __recommend(__res_arg);
3241 if (__res_arg != __cap)
3242 {
3243 pointer __new_data, __p;
3244 bool __was_long, __now_long;
3245 if (__res_arg == __min_cap - 1)
3246 {
3247 __was_long = true;
3248 __now_long = false;
3249 __new_data = __get_short_pointer();
3250 __p = __get_long_pointer();
3251 }
3252 else
3253 {
3254 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003255 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003256 else
3257 {
3258 #ifndef _LIBCPP_NO_EXCEPTIONS
3259 try
3260 {
Howard Hinnant324bb032010-08-22 00:02:43 +00003261 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00003262 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003263 #ifndef _LIBCPP_NO_EXCEPTIONS
3264 }
3265 catch (...)
3266 {
3267 return;
3268 }
Howard Hinnant324bb032010-08-22 00:02:43 +00003269 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003270 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003271 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00003272 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003273 }
3274 __now_long = true;
3275 __was_long = __is_long();
3276 __p = __get_pointer();
3277 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003278 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
3279 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003280 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00003281 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003282 if (__now_long)
3283 {
3284 __set_long_cap(__res_arg+1);
3285 __set_long_size(__sz);
3286 __set_long_pointer(__new_data);
3287 }
3288 else
3289 __set_short_size(__sz);
3290 __invalidate_all_iterators();
3291 }
3292}
3293
3294template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003295inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003296typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3297basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const
3298{
Howard Hinnant499cea12013-08-23 17:37:05 +00003299 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003300 return *(data() + __pos);
3301}
3302
3303template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003304inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003305typename basic_string<_CharT, _Traits, _Allocator>::reference
3306basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos)
3307{
Howard Hinnant499cea12013-08-23 17:37:05 +00003308 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003309 return *(__get_pointer() + __pos);
3310}
3311
3312template <class _CharT, class _Traits, class _Allocator>
3313typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3314basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3315{
3316 if (__n >= size())
3317 this->__throw_out_of_range();
3318 return (*this)[__n];
3319}
3320
3321template <class _CharT, class _Traits, class _Allocator>
3322typename basic_string<_CharT, _Traits, _Allocator>::reference
3323basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3324{
3325 if (__n >= size())
3326 this->__throw_out_of_range();
3327 return (*this)[__n];
3328}
3329
3330template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003331inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003332typename basic_string<_CharT, _Traits, _Allocator>::reference
3333basic_string<_CharT, _Traits, _Allocator>::front()
3334{
Howard Hinnant499cea12013-08-23 17:37:05 +00003335 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003336 return *__get_pointer();
3337}
3338
3339template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003340inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003341typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3342basic_string<_CharT, _Traits, _Allocator>::front() const
3343{
Howard Hinnant499cea12013-08-23 17:37:05 +00003344 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003345 return *data();
3346}
3347
3348template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003349inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003350typename basic_string<_CharT, _Traits, _Allocator>::reference
3351basic_string<_CharT, _Traits, _Allocator>::back()
3352{
Howard Hinnant499cea12013-08-23 17:37:05 +00003353 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003354 return *(__get_pointer() + size() - 1);
3355}
3356
3357template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003358inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003359typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3360basic_string<_CharT, _Traits, _Allocator>::back() const
3361{
Howard Hinnant499cea12013-08-23 17:37:05 +00003362 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003363 return *(data() + size() - 1);
3364}
3365
3366template <class _CharT, class _Traits, class _Allocator>
3367typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003368basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003369{
3370 size_type __sz = size();
3371 if (__pos > __sz)
3372 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003373 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003374 traits_type::copy(__s, data() + __pos, __rlen);
3375 return __rlen;
3376}
3377
3378template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003379inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003380basic_string<_CharT, _Traits, _Allocator>
3381basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3382{
3383 return basic_string(*this, __pos, __n, __alloc());
3384}
3385
3386template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003387inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003388void
3389basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00003390#if _LIBCPP_STD_VER >= 14
3391 _NOEXCEPT
3392#else
3393 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3394 __is_nothrow_swappable<allocator_type>::value)
3395#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003396{
Howard Hinnant499cea12013-08-23 17:37:05 +00003397#if _LIBCPP_DEBUG_LEVEL >= 2
3398 if (!__is_long())
3399 __get_db()->__invalidate_all(this);
3400 if (!__str.__is_long())
3401 __get_db()->__invalidate_all(&__str);
3402 __get_db()->swap(this, &__str);
3403#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00003404 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow7d914d12015-07-13 20:04:56 +00003405 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003406}
3407
3408// find
3409
3410template <class _Traits>
3411struct _LIBCPP_HIDDEN __traits_eq
3412{
3413 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003414 _LIBCPP_INLINE_VISIBILITY
3415 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3416 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003417};
3418
3419template<class _CharT, class _Traits, class _Allocator>
3420typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003421basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003422 size_type __pos,
3423 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003424{
Alp Tokerec34c482014-05-15 11:27:39 +00003425 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003426 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003427 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003428}
3429
3430template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003431inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003432typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003433basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3434 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003435{
Marshall Clow37025e12014-06-10 18:51:55 +00003436 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003437 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003438}
3439
3440template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003441inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003442typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003443basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003444 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003445{
Alp Tokerec34c482014-05-15 11:27:39 +00003446 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003447 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003448 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003449}
3450
3451template<class _CharT, class _Traits, class _Allocator>
3452typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003453basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3454 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003455{
Marshall Clow37025e12014-06-10 18:51:55 +00003456 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003457 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003458}
3459
3460// rfind
3461
3462template<class _CharT, class _Traits, class _Allocator>
3463typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003464basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003465 size_type __pos,
3466 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003467{
Alp Tokerec34c482014-05-15 11:27:39 +00003468 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003469 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003470 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003471}
3472
3473template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003474inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003475typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003476basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3477 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003478{
Marshall Clow37025e12014-06-10 18:51:55 +00003479 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003480 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003481}
3482
3483template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003484inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003485typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003486basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003487 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003488{
Alp Tokerec34c482014-05-15 11:27:39 +00003489 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003490 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003491 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003492}
3493
3494template<class _CharT, class _Traits, class _Allocator>
3495typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003496basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3497 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003498{
Marshall Clow37025e12014-06-10 18:51:55 +00003499 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003500 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003501}
3502
3503// find_first_of
3504
3505template<class _CharT, class _Traits, class _Allocator>
3506typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003507basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003508 size_type __pos,
3509 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003510{
Alp Tokerec34c482014-05-15 11:27:39 +00003511 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003512 return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003513 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003514}
3515
3516template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003517inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003518typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003519basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3520 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003521{
Marshall Clow37025e12014-06-10 18:51:55 +00003522 return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003523 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003524}
3525
3526template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003527inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003528typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003529basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003530 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003531{
Alp Tokerec34c482014-05-15 11:27:39 +00003532 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003533 return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003534 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003535}
3536
3537template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003538inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003539typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003540basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3541 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003542{
3543 return find(__c, __pos);
3544}
3545
3546// find_last_of
3547
3548template<class _CharT, class _Traits, class _Allocator>
3549typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003550basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003551 size_type __pos,
3552 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003553{
Alp Tokerec34c482014-05-15 11:27:39 +00003554 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003555 return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003556 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003557}
3558
3559template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003560inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003561typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003562basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3563 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003564{
Marshall Clow37025e12014-06-10 18:51:55 +00003565 return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003566 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003567}
3568
3569template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003570inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003571typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003572basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003573 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003574{
Alp Tokerec34c482014-05-15 11:27:39 +00003575 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003576 return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003577 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003578}
3579
3580template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003581inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003582typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003583basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3584 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003585{
3586 return rfind(__c, __pos);
3587}
3588
3589// find_first_not_of
3590
3591template<class _CharT, class _Traits, class _Allocator>
3592typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003593basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003594 size_type __pos,
3595 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003596{
Alp Tokerec34c482014-05-15 11:27:39 +00003597 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003598 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003599 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003600}
3601
3602template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003603inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003604typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003605basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3606 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003607{
Marshall Clow37025e12014-06-10 18:51:55 +00003608 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003609 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003610}
3611
3612template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003613inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003614typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003615basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003616 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003617{
Alp Tokerec34c482014-05-15 11:27:39 +00003618 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003619 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003620 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003621}
3622
3623template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003624inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003625typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003626basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3627 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003628{
Marshall Clow37025e12014-06-10 18:51:55 +00003629 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003630 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003631}
3632
3633// find_last_not_of
3634
3635template<class _CharT, class _Traits, class _Allocator>
3636typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003637basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003638 size_type __pos,
3639 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003640{
Alp Tokerec34c482014-05-15 11:27:39 +00003641 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003642 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003643 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003644}
3645
3646template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003647inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003648typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003649basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3650 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003651{
Marshall Clow37025e12014-06-10 18:51:55 +00003652 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003653 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003654}
3655
3656template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003657inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003658typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003659basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003660 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003661{
Alp Tokerec34c482014-05-15 11:27:39 +00003662 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow37025e12014-06-10 18:51:55 +00003663 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003664 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003665}
3666
3667template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003668inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003669typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003670basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3671 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003672{
Marshall Clow37025e12014-06-10 18:51:55 +00003673 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003674 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003675}
3676
3677// compare
3678
3679template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003680inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003681int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003682basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003683{
Howard Hinnantfa06d752011-07-24 21:45:06 +00003684 size_t __lhs_sz = size();
3685 size_t __rhs_sz = __str.size();
3686 int __result = traits_type::compare(data(), __str.data(),
3687 _VSTD::min(__lhs_sz, __rhs_sz));
3688 if (__result != 0)
3689 return __result;
3690 if (__lhs_sz < __rhs_sz)
3691 return -1;
3692 if (__lhs_sz > __rhs_sz)
3693 return 1;
3694 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003695}
3696
3697template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003698inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003699int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003700basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3701 size_type __n1,
3702 const basic_string& __str) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003703{
3704 return compare(__pos1, __n1, __str.data(), __str.size());
3705}
3706
3707template <class _CharT, class _Traits, class _Allocator>
3708int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003709basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3710 size_type __n1,
3711 const basic_string& __str,
3712 size_type __pos2,
3713 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003714{
3715 size_type __sz = __str.size();
3716 if (__pos2 > __sz)
3717 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003718 return compare(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003719 __sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003720}
3721
3722template <class _CharT, class _Traits, class _Allocator>
3723int
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003724basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003725{
Alp Tokerec34c482014-05-15 11:27:39 +00003726 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003727 return compare(0, npos, __s, traits_type::length(__s));
3728}
3729
3730template <class _CharT, class _Traits, class _Allocator>
3731int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003732basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3733 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003734 const value_type* __s) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003735{
Alp Tokerec34c482014-05-15 11:27:39 +00003736 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003737 return compare(__pos1, __n1, __s, traits_type::length(__s));
3738}
3739
3740template <class _CharT, class _Traits, class _Allocator>
3741int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003742basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3743 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003744 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003745 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003746{
Alp Tokerec34c482014-05-15 11:27:39 +00003747 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003748 size_type __sz = size();
3749 if (__pos1 > __sz || __n2 == npos)
3750 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003751 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3752 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003753 if (__r == 0)
3754 {
3755 if (__rlen < __n2)
3756 __r = -1;
3757 else if (__rlen > __n2)
3758 __r = 1;
3759 }
3760 return __r;
3761}
3762
3763// __invariants
3764
3765template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003766inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003767bool
3768basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3769{
3770 if (size() > capacity())
3771 return false;
3772 if (capacity() < __min_cap - 1)
3773 return false;
3774 if (data() == 0)
3775 return false;
3776 if (data()[size()] != value_type(0))
3777 return false;
3778 return true;
3779}
3780
3781// operator==
3782
3783template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003784inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003785bool
3786operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003787 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003788{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003789 size_t __lhs_sz = __lhs.size();
3790 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3791 __rhs.data(),
3792 __lhs_sz) == 0;
3793}
3794
3795template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003796inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:13 +00003797bool
3798operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3799 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3800{
3801 size_t __lhs_sz = __lhs.size();
3802 if (__lhs_sz != __rhs.size())
3803 return false;
3804 const char* __lp = __lhs.data();
3805 const char* __rp = __rhs.data();
3806 if (__lhs.__is_long())
3807 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3808 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3809 if (*__lp != *__rp)
3810 return false;
3811 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003812}
3813
3814template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003815inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003816bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003817operator==(const _CharT* __lhs,
3818 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003819{
Eric Fiselier4f241822015-08-28 03:02:37 +00003820 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3821 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3822 size_t __lhs_len = _Traits::length(__lhs);
3823 if (__lhs_len != __rhs.size()) return false;
3824 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003825}
3826
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003827template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003828inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003829bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003830operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3831 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003832{
Eric Fiselier4f241822015-08-28 03:02:37 +00003833 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3834 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3835 size_t __rhs_len = _Traits::length(__rhs);
3836 if (__rhs_len != __lhs.size()) return false;
3837 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003838}
3839
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003840// operator!=
3841
Howard Hinnant324bb032010-08-22 00:02:43 +00003842template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003843inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003844bool
3845operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003846 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003847{
3848 return !(__lhs == __rhs);
3849}
3850
3851template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003852inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003853bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003854operator!=(const _CharT* __lhs,
3855 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003856{
3857 return !(__lhs == __rhs);
3858}
3859
3860template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003861inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003862bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003863operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3864 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003865{
3866 return !(__lhs == __rhs);
3867}
3868
3869// operator<
3870
3871template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003872inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003873bool
3874operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003875 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003876{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003877 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003878}
3879
3880template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003881inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003882bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003883operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3884 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003885{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003886 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003887}
3888
3889template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003890inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003891bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003892operator< (const _CharT* __lhs,
3893 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003894{
3895 return __rhs.compare(__lhs) > 0;
3896}
3897
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003898// operator>
3899
3900template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003901inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003902bool
3903operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003904 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003905{
3906 return __rhs < __lhs;
3907}
3908
3909template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003910inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003911bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003912operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3913 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003914{
3915 return __rhs < __lhs;
3916}
3917
3918template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003919inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003920bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003921operator> (const _CharT* __lhs,
3922 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003923{
3924 return __rhs < __lhs;
3925}
3926
3927// operator<=
3928
3929template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003930inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003931bool
3932operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003933 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003934{
3935 return !(__rhs < __lhs);
3936}
3937
3938template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003939inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003940bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003941operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3942 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003943{
3944 return !(__rhs < __lhs);
3945}
3946
3947template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003948inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003949bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003950operator<=(const _CharT* __lhs,
3951 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003952{
3953 return !(__rhs < __lhs);
3954}
3955
3956// operator>=
3957
3958template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003959inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003960bool
3961operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003962 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003963{
3964 return !(__lhs < __rhs);
3965}
3966
3967template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003968inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003969bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003970operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3971 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003972{
3973 return !(__lhs < __rhs);
3974}
3975
3976template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003977inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003978bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003979operator>=(const _CharT* __lhs,
3980 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003981{
3982 return !(__lhs < __rhs);
3983}
3984
3985// operator +
3986
3987template<class _CharT, class _Traits, class _Allocator>
3988basic_string<_CharT, _Traits, _Allocator>
3989operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3990 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3991{
3992 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3993 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3994 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3995 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3996 __r.append(__rhs.data(), __rhs_sz);
3997 return __r;
3998}
3999
4000template<class _CharT, class _Traits, class _Allocator>
4001basic_string<_CharT, _Traits, _Allocator>
4002operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4003{
4004 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4005 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
4006 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4007 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
4008 __r.append(__rhs.data(), __rhs_sz);
4009 return __r;
4010}
4011
4012template<class _CharT, class _Traits, class _Allocator>
4013basic_string<_CharT, _Traits, _Allocator>
4014operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4015{
4016 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
4017 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
4018 __r.__init(&__lhs, 1, 1 + __rhs_sz);
4019 __r.append(__rhs.data(), __rhs_sz);
4020 return __r;
4021}
4022
4023template<class _CharT, class _Traits, class _Allocator>
4024basic_string<_CharT, _Traits, _Allocator>
4025operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
4026{
4027 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4028 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4029 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
4030 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
4031 __r.append(__rhs, __rhs_sz);
4032 return __r;
4033}
4034
4035template<class _CharT, class _Traits, class _Allocator>
4036basic_string<_CharT, _Traits, _Allocator>
4037operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
4038{
4039 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4040 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4041 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
4042 __r.push_back(__rhs);
4043 return __r;
4044}
4045
Howard Hinnant73d21a42010-09-04 23:28:19 +00004046#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004047
4048template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004049inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004050basic_string<_CharT, _Traits, _Allocator>
4051operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4052{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004053 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004054}
4055
4056template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004057inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004058basic_string<_CharT, _Traits, _Allocator>
4059operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4060{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004061 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004062}
4063
4064template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004065inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004066basic_string<_CharT, _Traits, _Allocator>
4067operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4068{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004069 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004070}
4071
4072template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004073inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004074basic_string<_CharT, _Traits, _Allocator>
4075operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4076{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004077 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004078}
4079
4080template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004081inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004082basic_string<_CharT, _Traits, _Allocator>
4083operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4084{
4085 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004086 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004087}
4088
4089template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004090inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004091basic_string<_CharT, _Traits, _Allocator>
4092operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
4093{
Howard Hinnant0949eed2011-06-30 21:18:19 +00004094 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004095}
4096
4097template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004098inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004099basic_string<_CharT, _Traits, _Allocator>
4100operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
4101{
4102 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004103 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004104}
4105
Howard Hinnant73d21a42010-09-04 23:28:19 +00004106#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004107
4108// swap
4109
4110template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00004111inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004112void
Howard Hinnanta6119a82011-05-29 19:57:12 +00004113swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00004114 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4115 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004116{
4117 __lhs.swap(__rhs);
4118}
4119
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004120#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
4121
4122typedef basic_string<char16_t> u16string;
4123typedef basic_string<char32_t> u32string;
4124
Howard Hinnant324bb032010-08-22 00:02:43 +00004125#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004126
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004127_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4128_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4129_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4130_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4131_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004132
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004133_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
4134_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
4135_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004136
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004137_LIBCPP_FUNC_VIS string to_string(int __val);
4138_LIBCPP_FUNC_VIS string to_string(unsigned __val);
4139_LIBCPP_FUNC_VIS string to_string(long __val);
4140_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4141_LIBCPP_FUNC_VIS string to_string(long long __val);
4142_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4143_LIBCPP_FUNC_VIS string to_string(float __val);
4144_LIBCPP_FUNC_VIS string to_string(double __val);
4145_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004146
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004147_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4148_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4149_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4150_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4151_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004152
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004153_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
4154_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
4155_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004156
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004157_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4158_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4159_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4160_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4161_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4162_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4163_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4164_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4165_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00004166
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004167template<class _CharT, class _Traits, class _Allocator>
4168 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4169 basic_string<_CharT, _Traits, _Allocator>::npos;
4170
4171template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004172struct _LIBCPP_TYPE_VIS_ONLY hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004173 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
4174{
4175 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00004176 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004177};
4178
4179template<class _CharT, class _Traits, class _Allocator>
4180size_t
4181hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00004182 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004183{
Sean Huntaffd9e52011-07-29 23:31:56 +00004184 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004185}
4186
Howard Hinnant464aa5c2011-07-18 15:51:59 +00004187template<class _CharT, class _Traits, class _Allocator>
4188basic_ostream<_CharT, _Traits>&
4189operator<<(basic_ostream<_CharT, _Traits>& __os,
4190 const basic_string<_CharT, _Traits, _Allocator>& __str);
4191
4192template<class _CharT, class _Traits, class _Allocator>
4193basic_istream<_CharT, _Traits>&
4194operator>>(basic_istream<_CharT, _Traits>& __is,
4195 basic_string<_CharT, _Traits, _Allocator>& __str);
4196
4197template<class _CharT, class _Traits, class _Allocator>
4198basic_istream<_CharT, _Traits>&
4199getline(basic_istream<_CharT, _Traits>& __is,
4200 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4201
4202template<class _CharT, class _Traits, class _Allocator>
4203inline _LIBCPP_INLINE_VISIBILITY
4204basic_istream<_CharT, _Traits>&
4205getline(basic_istream<_CharT, _Traits>& __is,
4206 basic_string<_CharT, _Traits, _Allocator>& __str);
4207
4208#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4209
4210template<class _CharT, class _Traits, class _Allocator>
4211inline _LIBCPP_INLINE_VISIBILITY
4212basic_istream<_CharT, _Traits>&
4213getline(basic_istream<_CharT, _Traits>&& __is,
4214 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4215
4216template<class _CharT, class _Traits, class _Allocator>
4217inline _LIBCPP_INLINE_VISIBILITY
4218basic_istream<_CharT, _Traits>&
4219getline(basic_istream<_CharT, _Traits>&& __is,
4220 basic_string<_CharT, _Traits, _Allocator>& __str);
4221
4222#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4223
Howard Hinnant499cea12013-08-23 17:37:05 +00004224#if _LIBCPP_DEBUG_LEVEL >= 2
4225
4226template<class _CharT, class _Traits, class _Allocator>
4227bool
4228basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4229{
4230 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
4231 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
4232}
4233
4234template<class _CharT, class _Traits, class _Allocator>
4235bool
4236basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4237{
4238 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
4239 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
4240}
4241
4242template<class _CharT, class _Traits, class _Allocator>
4243bool
4244basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4245{
4246 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4247 return this->data() <= __p && __p <= this->data() + this->size();
4248}
4249
4250template<class _CharT, class _Traits, class _Allocator>
4251bool
4252basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4253{
4254 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4255 return this->data() <= __p && __p < this->data() + this->size();
4256}
4257
4258#endif // _LIBCPP_DEBUG_LEVEL >= 2
4259
Marshall Clow15234322013-07-23 17:05:24 +00004260#if _LIBCPP_STD_VER > 11
4261// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:32 +00004262inline namespace literals
Marshall Clow15234322013-07-23 17:05:24 +00004263{
4264 inline namespace string_literals
4265 {
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004266 inline _LIBCPP_INLINE_VISIBILITY
4267 basic_string<char> operator "" s( const char *__str, size_t __len )
4268 {
4269 return basic_string<char> (__str, __len);
4270 }
Marshall Clow15234322013-07-23 17:05:24 +00004271
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004272 inline _LIBCPP_INLINE_VISIBILITY
4273 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4274 {
4275 return basic_string<wchar_t> (__str, __len);
4276 }
Marshall Clow15234322013-07-23 17:05:24 +00004277
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004278 inline _LIBCPP_INLINE_VISIBILITY
4279 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4280 {
4281 return basic_string<char16_t> (__str, __len);
4282 }
Marshall Clow15234322013-07-23 17:05:24 +00004283
Howard Hinnantab61b2c2013-08-07 19:39:48 +00004284 inline _LIBCPP_INLINE_VISIBILITY
4285 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4286 {
4287 return basic_string<char32_t> (__str, __len);
4288 }
Marshall Clow15234322013-07-23 17:05:24 +00004289 }
4290}
4291#endif
4292
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004293_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<char>)
4294_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<wchar_t>)
Howard Hinnant499cea12013-08-23 17:37:05 +00004295_LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004296
4297_LIBCPP_END_NAMESPACE_STD
4298
4299#endif // _LIBCPP_STRING