blob: 7d7994eaca1b95083ba95a2016183de57c4c8e7d [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);
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000101 basic_string(const basic_string& str, size_type pos,
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000102 const allocator_type& a = allocator_type());
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000103 basic_string(const basic_string& str, size_type pos, size_type n,
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000104 const Allocator& a = Allocator());
Marshall Clowdb7fa112016-11-14 18:22:19 +0000105 template<class T>
106 basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000107 explicit basic_string(const basic_string_view<charT, traits> sv, const Allocator& a = Allocator());
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000108 basic_string(const value_type* s, const allocator_type& a = allocator_type());
109 basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000110 basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
111 template<class InputIterator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000112 basic_string(InputIterator begin, InputIterator end,
113 const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000114 basic_string(initializer_list<value_type>, const Allocator& = Allocator());
115 basic_string(const basic_string&, const Allocator&);
116 basic_string(basic_string&&, const Allocator&);
117
118 ~basic_string();
119
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000120 operator basic_string_view<charT, traits>() const noexcept;
121
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000122 basic_string& operator=(const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000123 basic_string& operator=(basic_string_view<charT, traits> sv);
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000124 basic_string& operator=(basic_string&& str)
125 noexcept(
Marshall Clowaf961ed2015-08-18 18:57:00 +0000126 allocator_type::propagate_on_container_move_assignment::value ||
127 allocator_type::is_always_equal::value ); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000128 basic_string& operator=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000129 basic_string& operator=(value_type c);
130 basic_string& operator=(initializer_list<value_type>);
131
Howard Hinnanta6119a82011-05-29 19:57:12 +0000132 iterator begin() noexcept;
133 const_iterator begin() const noexcept;
134 iterator end() noexcept;
135 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000136
Howard Hinnanta6119a82011-05-29 19:57:12 +0000137 reverse_iterator rbegin() noexcept;
138 const_reverse_iterator rbegin() const noexcept;
139 reverse_iterator rend() noexcept;
140 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000141
Howard Hinnanta6119a82011-05-29 19:57:12 +0000142 const_iterator cbegin() const noexcept;
143 const_iterator cend() const noexcept;
144 const_reverse_iterator crbegin() const noexcept;
145 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000146
Howard Hinnanta6119a82011-05-29 19:57:12 +0000147 size_type size() const noexcept;
148 size_type length() const noexcept;
149 size_type max_size() const noexcept;
150 size_type capacity() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000151
152 void resize(size_type n, value_type c);
153 void resize(size_type n);
154
155 void reserve(size_type res_arg = 0);
156 void shrink_to_fit();
Howard Hinnanta6119a82011-05-29 19:57:12 +0000157 void clear() noexcept;
158 bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000159
160 const_reference operator[](size_type pos) const;
161 reference operator[](size_type pos);
162
163 const_reference at(size_type n) const;
164 reference at(size_type n);
165
166 basic_string& operator+=(const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000167 basic_string& operator+=(basic_string_view<charT, traits> sv);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000168 basic_string& operator+=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000169 basic_string& operator+=(value_type c);
170 basic_string& operator+=(initializer_list<value_type>);
171
172 basic_string& append(const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000173 basic_string& append(basic_string_view<charT, traits> sv);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000174 basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000175 template <class T>
176 basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000177 basic_string& append(const value_type* s, size_type n);
178 basic_string& append(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000179 basic_string& append(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000180 template<class InputIterator>
181 basic_string& append(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000182 basic_string& append(initializer_list<value_type>);
183
184 void push_back(value_type c);
185 void pop_back();
186 reference front();
187 const_reference front() const;
188 reference back();
189 const_reference back() const;
190
191 basic_string& assign(const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000192 basic_string& assign(basic_string_view<charT, traits> sv);
Howard Hinnanta6119a82011-05-29 19:57:12 +0000193 basic_string& assign(basic_string&& str);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000194 basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000195 template <class T>
196 basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000197 basic_string& assign(const value_type* s, size_type n);
198 basic_string& assign(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000199 basic_string& assign(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000200 template<class InputIterator>
201 basic_string& assign(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000202 basic_string& assign(initializer_list<value_type>);
203
204 basic_string& insert(size_type pos1, const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000205 basic_string& insert(size_type pos1, basic_string_view<charT, traits> sv);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000206 basic_string& insert(size_type pos1, const basic_string& str,
207 size_type pos2, size_type n);
Marshall Clow6ac8de02016-09-24 22:45:42 +0000208 template <class T>
209 basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17
Marshall Clowa93b5e22014-03-04 19:17:19 +0000210 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000211 basic_string& insert(size_type pos, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000212 basic_string& insert(size_type pos, size_type n, value_type c);
213 iterator insert(const_iterator p, value_type c);
214 iterator insert(const_iterator p, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000215 template<class InputIterator>
216 iterator insert(const_iterator p, InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000217 iterator insert(const_iterator p, initializer_list<value_type>);
218
219 basic_string& erase(size_type pos = 0, size_type n = npos);
220 iterator erase(const_iterator position);
221 iterator erase(const_iterator first, const_iterator last);
222
223 basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000224 basic_string& replace(size_type pos1, size_type n1, basic_string_view<charT, traits> sv);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000225 basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000226 size_type pos2, size_type n2=npos); // C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000227 template <class T>
228 basic_string& replace(size_type pos1, size_type n1, const T& t,
229 size_type pos2, size_type n); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000230 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
231 basic_string& replace(size_type pos, size_type n1, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000232 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000233 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000234 basic_string& replace(const_iterator i1, const_iterator i2, basic_string_view<charT, traits> sv);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000235 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
236 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000237 basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000238 template<class InputIterator>
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000239 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
240 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000241
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000242 size_type copy(value_type* s, size_type n, size_type pos = 0) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000243 basic_string substr(size_type pos = 0, size_type n = npos) const;
244
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000245 void swap(basic_string& str)
Marshall Clow7d914d12015-07-13 20:04:56 +0000246 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
247 allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000248
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000249 const value_type* c_str() const noexcept;
250 const value_type* data() const noexcept;
Marshall Clowf532a702016-03-08 15:44:30 +0000251 value_type* data() noexcept; // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000252
Howard Hinnanta6119a82011-05-29 19:57:12 +0000253 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000254
Howard Hinnanta6119a82011-05-29 19:57:12 +0000255 size_type find(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000256 size_type find(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000257 size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
258 size_type find(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000259 size_type find(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000260
Howard Hinnanta6119a82011-05-29 19:57:12 +0000261 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000262 size_type ffind(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000263 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
264 size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000265 size_type rfind(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000266
Howard Hinnanta6119a82011-05-29 19:57:12 +0000267 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000268 size_type find_first_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000269 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
270 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000271 size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000272
Howard Hinnanta6119a82011-05-29 19:57:12 +0000273 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000274 size_type find_last_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000275 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
276 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000277 size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000278
Howard Hinnanta6119a82011-05-29 19:57:12 +0000279 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000280 size_type find_first_not_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000281 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
282 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000283 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000284
Howard Hinnanta6119a82011-05-29 19:57:12 +0000285 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000286 size_type find_last_not_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000287 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
288 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000289 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000290
Howard Hinnanta6119a82011-05-29 19:57:12 +0000291 int compare(const basic_string& str) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000292 int compare(basic_string_view<charT, traits> sv) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000293 int compare(size_type pos1, size_type n1, const basic_string& str) const;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000294 int compare(size_type pos1, size_type n1, basic_string_view<charT, traits> sv) const;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000295 int compare(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000296 size_type pos2, size_type n2=npos) const; // C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000297 template <class T>
298 int compare(size_type pos1, size_type n1, const T& t,
299 size_type pos2, size_type n2=npos) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000300 int compare(const value_type* s) const noexcept;
301 int compare(size_type pos1, size_type n1, const value_type* s) const;
302 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000303
304 bool __invariants() const;
305};
306
307template<class charT, class traits, class Allocator>
308basic_string<charT, traits, Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000309operator+(const basic_string<charT, traits, Allocator>& lhs,
310 const basic_string<charT, traits, Allocator>& rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000311
312template<class charT, class traits, class Allocator>
313basic_string<charT, traits, Allocator>
314operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
315
316template<class charT, class traits, class Allocator>
317basic_string<charT, traits, Allocator>
318operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
319
320template<class charT, class traits, class Allocator>
321basic_string<charT, traits, Allocator>
322operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
323
324template<class charT, class traits, class Allocator>
325basic_string<charT, traits, Allocator>
326operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
327
328template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000329bool operator==(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000330 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000331
332template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000333bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000334
335template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000336bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000337
Howard Hinnant324bb032010-08-22 00:02:43 +0000338template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000339bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000340 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000341
342template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000343bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000344
345template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000346bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000347
348template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000349bool operator< (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000350 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000351
352template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000353bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000354
355template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000356bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000357
358template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000359bool operator> (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000360 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000361
362template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000363bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000364
365template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000366bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000367
368template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000369bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000370 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000371
372template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000373bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374
375template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000376bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000377
378template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000379bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000380 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000381
382template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000383bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000384
385template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000386bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000387
388template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000389void swap(basic_string<charT, traits, Allocator>& lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000390 basic_string<charT, traits, Allocator>& rhs)
391 noexcept(noexcept(lhs.swap(rhs)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000392
393template<class charT, class traits, class Allocator>
394basic_istream<charT, traits>&
395operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
396
397template<class charT, class traits, class Allocator>
398basic_ostream<charT, traits>&
399operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
400
401template<class charT, class traits, class Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +0000402basic_istream<charT, traits>&
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000403getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
404 charT delim);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000405
406template<class charT, class traits, class Allocator>
407basic_istream<charT, traits>&
408getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
409
410typedef basic_string<char> string;
411typedef basic_string<wchar_t> wstring;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000412typedef basic_string<char16_t> u16string;
413typedef basic_string<char32_t> u32string;
414
415int stoi (const string& str, size_t* idx = 0, int base = 10);
416long stol (const string& str, size_t* idx = 0, int base = 10);
417unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
418long long stoll (const string& str, size_t* idx = 0, int base = 10);
419unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
420
421float stof (const string& str, size_t* idx = 0);
422double stod (const string& str, size_t* idx = 0);
423long double stold(const string& str, size_t* idx = 0);
424
425string to_string(int val);
426string to_string(unsigned val);
427string to_string(long val);
428string to_string(unsigned long val);
429string to_string(long long val);
430string to_string(unsigned long long val);
431string to_string(float val);
432string to_string(double val);
433string to_string(long double val);
434
435int stoi (const wstring& str, size_t* idx = 0, int base = 10);
436long stol (const wstring& str, size_t* idx = 0, int base = 10);
437unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
438long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
439unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
440
441float stof (const wstring& str, size_t* idx = 0);
442double stod (const wstring& str, size_t* idx = 0);
443long double stold(const wstring& str, size_t* idx = 0);
444
445wstring to_wstring(int val);
446wstring to_wstring(unsigned val);
447wstring to_wstring(long val);
448wstring to_wstring(unsigned long val);
449wstring to_wstring(long long val);
450wstring to_wstring(unsigned long long val);
451wstring to_wstring(float val);
452wstring to_wstring(double val);
453wstring to_wstring(long double val);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000454
455template <> struct hash<string>;
456template <> struct hash<u16string>;
457template <> struct hash<u32string>;
458template <> struct hash<wstring>;
459
Marshall Clow15234322013-07-23 17:05:24 +0000460basic_string<char> operator "" s( const char *str, size_t len ); // C++14
461basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
462basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
463basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
464
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000465} // std
466
467*/
468
469#include <__config>
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000470#include <string_view>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000471#include <iosfwd>
472#include <cstring>
Howard Hinnantadff4892010-05-24 17:49:41 +0000473#include <cstdio> // For EOF.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000474#include <cwchar>
475#include <algorithm>
476#include <iterator>
477#include <utility>
478#include <memory>
479#include <stdexcept>
480#include <type_traits>
481#include <initializer_list>
482#include <__functional_base>
483#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
484#include <cstdint>
485#endif
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000486
Howard Hinnant66c6f972011-11-29 16:45:27 +0000487#include <__undef_min_max>
488
Eric Fiselierb9536102014-08-10 23:53:08 +0000489#include <__debug>
490
Howard Hinnant08e17472011-10-17 20:05:10 +0000491#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000492#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000493#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000494
495_LIBCPP_BEGIN_NAMESPACE_STD
496
497// fpos
498
499template <class _StateT>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000500class _LIBCPP_TEMPLATE_VIS fpos
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000501{
502private:
503 _StateT __st_;
504 streamoff __off_;
505public:
506 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
507
508 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
509
510 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
511 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
512
513 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
514 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
515 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
516 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
517};
518
519template <class _StateT>
520inline _LIBCPP_INLINE_VISIBILITY
521streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
522 {return streamoff(__x) - streamoff(__y);}
523
524template <class _StateT>
525inline _LIBCPP_INLINE_VISIBILITY
526bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
527 {return streamoff(__x) == streamoff(__y);}
528
529template <class _StateT>
530inline _LIBCPP_INLINE_VISIBILITY
531bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
532 {return streamoff(__x) != streamoff(__y);}
533
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000534// basic_string
535
536template<class _CharT, class _Traits, class _Allocator>
537basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000538operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
539 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000540
541template<class _CharT, class _Traits, class _Allocator>
542basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000543operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000544
545template<class _CharT, class _Traits, class _Allocator>
546basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000547operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000548
549template<class _CharT, class _Traits, class _Allocator>
550basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000551operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000552
553template<class _CharT, class _Traits, class _Allocator>
554basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000555operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000556
557template <bool>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000558class _LIBCPP_TEMPLATE_VIS __basic_string_common
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000559{
560protected:
Marshall Clow14c09a22016-08-25 15:09:01 +0000561 _LIBCPP_NORETURN void __throw_length_error() const;
562 _LIBCPP_NORETURN void __throw_out_of_range() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000563};
564
565template <bool __b>
566void
567__basic_string_common<__b>::__throw_length_error() const
568{
Marshall Clow14c09a22016-08-25 15:09:01 +0000569 _VSTD::__throw_length_error("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000570}
571
572template <bool __b>
573void
574__basic_string_common<__b>::__throw_out_of_range() const
575{
Marshall Clow14c09a22016-08-25 15:09:01 +0000576 _VSTD::__throw_out_of_range("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000577}
578
Howard Hinnante9df0a52013-08-01 18:17:34 +0000579#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +0000580#pragma warning( push )
581#pragma warning( disable: 4231 )
Howard Hinnante9df0a52013-08-01 18:17:34 +0000582#endif // _LIBCPP_MSVC
Eric Fiselier833d6442016-09-15 22:27:07 +0000583_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>)
Howard Hinnante9df0a52013-08-01 18:17:34 +0000584#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +0000585#pragma warning( pop )
Howard Hinnante9df0a52013-08-01 18:17:34 +0000586#endif // _LIBCPP_MSVC
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000587
Marshall Clowdf9db312016-01-13 21:54:34 +0000588#ifdef _LIBCPP_NO_EXCEPTIONS
589template <class _Iter>
590struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
591#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
592template <class _Iter>
593struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
594#else
595template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
596struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
597 noexcept(++(declval<_Iter&>())) &&
598 is_nothrow_assignable<_Iter&, _Iter>::value &&
599 noexcept(declval<_Iter>() == declval<_Iter>()) &&
600 noexcept(*declval<_Iter>())
601)) {};
602
603template <class _Iter>
604struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
605#endif
606
607
608template <class _Iter>
609struct __libcpp_string_gets_noexcept_iterator
610 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
611
Marshall Clow6ac8de02016-09-24 22:45:42 +0000612template <class _CharT, class _Traits, class _Tp>
613struct __can_be_converted_to_string_view : public _LIBCPP_BOOL_CONSTANT(
614 ( is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
615 !is_convertible<const _Tp&, const _CharT*>::value)) {};
616
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000617#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000618
619template <class _CharT, size_t = sizeof(_CharT)>
620struct __padding
621{
622 unsigned char __xx[sizeof(_CharT)-1];
623};
624
625template <class _CharT>
626struct __padding<_CharT, 1>
627{
628};
629
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000630#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000631
Howard Hinnant324bb032010-08-22 00:02:43 +0000632template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000633class _LIBCPP_TEMPLATE_VIS basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000634 : private __basic_string_common<true>
635{
636public:
637 typedef basic_string __self;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000638 typedef basic_string_view<_CharT, _Traits> __self_view;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000639 typedef _Traits traits_type;
640 typedef typename traits_type::char_type value_type;
641 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000642 typedef allocator_traits<allocator_type> __alloc_traits;
643 typedef typename __alloc_traits::size_type size_type;
644 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000645 typedef value_type& reference;
646 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000647 typedef typename __alloc_traits::pointer pointer;
648 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000649
Howard Hinnant499cea12013-08-23 17:37:05 +0000650 static_assert(is_pod<value_type>::value, "Character type of basic_string must be a POD");
651 static_assert((is_same<_CharT, value_type>::value),
652 "traits_type::char_type must be the same type as CharT");
653 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
654 "Allocator::value_type must be same type as value_type");
655#if defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000656 typedef pointer iterator;
657 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000658#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000659 typedef __wrap_iter<pointer> iterator;
660 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000661#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000662 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
663 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000664
665private:
Howard Hinnant15467182013-04-30 21:44:48 +0000666
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000667#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000668
669 struct __long
670 {
671 pointer __data_;
672 size_type __size_;
673 size_type __cap_;
674 };
675
676#if _LIBCPP_BIG_ENDIAN
677 enum {__short_mask = 0x01};
678 enum {__long_mask = 0x1ul};
679#else // _LIBCPP_BIG_ENDIAN
680 enum {__short_mask = 0x80};
681 enum {__long_mask = ~(size_type(~0) >> 1)};
682#endif // _LIBCPP_BIG_ENDIAN
683
684 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
685 (sizeof(__long) - 1)/sizeof(value_type) : 2};
686
687 struct __short
688 {
689 value_type __data_[__min_cap];
690 struct
691 : __padding<value_type>
692 {
693 unsigned char __size_;
694 };
695 };
696
697#else
698
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000699 struct __long
700 {
701 size_type __cap_;
702 size_type __size_;
703 pointer __data_;
704 };
705
706#if _LIBCPP_BIG_ENDIAN
707 enum {__short_mask = 0x80};
708 enum {__long_mask = ~(size_type(~0) >> 1)};
Howard Hinnant324bb032010-08-22 00:02:43 +0000709#else // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000710 enum {__short_mask = 0x01};
Howard Hinnantec3773c2011-12-01 20:21:04 +0000711 enum {__long_mask = 0x1ul};
Howard Hinnant324bb032010-08-22 00:02:43 +0000712#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000713
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000714 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
715 (sizeof(__long) - 1)/sizeof(value_type) : 2};
716
717 struct __short
718 {
719 union
720 {
721 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59 +0000722 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000723 };
724 value_type __data_[__min_cap];
725 };
726
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000727#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000728
Howard Hinnant499cea12013-08-23 17:37:05 +0000729 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000730
Howard Hinnant499cea12013-08-23 17:37:05 +0000731 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000732
733 struct __raw
734 {
735 size_type __words[__n_words];
736 };
737
738 struct __rep
739 {
740 union
741 {
742 __long __l;
743 __short __s;
744 __raw __r;
745 };
746 };
747
748 __compressed_pair<__rep, allocator_type> __r_;
749
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000750public:
751 static const size_type npos = -1;
752
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000753 _LIBCPP_INLINE_VISIBILITY basic_string()
754 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000755
756 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
757#if _LIBCPP_STD_VER <= 14
758 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
759#else
760 _NOEXCEPT;
761#endif
762
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000763 basic_string(const basic_string& __str);
764 basic_string(const basic_string& __str, const allocator_type& __a);
Marshall Clow7b193f72015-06-03 19:56:43 +0000765
Howard Hinnant73d21a42010-09-04 23:28:19 +0000766#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9f193f22011-01-26 00:06:59 +0000767 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000768 basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +0000769#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000770 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000771#else
772 _NOEXCEPT;
773#endif
774
Howard Hinnant9f193f22011-01-26 00:06:59 +0000775 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000776 basic_string(basic_string&& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000777#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000778 _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000779 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000780 basic_string(const value_type* __s, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000781 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000782 basic_string(const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000783 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000784 basic_string(const value_type* __s, size_type __n, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000785 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000786 basic_string(size_type __n, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000787 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000788 basic_string(size_type __n, value_type __c, const allocator_type& __a);
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000789 basic_string(const basic_string& __str, size_type __pos, size_type __n,
790 const allocator_type& __a = allocator_type());
791 _LIBCPP_INLINE_VISIBILITY
792 basic_string(const basic_string& __str, size_type __pos,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000793 const allocator_type& __a = allocator_type());
Marshall Clowdb7fa112016-11-14 18:22:19 +0000794 template<class _Tp>
795 basic_string(const _Tp& __t, size_type __pos, size_type __n,
796 const allocator_type& __a = allocator_type(),
797 typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type* = 0);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000798 _LIBCPP_INLINE_VISIBILITY explicit
799 basic_string(__self_view __sv);
800 _LIBCPP_INLINE_VISIBILITY
801 basic_string(__self_view __sv, const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000802 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000803 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000804 basic_string(_InputIterator __first, _InputIterator __last);
805 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000806 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000807 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000808#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000809 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000810 basic_string(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000811 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000812 basic_string(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000813#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000814
Eric Fiselier51eb1d52016-10-31 03:42:50 +0000815 inline ~basic_string();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000816
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000817 _LIBCPP_INLINE_VISIBILITY
818 operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
819
Howard Hinnante32b5e22010-11-17 17:55:08 +0000820 basic_string& operator=(const basic_string& __str);
Eric Fiselier37b2be92017-01-17 22:10:32 +0000821 template <class = void>
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000822 _LIBCPP_INLINE_VISIBILITY
823 basic_string& operator=(__self_view __sv) {return assign(__sv);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000824#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000825 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000826 basic_string& operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +0000827 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000828#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000829 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000830 basic_string& operator=(value_type __c);
Howard Hinnante3e32912011-08-12 21:56:02 +0000831#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000832 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000833 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000834#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000835
Howard Hinnant499cea12013-08-23 17:37:05 +0000836#if _LIBCPP_DEBUG_LEVEL >= 2
837 _LIBCPP_INLINE_VISIBILITY
838 iterator begin() _NOEXCEPT
839 {return iterator(this, __get_pointer());}
840 _LIBCPP_INLINE_VISIBILITY
841 const_iterator begin() const _NOEXCEPT
842 {return const_iterator(this, __get_pointer());}
843 _LIBCPP_INLINE_VISIBILITY
844 iterator end() _NOEXCEPT
845 {return iterator(this, __get_pointer() + size());}
846 _LIBCPP_INLINE_VISIBILITY
847 const_iterator end() const _NOEXCEPT
848 {return const_iterator(this, __get_pointer() + size());}
849#else
Howard Hinnanta6119a82011-05-29 19:57:12 +0000850 _LIBCPP_INLINE_VISIBILITY
851 iterator begin() _NOEXCEPT
852 {return iterator(__get_pointer());}
853 _LIBCPP_INLINE_VISIBILITY
854 const_iterator begin() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000855 {return const_iterator(__get_pointer());}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000856 _LIBCPP_INLINE_VISIBILITY
857 iterator end() _NOEXCEPT
858 {return iterator(__get_pointer() + size());}
859 _LIBCPP_INLINE_VISIBILITY
860 const_iterator end() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000861 {return const_iterator(__get_pointer() + size());}
Howard Hinnant499cea12013-08-23 17:37:05 +0000862#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnanta6119a82011-05-29 19:57:12 +0000863 _LIBCPP_INLINE_VISIBILITY
864 reverse_iterator rbegin() _NOEXCEPT
865 {return reverse_iterator(end());}
866 _LIBCPP_INLINE_VISIBILITY
867 const_reverse_iterator rbegin() const _NOEXCEPT
868 {return const_reverse_iterator(end());}
869 _LIBCPP_INLINE_VISIBILITY
870 reverse_iterator rend() _NOEXCEPT
871 {return reverse_iterator(begin());}
872 _LIBCPP_INLINE_VISIBILITY
873 const_reverse_iterator rend() const _NOEXCEPT
874 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000875
Howard Hinnanta6119a82011-05-29 19:57:12 +0000876 _LIBCPP_INLINE_VISIBILITY
877 const_iterator cbegin() const _NOEXCEPT
878 {return begin();}
879 _LIBCPP_INLINE_VISIBILITY
880 const_iterator cend() const _NOEXCEPT
881 {return end();}
882 _LIBCPP_INLINE_VISIBILITY
883 const_reverse_iterator crbegin() const _NOEXCEPT
884 {return rbegin();}
885 _LIBCPP_INLINE_VISIBILITY
886 const_reverse_iterator crend() const _NOEXCEPT
887 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000888
Howard Hinnanta6119a82011-05-29 19:57:12 +0000889 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000890 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000891 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
892 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
893 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +0000894 {return (__is_long() ? __get_long_cap()
895 : static_cast<size_type>(__min_cap)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000896
897 void resize(size_type __n, value_type __c);
898 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
899
900 void reserve(size_type res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000901 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000902 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +0000904 void clear() _NOEXCEPT;
905 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000906
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000907 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
908 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000909
910 const_reference at(size_type __n) const;
911 reference at(size_type __n);
912
913 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000914 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(__self_view __sv) {return append(__sv);}
915 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000916 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +0000917#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000918 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Howard Hinnante3e32912011-08-12 21:56:02 +0000919#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000920
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000921 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000922 basic_string& append(const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000923 _LIBCPP_INLINE_VISIBILITY
924 basic_string& append(__self_view __sv) { return append(__sv.data(), __sv.size()); }
Marshall Clowa93b5e22014-03-04 19:17:19 +0000925 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow42a87db2016-10-03 23:40:48 +0000926 template <class _Tp>
Marshall Clow6ac8de02016-09-24 22:45:42 +0000927 typename enable_if
928 <
929 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
930 basic_string&
931 >::type
932 append(const _Tp& __t, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000933 basic_string& append(const value_type* __s, size_type __n);
934 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000935 basic_string& append(size_type __n, value_type __c);
Eric Fiselier026d38e2016-10-31 02:46:25 +0000936 template <class _ForwardIterator>
Eric Fiselierd5b0db52016-10-31 03:40:29 +0000937 inline basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000938 template<class _InputIterator>
939 typename enable_if
940 <
Marshall Clowdf9db312016-01-13 21:54:34 +0000941 __is_exactly_input_iterator<_InputIterator>::value
942 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000943 basic_string&
944 >::type
Eric Fiselier026d38e2016-10-31 02:46:25 +0000945 _LIBCPP_INLINE_VISIBILITY
946 append(_InputIterator __first, _InputIterator __last) {
947 const basic_string __temp (__first, __last, __alloc());
948 append(__temp.data(), __temp.size());
949 return *this;
950 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000951 template<class _ForwardIterator>
952 typename enable_if
953 <
Marshall Clowdf9db312016-01-13 21:54:34 +0000954 __is_forward_iterator<_ForwardIterator>::value
955 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000956 basic_string&
957 >::type
Eric Fiselier026d38e2016-10-31 02:46:25 +0000958 _LIBCPP_INLINE_VISIBILITY
959 append(_ForwardIterator __first, _ForwardIterator __last) {
960 return __append_forward_unsafe(__first, __last);
961 }
962
Howard Hinnante3e32912011-08-12 21:56:02 +0000963#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000964 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000965 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000966#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000967
968 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000970 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000971 _LIBCPP_INLINE_VISIBILITY reference front();
972 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
973 _LIBCPP_INLINE_VISIBILITY reference back();
974 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000975
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000976 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000977 basic_string& assign(__self_view __sv) { return assign(__sv.data(), __sv.size()); }
978 _LIBCPP_INLINE_VISIBILITY
Marshall Clowf40ec902016-03-09 18:08:29 +0000979 basic_string& assign(const basic_string& __str) { return *this = __str; }
Howard Hinnanta6119a82011-05-29 19:57:12 +0000980#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
981 _LIBCPP_INLINE_VISIBILITY
982 basic_string& assign(basic_string&& str)
Marshall Clow7ed093b2015-10-05 16:17:34 +0000983 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000984 {*this = _VSTD::move(str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000985#endif
Marshall Clowa93b5e22014-03-04 19:17:19 +0000986 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow42a87db2016-10-03 23:40:48 +0000987 template <class _Tp>
Marshall Clow6ac8de02016-09-24 22:45:42 +0000988 typename enable_if
989 <
990 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
991 basic_string&
992 >::type
993 assign(const _Tp & __t, size_type pos, size_type n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000994 basic_string& assign(const value_type* __s, size_type __n);
995 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000996 basic_string& assign(size_type __n, value_type __c);
997 template<class _InputIterator>
998 typename enable_if
999 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001000 __is_exactly_input_iterator<_InputIterator>::value
1001 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001002 basic_string&
1003 >::type
1004 assign(_InputIterator __first, _InputIterator __last);
1005 template<class _ForwardIterator>
1006 typename enable_if
1007 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001008 __is_forward_iterator<_ForwardIterator>::value
1009 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001010 basic_string&
1011 >::type
1012 assign(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001013#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001014 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001015 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001016#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001017
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001018 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001019 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001020 _LIBCPP_INLINE_VISIBILITY
1021 basic_string& insert(size_type __pos1, __self_view __sv) { return insert(__pos1, __sv.data(), __sv.size()); }
Marshall Clow6ac8de02016-09-24 22:45:42 +00001022 template <class _Tp>
1023 typename enable_if
1024 <
1025 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1026 basic_string&
1027 >::type
1028 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001029 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001030 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1031 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001032 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1033 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001034 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001035 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1036 template<class _InputIterator>
1037 typename enable_if
1038 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001039 __is_exactly_input_iterator<_InputIterator>::value
1040 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001041 iterator
1042 >::type
1043 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1044 template<class _ForwardIterator>
1045 typename enable_if
1046 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001047 __is_forward_iterator<_ForwardIterator>::value
1048 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001049 iterator
1050 >::type
1051 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001052#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001053 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001054 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1055 {return insert(__pos, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001056#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001057
1058 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001059 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001060 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001061 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001062 iterator erase(const_iterator __first, const_iterator __last);
1063
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001064 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001065 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001066 _LIBCPP_INLINE_VISIBILITY
1067 basic_string& replace(size_type __pos1, size_type __n1, __self_view __sv) { return replace(__pos1, __n1, __sv.data(), __sv.size()); }
Marshall Clowa93b5e22014-03-04 19:17:19 +00001068 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
Marshall Clow6ac8de02016-09-24 22:45:42 +00001069 template <class _Tp>
1070 typename enable_if
1071 <
1072 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1073 basic_string&
1074 >::type
1075 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001076 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1077 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001078 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001079 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001080 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001081 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001082 basic_string& replace(const_iterator __i1, const_iterator __i2, __self_view __sv) { return replace(__i1 - begin(), __i2 - __i1, __sv); }
1083 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001084 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001085 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001086 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001087 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001088 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001089 template<class _InputIterator>
1090 typename enable_if
1091 <
1092 __is_input_iterator<_InputIterator>::value,
1093 basic_string&
1094 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001095 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Howard Hinnante3e32912011-08-12 21:56:02 +00001096#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001097 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001098 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001099 {return replace(__i1, __i2, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001100#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001101
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001102 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001103 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001104 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1105
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001106 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001107 void swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00001108#if _LIBCPP_STD_VER >= 14
Eric Fiselier47257c42016-12-28 05:53:01 +00001109 _NOEXCEPT_DEBUG;
Marshall Clow7d914d12015-07-13 20:04:56 +00001110#else
Eric Fiselier47257c42016-12-28 05:53:01 +00001111 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56 +00001112 __is_nothrow_swappable<allocator_type>::value);
1113#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001114
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001115 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001116 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001117 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001118 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Marshall Clowf532a702016-03-08 15:44:30 +00001119#if _LIBCPP_STD_VER > 14
1120 _LIBCPP_INLINE_VISIBILITY
1121 value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1122#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001123
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001124 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001125 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001126
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001127 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001128 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001129 _LIBCPP_INLINE_VISIBILITY
1130 size_type find(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001131 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001132 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001133 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001134 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001135
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001136 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001137 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001138 _LIBCPP_INLINE_VISIBILITY
1139 size_type rfind(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001140 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001141 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001142 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001143 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001144
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001145 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001146 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001147 _LIBCPP_INLINE_VISIBILITY
1148 size_type find_first_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001149 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001150 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001151 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001152 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001153 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001154
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001155 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001156 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001157 _LIBCPP_INLINE_VISIBILITY
1158 size_type find_last_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001159 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001160 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001161 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001162 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001163 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001164
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001165 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001166 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001167 _LIBCPP_INLINE_VISIBILITY
1168 size_type find_first_not_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001169 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 +00001170 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001171 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001172 _LIBCPP_INLINE_VISIBILITY
1173 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1174
1175 _LIBCPP_INLINE_VISIBILITY
1176 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001177 _LIBCPP_INLINE_VISIBILITY
1178 size_type find_last_not_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001179 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 +00001180 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001181 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001182 _LIBCPP_INLINE_VISIBILITY
1183 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1184
1185 _LIBCPP_INLINE_VISIBILITY
1186 int compare(const basic_string& __str) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001187 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001188 int compare(__self_view __sv) const _NOEXCEPT;
1189 _LIBCPP_INLINE_VISIBILITY
1190 int compare(size_type __pos1, size_type __n1, __self_view __sv) const;
1191 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001192 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clowa93b5e22014-03-04 19:17:19 +00001193 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
Marshall Clow6ac8de02016-09-24 22:45:42 +00001194 template <class _Tp>
Eric Fiselier9dbc0532016-10-14 05:29:46 +00001195 inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow6ac8de02016-09-24 22:45:42 +00001196 typename enable_if
1197 <
1198 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1199 int
1200 >::type
1201 compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001202 int compare(const value_type* __s) const _NOEXCEPT;
1203 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1204 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001205
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001206 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:13 +00001207
1208 _LIBCPP_INLINE_VISIBILITY
1209 bool __is_long() const _NOEXCEPT
1210 {return bool(__r_.first().__s.__size_ & __short_mask);}
1211
Howard Hinnant499cea12013-08-23 17:37:05 +00001212#if _LIBCPP_DEBUG_LEVEL >= 2
1213
1214 bool __dereferenceable(const const_iterator* __i) const;
1215 bool __decrementable(const const_iterator* __i) const;
1216 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1217 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1218
1219#endif // _LIBCPP_DEBUG_LEVEL >= 2
1220
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001221private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001222 _LIBCPP_INLINE_VISIBILITY
1223 allocator_type& __alloc() _NOEXCEPT
1224 {return __r_.second();}
1225 _LIBCPP_INLINE_VISIBILITY
1226 const allocator_type& __alloc() const _NOEXCEPT
1227 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001228
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001229#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001230
Howard Hinnanta6119a82011-05-29 19:57:12 +00001231 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001232 void __set_short_size(size_type __s) _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001233# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001234 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:48 +00001235# else
1236 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1237# endif
1238
Howard Hinnanta6119a82011-05-29 19:57:12 +00001239 _LIBCPP_INLINE_VISIBILITY
1240 size_type __get_short_size() const _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001241# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001242 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:48 +00001243# else
1244 {return __r_.first().__s.__size_;}
1245# endif
1246
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001247#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001248
1249 _LIBCPP_INLINE_VISIBILITY
1250 void __set_short_size(size_type __s) _NOEXCEPT
1251# if _LIBCPP_BIG_ENDIAN
1252 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1253# else
1254 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1255# endif
1256
1257 _LIBCPP_INLINE_VISIBILITY
1258 size_type __get_short_size() const _NOEXCEPT
1259# if _LIBCPP_BIG_ENDIAN
1260 {return __r_.first().__s.__size_;}
1261# else
1262 {return __r_.first().__s.__size_ >> 1;}
1263# endif
1264
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001265#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001266
Howard Hinnanta6119a82011-05-29 19:57:12 +00001267 _LIBCPP_INLINE_VISIBILITY
1268 void __set_long_size(size_type __s) _NOEXCEPT
1269 {__r_.first().__l.__size_ = __s;}
1270 _LIBCPP_INLINE_VISIBILITY
1271 size_type __get_long_size() const _NOEXCEPT
1272 {return __r_.first().__l.__size_;}
1273 _LIBCPP_INLINE_VISIBILITY
1274 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001275 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1276
Howard Hinnanta6119a82011-05-29 19:57:12 +00001277 _LIBCPP_INLINE_VISIBILITY
1278 void __set_long_cap(size_type __s) _NOEXCEPT
1279 {__r_.first().__l.__cap_ = __long_mask | __s;}
1280 _LIBCPP_INLINE_VISIBILITY
1281 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001282 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001283
Howard Hinnanta6119a82011-05-29 19:57:12 +00001284 _LIBCPP_INLINE_VISIBILITY
1285 void __set_long_pointer(pointer __p) _NOEXCEPT
1286 {__r_.first().__l.__data_ = __p;}
1287 _LIBCPP_INLINE_VISIBILITY
1288 pointer __get_long_pointer() _NOEXCEPT
1289 {return __r_.first().__l.__data_;}
1290 _LIBCPP_INLINE_VISIBILITY
1291 const_pointer __get_long_pointer() const _NOEXCEPT
1292 {return __r_.first().__l.__data_;}
1293 _LIBCPP_INLINE_VISIBILITY
1294 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001295 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001296 _LIBCPP_INLINE_VISIBILITY
1297 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001298 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001299 _LIBCPP_INLINE_VISIBILITY
1300 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001301 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001302 _LIBCPP_INLINE_VISIBILITY
1303 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001304 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1305
Howard Hinnanta6119a82011-05-29 19:57:12 +00001306 _LIBCPP_INLINE_VISIBILITY
1307 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001308 {
1309 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1310 for (unsigned __i = 0; __i < __n_words; ++__i)
1311 __a[__i] = 0;
1312 }
1313
1314 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001315 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:20 +00001316 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001317 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001318 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001319 static _LIBCPP_INLINE_VISIBILITY
1320 size_type __recommend(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001321 {return (__s < __min_cap ? static_cast<size_type>(__min_cap) :
Howard Hinnant7f764502013-08-14 18:00:20 +00001322 __align_it<sizeof(value_type) < __alignment ?
Howard Hinnanta6119a82011-05-29 19:57:12 +00001323 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001324
Eric Fiselier6dbed462016-09-16 00:00:48 +00001325 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001326 void __init(const value_type* __s, size_type __sz, size_type __reserve);
Eric Fiselier6dbed462016-09-16 00:00:48 +00001327 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001328 void __init(const value_type* __s, size_type __sz);
Eric Fiselier6dbed462016-09-16 00:00:48 +00001329 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001330 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001331
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001332 template <class _InputIterator>
Eric Fiselier6dbed462016-09-16 00:00:48 +00001333 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001334 typename enable_if
1335 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001336 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001337 void
1338 >::type
1339 __init(_InputIterator __first, _InputIterator __last);
1340
1341 template <class _ForwardIterator>
Eric Fiselier6dbed462016-09-16 00:00:48 +00001342 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001343 typename enable_if
1344 <
1345 __is_forward_iterator<_ForwardIterator>::value,
1346 void
1347 >::type
1348 __init(_ForwardIterator __first, _ForwardIterator __last);
1349
1350 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001351 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001352 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1353 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001354 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001355
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001356 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001357 void __erase_to_end(size_type __pos);
1358
Howard Hinnante32b5e22010-11-17 17:55:08 +00001359 _LIBCPP_INLINE_VISIBILITY
1360 void __copy_assign_alloc(const basic_string& __str)
1361 {__copy_assign_alloc(__str, integral_constant<bool,
1362 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1363
1364 _LIBCPP_INLINE_VISIBILITY
1365 void __copy_assign_alloc(const basic_string& __str, true_type)
1366 {
1367 if (__alloc() != __str.__alloc())
1368 {
1369 clear();
1370 shrink_to_fit();
1371 }
1372 __alloc() = __str.__alloc();
1373 }
1374
1375 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001376 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001377 {}
1378
1379#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001380 _LIBCPP_INLINE_VISIBILITY
Marshall Clowaf961ed2015-08-18 18:57:00 +00001381 void __move_assign(basic_string& __str, false_type)
1382 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001383 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001384 void __move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001385#if _LIBCPP_STD_VER > 14
1386 _NOEXCEPT;
1387#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001388 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001389#endif
Marshall Clowaf961ed2015-08-18 18:57:00 +00001390#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00001391
1392 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001393 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001394 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001395 _NOEXCEPT_(
1396 !__alloc_traits::propagate_on_container_move_assignment::value ||
1397 is_nothrow_move_assignable<allocator_type>::value)
1398 {__move_assign_alloc(__str, integral_constant<bool,
1399 __alloc_traits::propagate_on_container_move_assignment::value>());}
1400
1401 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001402 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001403 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1404 {
1405 __alloc() = _VSTD::move(__c.__alloc());
1406 }
1407
1408 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001409 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001410 _NOEXCEPT
1411 {}
1412
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001413 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1414 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001415
1416 friend basic_string operator+<>(const basic_string&, const basic_string&);
1417 friend basic_string operator+<>(const value_type*, const basic_string&);
1418 friend basic_string operator+<>(value_type, const basic_string&);
1419 friend basic_string operator+<>(const basic_string&, const value_type*);
1420 friend basic_string operator+<>(const basic_string&, value_type);
1421};
1422
1423template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001424inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001425void
1426basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1427{
Howard Hinnant499cea12013-08-23 17:37:05 +00001428#if _LIBCPP_DEBUG_LEVEL >= 2
1429 __get_db()->__invalidate_all(this);
1430#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001431}
1432
1433template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001434inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001435void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001436basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant499cea12013-08-23 17:37:05 +00001437#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantec3773c2011-12-01 20:21:04 +00001438 __pos
1439#endif
1440 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001441{
Howard Hinnant499cea12013-08-23 17:37:05 +00001442#if _LIBCPP_DEBUG_LEVEL >= 2
1443 __c_node* __c = __get_db()->__find_c_and_lock(this);
1444 if (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001445 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001446 const_pointer __new_last = __get_pointer() + __pos;
1447 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001448 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001449 --__p;
1450 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1451 if (__i->base() > __new_last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001452 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001453 (*__p)->__c_ = nullptr;
1454 if (--__c->end_ != __p)
1455 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001456 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001457 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001458 __get_db()->unlock();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001459 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001460#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001461}
1462
1463template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001464inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001465basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowc912c0c2015-06-04 02:05:41 +00001466 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001467{
Howard Hinnant499cea12013-08-23 17:37:05 +00001468#if _LIBCPP_DEBUG_LEVEL >= 2
1469 __get_db()->__insert_c(this);
1470#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001471 __zero();
1472}
1473
1474template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001475inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001476basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiselier692177d2015-07-18 20:40:46 +00001477#if _LIBCPP_STD_VER <= 14
1478 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1479#else
1480 _NOEXCEPT
1481#endif
1482: __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001483{
Howard Hinnant499cea12013-08-23 17:37:05 +00001484#if _LIBCPP_DEBUG_LEVEL >= 2
1485 __get_db()->__insert_c(this);
1486#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001487 __zero();
1488}
1489
1490template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier6dbed462016-09-16 00:00:48 +00001491void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1492 size_type __sz,
1493 size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001494{
1495 if (__reserve > max_size())
1496 this->__throw_length_error();
1497 pointer __p;
1498 if (__reserve < __min_cap)
1499 {
1500 __set_short_size(__sz);
1501 __p = __get_short_pointer();
1502 }
1503 else
1504 {
1505 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001506 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001507 __set_long_pointer(__p);
1508 __set_long_cap(__cap+1);
1509 __set_long_size(__sz);
1510 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001511 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001512 traits_type::assign(__p[__sz], value_type());
1513}
1514
1515template <class _CharT, class _Traits, class _Allocator>
1516void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001517basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001518{
1519 if (__sz > max_size())
1520 this->__throw_length_error();
1521 pointer __p;
1522 if (__sz < __min_cap)
1523 {
1524 __set_short_size(__sz);
1525 __p = __get_short_pointer();
1526 }
1527 else
1528 {
1529 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001530 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001531 __set_long_pointer(__p);
1532 __set_long_cap(__cap+1);
1533 __set_long_size(__sz);
1534 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001535 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001536 traits_type::assign(__p[__sz], value_type());
1537}
1538
1539template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001540inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001541basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001542{
Howard Hinnant499cea12013-08-23 17:37:05 +00001543 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001544 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00001545#if _LIBCPP_DEBUG_LEVEL >= 2
1546 __get_db()->__insert_c(this);
1547#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001548}
1549
1550template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001551inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001552basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001553 : __r_(__a)
1554{
Howard Hinnant499cea12013-08-23 17:37:05 +00001555 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001556 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00001557#if _LIBCPP_DEBUG_LEVEL >= 2
1558 __get_db()->__insert_c(this);
1559#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001560}
1561
1562template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001563inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001564basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001565{
Howard Hinnant499cea12013-08-23 17:37:05 +00001566 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001567 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001568#if _LIBCPP_DEBUG_LEVEL >= 2
1569 __get_db()->__insert_c(this);
1570#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001571}
1572
1573template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001574inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001575basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001576 : __r_(__a)
1577{
Howard Hinnant499cea12013-08-23 17:37:05 +00001578 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001579 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001580#if _LIBCPP_DEBUG_LEVEL >= 2
1581 __get_db()->__insert_c(this);
1582#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001583}
1584
1585template <class _CharT, class _Traits, class _Allocator>
1586basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001587 : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001588{
1589 if (!__str.__is_long())
1590 __r_.first().__r = __str.__r_.first().__r;
1591 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001592 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001593#if _LIBCPP_DEBUG_LEVEL >= 2
1594 __get_db()->__insert_c(this);
1595#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001596}
1597
1598template <class _CharT, class _Traits, class _Allocator>
1599basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
1600 : __r_(__a)
1601{
1602 if (!__str.__is_long())
1603 __r_.first().__r = __str.__r_.first().__r;
1604 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001605 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001606#if _LIBCPP_DEBUG_LEVEL >= 2
1607 __get_db()->__insert_c(this);
1608#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001609}
1610
Howard Hinnant73d21a42010-09-04 23:28:19 +00001611#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001612
1613template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001614inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001615basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +00001616#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001617 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clow7b193f72015-06-03 19:56:43 +00001618#else
1619 _NOEXCEPT
1620#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001621 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001622{
1623 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:05 +00001624#if _LIBCPP_DEBUG_LEVEL >= 2
1625 __get_db()->__insert_c(this);
1626 if (__is_long())
1627 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001628#endif
1629}
1630
1631template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001632inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001633basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001634 : __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001635{
Marshall Clowd5549cc2014-07-17 15:32:20 +00001636 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001637 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd5549cc2014-07-17 15:32:20 +00001638 else
1639 {
1640 __r_.first().__r = __str.__r_.first().__r;
1641 __str.__zero();
1642 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001643#if _LIBCPP_DEBUG_LEVEL >= 2
1644 __get_db()->__insert_c(this);
1645 if (__is_long())
1646 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001647#endif
1648}
1649
Howard Hinnant73d21a42010-09-04 23:28:19 +00001650#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001651
1652template <class _CharT, class _Traits, class _Allocator>
1653void
1654basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1655{
1656 if (__n > max_size())
1657 this->__throw_length_error();
1658 pointer __p;
1659 if (__n < __min_cap)
1660 {
1661 __set_short_size(__n);
1662 __p = __get_short_pointer();
1663 }
1664 else
1665 {
1666 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001667 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001668 __set_long_pointer(__p);
1669 __set_long_cap(__cap+1);
1670 __set_long_size(__n);
1671 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001672 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001673 traits_type::assign(__p[__n], value_type());
1674}
1675
1676template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001677inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001678basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
1679{
1680 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001681#if _LIBCPP_DEBUG_LEVEL >= 2
1682 __get_db()->__insert_c(this);
1683#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001684}
1685
1686template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001687inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001688basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
1689 : __r_(__a)
1690{
1691 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001692#if _LIBCPP_DEBUG_LEVEL >= 2
1693 __get_db()->__insert_c(this);
1694#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001695}
1696
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001697template <class _CharT, class _Traits, class _Allocator>
1698basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
1699 const allocator_type& __a)
1700 : __r_(__a)
1701{
1702 size_type __str_sz = __str.size();
1703 if (__pos > __str_sz)
1704 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001705 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant499cea12013-08-23 17:37:05 +00001706#if _LIBCPP_DEBUG_LEVEL >= 2
1707 __get_db()->__insert_c(this);
1708#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001709}
1710
1711template <class _CharT, class _Traits, class _Allocator>
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001712inline _LIBCPP_INLINE_VISIBILITY
1713basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
1714 const allocator_type& __a)
1715 : __r_(__a)
1716{
1717 size_type __str_sz = __str.size();
1718 if (__pos > __str_sz)
1719 this->__throw_out_of_range();
1720 __init(__str.data() + __pos, __str_sz - __pos);
1721#if _LIBCPP_DEBUG_LEVEL >= 2
1722 __get_db()->__insert_c(this);
1723#endif
1724}
1725
1726template <class _CharT, class _Traits, class _Allocator>
Marshall Clowdb7fa112016-11-14 18:22:19 +00001727template <class _Tp>
1728basic_string<_CharT, _Traits, _Allocator>::basic_string(
1729 const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a,
1730 typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type *)
1731 : __r_(__a)
1732{
1733 __self_view __sv = __self_view(__t).substr(__pos, __n);
1734 __init(__sv.data(), __sv.size());
1735#if _LIBCPP_DEBUG_LEVEL >= 2
1736 __get_db()->__insert_c(this);
1737#endif
1738}
1739
1740template <class _CharT, class _Traits, class _Allocator>
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001741inline _LIBCPP_INLINE_VISIBILITY
1742basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv)
1743{
1744 __init(__sv.data(), __sv.size());
1745#if _LIBCPP_DEBUG_LEVEL >= 2
1746 __get_db()->__insert_c(this);
1747#endif
1748}
1749
1750template <class _CharT, class _Traits, class _Allocator>
1751inline _LIBCPP_INLINE_VISIBILITY
1752basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv, const allocator_type& __a)
1753 : __r_(__a)
1754{
1755 __init(__sv.data(), __sv.size());
1756#if _LIBCPP_DEBUG_LEVEL >= 2
1757 __get_db()->__insert_c(this);
1758#endif
1759}
1760
1761template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001762template <class _InputIterator>
1763typename enable_if
1764<
Marshall Clowdf9db312016-01-13 21:54:34 +00001765 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001766 void
1767>::type
1768basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
1769{
1770 __zero();
1771#ifndef _LIBCPP_NO_EXCEPTIONS
1772 try
1773 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001774#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001775 for (; __first != __last; ++__first)
1776 push_back(*__first);
1777#ifndef _LIBCPP_NO_EXCEPTIONS
1778 }
1779 catch (...)
1780 {
1781 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00001782 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001783 throw;
1784 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001785#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001786}
1787
1788template <class _CharT, class _Traits, class _Allocator>
1789template <class _ForwardIterator>
1790typename enable_if
1791<
1792 __is_forward_iterator<_ForwardIterator>::value,
1793 void
1794>::type
1795basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
1796{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001797 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001798 if (__sz > max_size())
1799 this->__throw_length_error();
1800 pointer __p;
1801 if (__sz < __min_cap)
1802 {
1803 __set_short_size(__sz);
1804 __p = __get_short_pointer();
1805 }
1806 else
1807 {
1808 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001809 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001810 __set_long_pointer(__p);
1811 __set_long_cap(__cap+1);
1812 __set_long_size(__sz);
1813 }
Eric Fiselierb9919752014-10-27 19:28:20 +00001814 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001815 traits_type::assign(*__p, *__first);
1816 traits_type::assign(*__p, value_type());
1817}
1818
1819template <class _CharT, class _Traits, class _Allocator>
1820template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001821inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001822basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
1823{
1824 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00001825#if _LIBCPP_DEBUG_LEVEL >= 2
1826 __get_db()->__insert_c(this);
1827#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001828}
1829
1830template <class _CharT, class _Traits, class _Allocator>
1831template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001832inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001833basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
1834 const allocator_type& __a)
1835 : __r_(__a)
1836{
1837 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00001838#if _LIBCPP_DEBUG_LEVEL >= 2
1839 __get_db()->__insert_c(this);
1840#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001841}
1842
Howard Hinnante3e32912011-08-12 21:56:02 +00001843#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1844
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001845template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001846inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001847basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
1848{
1849 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00001850#if _LIBCPP_DEBUG_LEVEL >= 2
1851 __get_db()->__insert_c(this);
1852#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001853}
1854
1855template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001856inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001857basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
1858 : __r_(__a)
1859{
1860 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00001861#if _LIBCPP_DEBUG_LEVEL >= 2
1862 __get_db()->__insert_c(this);
1863#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001864}
1865
Howard Hinnante3e32912011-08-12 21:56:02 +00001866#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1867
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001868template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001869basic_string<_CharT, _Traits, _Allocator>::~basic_string()
1870{
Howard Hinnant499cea12013-08-23 17:37:05 +00001871#if _LIBCPP_DEBUG_LEVEL >= 2
1872 __get_db()->__erase_c(this);
1873#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001874 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00001875 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001876}
1877
1878template <class _CharT, class _Traits, class _Allocator>
1879void
1880basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
1881 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001882 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 +00001883{
1884 size_type __ms = max_size();
1885 if (__delta_cap > __ms - __old_cap - 1)
1886 this->__throw_length_error();
1887 pointer __old_p = __get_pointer();
1888 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00001889 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001890 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001891 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001892 __invalidate_all_iterators();
1893 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001894 traits_type::copy(_VSTD::__to_raw_pointer(__p),
1895 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001896 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001897 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001898 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
1899 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001900 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
1901 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001902 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001903 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001904 __set_long_pointer(__p);
1905 __set_long_cap(__cap+1);
1906 __old_sz = __n_copy + __n_add + __sec_cp_sz;
1907 __set_long_size(__old_sz);
1908 traits_type::assign(__p[__old_sz], value_type());
1909}
1910
1911template <class _CharT, class _Traits, class _Allocator>
1912void
1913basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1914 size_type __n_copy, size_type __n_del, size_type __n_add)
1915{
1916 size_type __ms = max_size();
Marshall Clowecc8d7b2013-11-06 14:24:38 +00001917 if (__delta_cap > __ms - __old_cap)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001918 this->__throw_length_error();
1919 pointer __old_p = __get_pointer();
1920 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00001921 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001922 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001923 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001924 __invalidate_all_iterators();
1925 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001926 traits_type::copy(_VSTD::__to_raw_pointer(__p),
1927 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001928 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
1929 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001930 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
1931 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
1932 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001933 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001934 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001935 __set_long_pointer(__p);
1936 __set_long_cap(__cap+1);
1937}
1938
1939// assign
1940
1941template <class _CharT, class _Traits, class _Allocator>
1942basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001943basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001944{
Alp Tokerec34c482014-05-15 11:27:39 +00001945 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001946 size_type __cap = capacity();
1947 if (__cap >= __n)
1948 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001949 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001950 traits_type::move(__p, __s, __n);
1951 traits_type::assign(__p[__n], value_type());
1952 __set_size(__n);
1953 __invalidate_iterators_past(__n);
1954 }
1955 else
1956 {
1957 size_type __sz = size();
1958 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
1959 }
1960 return *this;
1961}
1962
1963template <class _CharT, class _Traits, class _Allocator>
1964basic_string<_CharT, _Traits, _Allocator>&
1965basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
1966{
1967 size_type __cap = capacity();
1968 if (__cap < __n)
1969 {
1970 size_type __sz = size();
1971 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
1972 }
1973 else
1974 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001975 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001976 traits_type::assign(__p, __n, __c);
1977 traits_type::assign(__p[__n], value_type());
1978 __set_size(__n);
1979 return *this;
1980}
1981
1982template <class _CharT, class _Traits, class _Allocator>
1983basic_string<_CharT, _Traits, _Allocator>&
1984basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
1985{
1986 pointer __p;
1987 if (__is_long())
1988 {
1989 __p = __get_long_pointer();
1990 __set_long_size(1);
1991 }
1992 else
1993 {
1994 __p = __get_short_pointer();
1995 __set_short_size(1);
1996 }
1997 traits_type::assign(*__p, __c);
1998 traits_type::assign(*++__p, value_type());
1999 __invalidate_iterators_past(1);
2000 return *this;
2001}
2002
2003template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00002004basic_string<_CharT, _Traits, _Allocator>&
2005basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2006{
2007 if (this != &__str)
2008 {
2009 __copy_assign_alloc(__str);
Marshall Clowf40ec902016-03-09 18:08:29 +00002010 assign(__str.data(), __str.size());
Howard Hinnante32b5e22010-11-17 17:55:08 +00002011 }
2012 return *this;
2013}
2014
2015#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2016
2017template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002018inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002019void
2020basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002021 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002022{
2023 if (__alloc() != __str.__alloc())
2024 assign(__str);
2025 else
2026 __move_assign(__str, true_type());
2027}
2028
2029template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002030inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002031void
2032basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002033#if _LIBCPP_STD_VER > 14
2034 _NOEXCEPT
2035#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002036 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002037#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00002038{
2039 clear();
2040 shrink_to_fit();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00002041 __r_.first() = __str.__r_.first();
2042 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002043 __str.__zero();
2044}
2045
2046template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002047inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002048basic_string<_CharT, _Traits, _Allocator>&
2049basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002050 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnante32b5e22010-11-17 17:55:08 +00002051{
2052 __move_assign(__str, integral_constant<bool,
2053 __alloc_traits::propagate_on_container_move_assignment::value>());
2054 return *this;
2055}
2056
2057#endif
2058
2059template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002060template<class _InputIterator>
2061typename enable_if
2062<
Marshall Clowdf9db312016-01-13 21:54:34 +00002063 __is_exactly_input_iterator <_InputIterator>::value
2064 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002065 basic_string<_CharT, _Traits, _Allocator>&
2066>::type
2067basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2068{
Marshall Clowd979eed2016-09-05 01:54:30 +00002069 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002070 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002071 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002072}
2073
2074template <class _CharT, class _Traits, class _Allocator>
2075template<class _ForwardIterator>
2076typename enable_if
2077<
Marshall Clowdf9db312016-01-13 21:54:34 +00002078 __is_forward_iterator<_ForwardIterator>::value
2079 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002080 basic_string<_CharT, _Traits, _Allocator>&
2081>::type
2082basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2083{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002084 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002085 size_type __cap = capacity();
2086 if (__cap < __n)
2087 {
2088 size_type __sz = size();
2089 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2090 }
2091 else
2092 __invalidate_iterators_past(__n);
2093 pointer __p = __get_pointer();
2094 for (; __first != __last; ++__first, ++__p)
2095 traits_type::assign(*__p, *__first);
2096 traits_type::assign(*__p, value_type());
2097 __set_size(__n);
2098 return *this;
2099}
2100
2101template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002102basic_string<_CharT, _Traits, _Allocator>&
2103basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2104{
2105 size_type __sz = __str.size();
2106 if (__pos > __sz)
2107 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002108 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002109}
2110
2111template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002112template <class _Tp>
2113typename enable_if
2114<
2115 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2116 basic_string<_CharT, _Traits, _Allocator>&
2117>::type
2118basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002119{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002120 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002121 size_type __sz = __sv.size();
2122 if (__pos > __sz)
2123 this->__throw_out_of_range();
2124 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2125}
2126
2127
2128template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002129basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002130basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002131{
Alp Tokerec34c482014-05-15 11:27:39 +00002132 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002133 return assign(__s, traits_type::length(__s));
2134}
2135
2136// append
2137
2138template <class _CharT, class _Traits, class _Allocator>
2139basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002140basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002141{
Alp Tokerec34c482014-05-15 11:27:39 +00002142 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002143 size_type __cap = capacity();
2144 size_type __sz = size();
2145 if (__cap - __sz >= __n)
2146 {
2147 if (__n)
2148 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002149 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002150 traits_type::copy(__p + __sz, __s, __n);
2151 __sz += __n;
2152 __set_size(__sz);
2153 traits_type::assign(__p[__sz], value_type());
2154 }
2155 }
2156 else
2157 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2158 return *this;
2159}
2160
2161template <class _CharT, class _Traits, class _Allocator>
2162basic_string<_CharT, _Traits, _Allocator>&
2163basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2164{
2165 if (__n)
2166 {
2167 size_type __cap = capacity();
2168 size_type __sz = size();
2169 if (__cap - __sz < __n)
2170 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2171 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002172 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002173 __sz += __n;
2174 __set_size(__sz);
2175 traits_type::assign(__p[__sz], value_type());
2176 }
2177 return *this;
2178}
2179
2180template <class _CharT, class _Traits, class _Allocator>
2181void
2182basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2183{
Howard Hinnant15467182013-04-30 21:44:48 +00002184 bool __is_short = !__is_long();
2185 size_type __cap;
2186 size_type __sz;
2187 if (__is_short)
2188 {
2189 __cap = __min_cap - 1;
2190 __sz = __get_short_size();
2191 }
2192 else
2193 {
2194 __cap = __get_long_cap() - 1;
2195 __sz = __get_long_size();
2196 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002197 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002198 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002199 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002200 __is_short = !__is_long();
2201 }
2202 pointer __p;
2203 if (__is_short)
2204 {
2205 __p = __get_short_pointer() + __sz;
2206 __set_short_size(__sz+1);
2207 }
2208 else
2209 {
2210 __p = __get_long_pointer() + __sz;
2211 __set_long_size(__sz+1);
2212 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002213 traits_type::assign(*__p, __c);
2214 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002215}
2216
Marshall Clowac655ef2016-09-07 03:32:06 +00002217template <class _Tp>
Marshall Clowd979eed2016-09-05 01:54:30 +00002218bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
2219{
2220 return __first <= __p && __p < __last;
2221}
2222
Marshall Clowac655ef2016-09-07 03:32:06 +00002223template <class _Tp1, class _Tp2>
Eric Fiselier0e5ebbc2016-12-23 23:37:52 +00002224bool __ptr_in_range (const _Tp1*, const _Tp2*, const _Tp2*)
Marshall Clowac655ef2016-09-07 03:32:06 +00002225{
2226 return false;
2227}
2228
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002229template <class _CharT, class _Traits, class _Allocator>
2230template<class _ForwardIterator>
Eric Fiselier026d38e2016-10-31 02:46:25 +00002231basic_string<_CharT, _Traits, _Allocator>&
2232basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe(
2233 _ForwardIterator __first, _ForwardIterator __last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002234{
Eric Fiselier026d38e2016-10-31 02:46:25 +00002235 static_assert(__is_forward_iterator<_ForwardIterator>::value,
2236 "function requires a ForwardIterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002237 size_type __sz = size();
2238 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002239 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002240 if (__n)
2241 {
Marshall Clowd979eed2016-09-05 01:54:30 +00002242 if ( __ptr_in_range(&*__first, data(), data() + size()))
2243 {
2244 const basic_string __temp (__first, __last, __alloc());
2245 append(__temp.data(), __temp.size());
2246 }
2247 else
2248 {
2249 if (__cap - __sz < __n)
2250 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2251 pointer __p = __get_pointer() + __sz;
2252 for (; __first != __last; ++__p, ++__first)
2253 traits_type::assign(*__p, *__first);
2254 traits_type::assign(*__p, value_type());
2255 __set_size(__sz + __n);
2256 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002257 }
2258 return *this;
2259}
2260
2261template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002262inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002263basic_string<_CharT, _Traits, _Allocator>&
2264basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2265{
2266 return append(__str.data(), __str.size());
2267}
2268
2269template <class _CharT, class _Traits, class _Allocator>
2270basic_string<_CharT, _Traits, _Allocator>&
2271basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2272{
2273 size_type __sz = __str.size();
2274 if (__pos > __sz)
2275 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002276 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002277}
2278
2279template <class _CharT, class _Traits, class _Allocator>
Marshall Clow42a87db2016-10-03 23:40:48 +00002280template <class _Tp>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002281 typename enable_if
2282 <
2283 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2284 basic_string<_CharT, _Traits, _Allocator>&
2285 >::type
2286basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002287{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002288 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002289 size_type __sz = __sv.size();
2290 if (__pos > __sz)
2291 this->__throw_out_of_range();
2292 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2293}
2294
2295template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002296basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002297basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002298{
Alp Tokerec34c482014-05-15 11:27:39 +00002299 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002300 return append(__s, traits_type::length(__s));
2301}
2302
2303// insert
2304
2305template <class _CharT, class _Traits, class _Allocator>
2306basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002307basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002308{
Alp Tokerec34c482014-05-15 11:27:39 +00002309 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002310 size_type __sz = size();
2311 if (__pos > __sz)
2312 this->__throw_out_of_range();
2313 size_type __cap = capacity();
2314 if (__cap - __sz >= __n)
2315 {
2316 if (__n)
2317 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002318 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002319 size_type __n_move = __sz - __pos;
2320 if (__n_move != 0)
2321 {
2322 if (__p + __pos <= __s && __s < __p + __sz)
2323 __s += __n;
2324 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2325 }
2326 traits_type::move(__p + __pos, __s, __n);
2327 __sz += __n;
2328 __set_size(__sz);
2329 traits_type::assign(__p[__sz], value_type());
2330 }
2331 }
2332 else
2333 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2334 return *this;
2335}
2336
2337template <class _CharT, class _Traits, class _Allocator>
2338basic_string<_CharT, _Traits, _Allocator>&
2339basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2340{
2341 size_type __sz = size();
2342 if (__pos > __sz)
2343 this->__throw_out_of_range();
2344 if (__n)
2345 {
2346 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002347 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002348 if (__cap - __sz >= __n)
2349 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002350 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002351 size_type __n_move = __sz - __pos;
2352 if (__n_move != 0)
2353 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2354 }
2355 else
2356 {
2357 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002358 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002359 }
2360 traits_type::assign(__p + __pos, __n, __c);
2361 __sz += __n;
2362 __set_size(__sz);
2363 traits_type::assign(__p[__sz], value_type());
2364 }
2365 return *this;
2366}
2367
2368template <class _CharT, class _Traits, class _Allocator>
2369template<class _InputIterator>
2370typename enable_if
2371<
Marshall Clowdf9db312016-01-13 21:54:34 +00002372 __is_exactly_input_iterator<_InputIterator>::value
2373 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2374 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002375>::type
2376basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2377{
Howard Hinnant499cea12013-08-23 17:37:05 +00002378#if _LIBCPP_DEBUG_LEVEL >= 2
2379 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2380 "string::insert(iterator, range) called with an iterator not"
2381 " referring to this string");
2382#endif
Marshall Clowd979eed2016-09-05 01:54:30 +00002383 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002384 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002385}
2386
2387template <class _CharT, class _Traits, class _Allocator>
2388template<class _ForwardIterator>
2389typename enable_if
2390<
Marshall Clowdf9db312016-01-13 21:54:34 +00002391 __is_forward_iterator<_ForwardIterator>::value
2392 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002393 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2394>::type
2395basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2396{
Howard Hinnant499cea12013-08-23 17:37:05 +00002397#if _LIBCPP_DEBUG_LEVEL >= 2
2398 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2399 "string::insert(iterator, range) called with an iterator not"
2400 " referring to this string");
2401#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002402 size_type __ip = static_cast<size_type>(__pos - begin());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002403 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002404 if (__n)
2405 {
Marshall Clowd979eed2016-09-05 01:54:30 +00002406 if ( __ptr_in_range(&*__first, data(), data() + size()))
2407 {
2408 const basic_string __temp(__first, __last, __alloc());
2409 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2410 }
2411
2412 size_type __sz = size();
2413 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002414 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002415 if (__cap - __sz >= __n)
2416 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002417 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002418 size_type __n_move = __sz - __ip;
2419 if (__n_move != 0)
2420 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2421 }
2422 else
2423 {
2424 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002425 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002426 }
2427 __sz += __n;
2428 __set_size(__sz);
2429 traits_type::assign(__p[__sz], value_type());
2430 for (__p += __ip; __first != __last; ++__p, ++__first)
2431 traits_type::assign(*__p, *__first);
2432 }
2433 return begin() + __ip;
2434}
2435
2436template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002437inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002438basic_string<_CharT, _Traits, _Allocator>&
2439basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2440{
2441 return insert(__pos1, __str.data(), __str.size());
2442}
2443
2444template <class _CharT, class _Traits, class _Allocator>
2445basic_string<_CharT, _Traits, _Allocator>&
2446basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2447 size_type __pos2, size_type __n)
2448{
2449 size_type __str_sz = __str.size();
2450 if (__pos2 > __str_sz)
2451 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002452 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002453}
2454
2455template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002456template <class _Tp>
2457typename enable_if
2458<
2459 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2460 basic_string<_CharT, _Traits, _Allocator>&
2461>::type
2462basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002463 size_type __pos2, size_type __n)
2464{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002465 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002466 size_type __str_sz = __sv.size();
2467 if (__pos2 > __str_sz)
2468 this->__throw_out_of_range();
2469 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2470}
2471
2472template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002473basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002474basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002475{
Alp Tokerec34c482014-05-15 11:27:39 +00002476 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002477 return insert(__pos, __s, traits_type::length(__s));
2478}
2479
2480template <class _CharT, class _Traits, class _Allocator>
2481typename basic_string<_CharT, _Traits, _Allocator>::iterator
2482basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2483{
2484 size_type __ip = static_cast<size_type>(__pos - begin());
2485 size_type __sz = size();
2486 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002487 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002488 if (__cap == __sz)
2489 {
2490 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002491 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002492 }
2493 else
2494 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002495 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002496 size_type __n_move = __sz - __ip;
2497 if (__n_move != 0)
2498 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2499 }
2500 traits_type::assign(__p[__ip], __c);
2501 traits_type::assign(__p[++__sz], value_type());
2502 __set_size(__sz);
2503 return begin() + static_cast<difference_type>(__ip);
2504}
2505
2506template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002507inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002508typename basic_string<_CharT, _Traits, _Allocator>::iterator
2509basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2510{
Howard Hinnant499cea12013-08-23 17:37:05 +00002511#if _LIBCPP_DEBUG_LEVEL >= 2
2512 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2513 "string::insert(iterator, n, value) called with an iterator not"
2514 " referring to this string");
2515#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002516 difference_type __p = __pos - begin();
2517 insert(static_cast<size_type>(__p), __n, __c);
2518 return begin() + __p;
2519}
2520
2521// replace
2522
2523template <class _CharT, class _Traits, class _Allocator>
2524basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002525basic_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 +00002526{
Alp Tokerec34c482014-05-15 11:27:39 +00002527 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002528 size_type __sz = size();
2529 if (__pos > __sz)
2530 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002531 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002532 size_type __cap = capacity();
2533 if (__cap - __sz + __n1 >= __n2)
2534 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002535 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002536 if (__n1 != __n2)
2537 {
2538 size_type __n_move = __sz - __pos - __n1;
2539 if (__n_move != 0)
2540 {
2541 if (__n1 > __n2)
2542 {
2543 traits_type::move(__p + __pos, __s, __n2);
2544 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2545 goto __finish;
2546 }
2547 if (__p + __pos < __s && __s < __p + __sz)
2548 {
2549 if (__p + __pos + __n1 <= __s)
2550 __s += __n2 - __n1;
2551 else // __p + __pos < __s < __p + __pos + __n1
2552 {
2553 traits_type::move(__p + __pos, __s, __n1);
2554 __pos += __n1;
2555 __s += __n2;
2556 __n2 -= __n1;
2557 __n1 = 0;
2558 }
2559 }
2560 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2561 }
2562 }
2563 traits_type::move(__p + __pos, __s, __n2);
2564__finish:
2565 __sz += __n2 - __n1;
2566 __set_size(__sz);
2567 __invalidate_iterators_past(__sz);
2568 traits_type::assign(__p[__sz], value_type());
2569 }
2570 else
2571 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2572 return *this;
2573}
2574
2575template <class _CharT, class _Traits, class _Allocator>
2576basic_string<_CharT, _Traits, _Allocator>&
2577basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
2578{
2579 size_type __sz = size();
2580 if (__pos > __sz)
2581 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002582 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002583 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002584 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002585 if (__cap - __sz + __n1 >= __n2)
2586 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002587 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002588 if (__n1 != __n2)
2589 {
2590 size_type __n_move = __sz - __pos - __n1;
2591 if (__n_move != 0)
2592 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2593 }
2594 }
2595 else
2596 {
2597 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002598 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002599 }
2600 traits_type::assign(__p + __pos, __n2, __c);
2601 __sz += __n2 - __n1;
2602 __set_size(__sz);
2603 __invalidate_iterators_past(__sz);
2604 traits_type::assign(__p[__sz], value_type());
2605 return *this;
2606}
2607
2608template <class _CharT, class _Traits, class _Allocator>
2609template<class _InputIterator>
2610typename enable_if
2611<
2612 __is_input_iterator<_InputIterator>::value,
2613 basic_string<_CharT, _Traits, _Allocator>&
2614>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002615basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002616 _InputIterator __j1, _InputIterator __j2)
2617{
Marshall Clowd979eed2016-09-05 01:54:30 +00002618 const basic_string __temp(__j1, __j2, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002619 return this->replace(__i1, __i2, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002620}
2621
2622template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002623inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002624basic_string<_CharT, _Traits, _Allocator>&
2625basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2626{
2627 return replace(__pos1, __n1, __str.data(), __str.size());
2628}
2629
2630template <class _CharT, class _Traits, class _Allocator>
2631basic_string<_CharT, _Traits, _Allocator>&
2632basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2633 size_type __pos2, size_type __n2)
2634{
2635 size_type __str_sz = __str.size();
2636 if (__pos2 > __str_sz)
2637 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002638 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002639}
2640
2641template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002642template <class _Tp>
2643typename enable_if
2644<
2645 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2646 basic_string<_CharT, _Traits, _Allocator>&
2647>::type
2648basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002649 size_type __pos2, size_type __n2)
2650{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002651 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002652 size_type __str_sz = __sv.size();
2653 if (__pos2 > __str_sz)
2654 this->__throw_out_of_range();
2655 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2656}
2657
2658template <class _CharT, class _Traits, class _Allocator>
2659basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002660basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002661{
Alp Tokerec34c482014-05-15 11:27:39 +00002662 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002663 return replace(__pos, __n1, __s, traits_type::length(__s));
2664}
2665
2666template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002667inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002668basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002669basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002670{
2671 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2672 __str.data(), __str.size());
2673}
2674
2675template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002676inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002677basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002678basic_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 +00002679{
2680 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2681}
2682
2683template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002684inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002685basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002686basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002687{
2688 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2689}
2690
2691template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002692inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002693basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002694basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002695{
2696 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2697}
2698
2699// erase
2700
2701template <class _CharT, class _Traits, class _Allocator>
2702basic_string<_CharT, _Traits, _Allocator>&
2703basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2704{
2705 size_type __sz = size();
2706 if (__pos > __sz)
2707 this->__throw_out_of_range();
2708 if (__n)
2709 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002710 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002711 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002712 size_type __n_move = __sz - __pos - __n;
2713 if (__n_move != 0)
2714 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2715 __sz -= __n;
2716 __set_size(__sz);
2717 __invalidate_iterators_past(__sz);
2718 traits_type::assign(__p[__sz], value_type());
2719 }
2720 return *this;
2721}
2722
2723template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002724inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002725typename basic_string<_CharT, _Traits, _Allocator>::iterator
2726basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2727{
Howard Hinnant499cea12013-08-23 17:37:05 +00002728#if _LIBCPP_DEBUG_LEVEL >= 2
2729 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2730 "string::erase(iterator) called with an iterator not"
2731 " referring to this string");
2732#endif
2733 _LIBCPP_ASSERT(__pos != end(),
2734 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002735 iterator __b = begin();
2736 size_type __r = static_cast<size_type>(__pos - __b);
2737 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00002738 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002739}
2740
2741template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002742inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002743typename basic_string<_CharT, _Traits, _Allocator>::iterator
2744basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
2745{
Howard Hinnant499cea12013-08-23 17:37:05 +00002746#if _LIBCPP_DEBUG_LEVEL >= 2
2747 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
2748 "string::erase(iterator, iterator) called with an iterator not"
2749 " referring to this string");
2750#endif
2751 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002752 iterator __b = begin();
2753 size_type __r = static_cast<size_type>(__first - __b);
2754 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00002755 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002756}
2757
2758template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002759inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002760void
2761basic_string<_CharT, _Traits, _Allocator>::pop_back()
2762{
Howard Hinnant499cea12013-08-23 17:37:05 +00002763 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002764 size_type __sz;
2765 if (__is_long())
2766 {
2767 __sz = __get_long_size() - 1;
2768 __set_long_size(__sz);
2769 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
2770 }
2771 else
2772 {
2773 __sz = __get_short_size() - 1;
2774 __set_short_size(__sz);
2775 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
2776 }
2777 __invalidate_iterators_past(__sz);
2778}
2779
2780template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002781inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002782void
Howard Hinnanta6119a82011-05-29 19:57:12 +00002783basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002784{
2785 __invalidate_all_iterators();
2786 if (__is_long())
2787 {
2788 traits_type::assign(*__get_long_pointer(), value_type());
2789 __set_long_size(0);
2790 }
2791 else
2792 {
2793 traits_type::assign(*__get_short_pointer(), value_type());
2794 __set_short_size(0);
2795 }
2796}
2797
2798template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002799inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002800void
2801basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
2802{
2803 if (__is_long())
2804 {
2805 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
2806 __set_long_size(__pos);
2807 }
2808 else
2809 {
2810 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
2811 __set_short_size(__pos);
2812 }
2813 __invalidate_iterators_past(__pos);
2814}
2815
2816template <class _CharT, class _Traits, class _Allocator>
2817void
2818basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
2819{
2820 size_type __sz = size();
2821 if (__n > __sz)
2822 append(__n - __sz, __c);
2823 else
2824 __erase_to_end(__n);
2825}
2826
2827template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002828inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002829typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00002830basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002831{
Howard Hinnante32b5e22010-11-17 17:55:08 +00002832 size_type __m = __alloc_traits::max_size(__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002833#if _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:08 +00002834 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002835#else
Marshall Clow09f85502013-10-31 17:23:08 +00002836 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002837#endif
2838}
2839
2840template <class _CharT, class _Traits, class _Allocator>
2841void
2842basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
2843{
2844 if (__res_arg > max_size())
2845 this->__throw_length_error();
2846 size_type __cap = capacity();
2847 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002848 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002849 __res_arg = __recommend(__res_arg);
2850 if (__res_arg != __cap)
2851 {
2852 pointer __new_data, __p;
2853 bool __was_long, __now_long;
2854 if (__res_arg == __min_cap - 1)
2855 {
2856 __was_long = true;
2857 __now_long = false;
2858 __new_data = __get_short_pointer();
2859 __p = __get_long_pointer();
2860 }
2861 else
2862 {
2863 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002864 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002865 else
2866 {
2867 #ifndef _LIBCPP_NO_EXCEPTIONS
2868 try
2869 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002870 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00002871 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002872 #ifndef _LIBCPP_NO_EXCEPTIONS
2873 }
2874 catch (...)
2875 {
2876 return;
2877 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002878 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002879 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002880 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00002881 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002882 }
2883 __now_long = true;
2884 __was_long = __is_long();
2885 __p = __get_pointer();
2886 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002887 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
2888 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002889 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002890 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002891 if (__now_long)
2892 {
2893 __set_long_cap(__res_arg+1);
2894 __set_long_size(__sz);
2895 __set_long_pointer(__new_data);
2896 }
2897 else
2898 __set_short_size(__sz);
2899 __invalidate_all_iterators();
2900 }
2901}
2902
2903template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002904inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002905typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002906basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002907{
Howard Hinnant499cea12013-08-23 17:37:05 +00002908 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002909 return *(data() + __pos);
2910}
2911
2912template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002913inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002914typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002915basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002916{
Howard Hinnant499cea12013-08-23 17:37:05 +00002917 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002918 return *(__get_pointer() + __pos);
2919}
2920
2921template <class _CharT, class _Traits, class _Allocator>
2922typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2923basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
2924{
2925 if (__n >= size())
2926 this->__throw_out_of_range();
2927 return (*this)[__n];
2928}
2929
2930template <class _CharT, class _Traits, class _Allocator>
2931typename basic_string<_CharT, _Traits, _Allocator>::reference
2932basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
2933{
2934 if (__n >= size())
2935 this->__throw_out_of_range();
2936 return (*this)[__n];
2937}
2938
2939template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002940inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002941typename basic_string<_CharT, _Traits, _Allocator>::reference
2942basic_string<_CharT, _Traits, _Allocator>::front()
2943{
Howard Hinnant499cea12013-08-23 17:37:05 +00002944 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002945 return *__get_pointer();
2946}
2947
2948template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002949inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002950typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2951basic_string<_CharT, _Traits, _Allocator>::front() const
2952{
Howard Hinnant499cea12013-08-23 17:37:05 +00002953 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002954 return *data();
2955}
2956
2957template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002958inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002959typename basic_string<_CharT, _Traits, _Allocator>::reference
2960basic_string<_CharT, _Traits, _Allocator>::back()
2961{
Howard Hinnant499cea12013-08-23 17:37:05 +00002962 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002963 return *(__get_pointer() + size() - 1);
2964}
2965
2966template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002967inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002968typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2969basic_string<_CharT, _Traits, _Allocator>::back() const
2970{
Howard Hinnant499cea12013-08-23 17:37:05 +00002971 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002972 return *(data() + size() - 1);
2973}
2974
2975template <class _CharT, class _Traits, class _Allocator>
2976typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002977basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002978{
2979 size_type __sz = size();
2980 if (__pos > __sz)
2981 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002982 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002983 traits_type::copy(__s, data() + __pos, __rlen);
2984 return __rlen;
2985}
2986
2987template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002988inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002989basic_string<_CharT, _Traits, _Allocator>
2990basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
2991{
2992 return basic_string(*this, __pos, __n, __alloc());
2993}
2994
2995template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002996inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002997void
2998basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00002999#if _LIBCPP_STD_VER >= 14
Eric Fiselier47257c42016-12-28 05:53:01 +00003000 _NOEXCEPT_DEBUG
Marshall Clow7d914d12015-07-13 20:04:56 +00003001#else
Eric Fiselier47257c42016-12-28 05:53:01 +00003002 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56 +00003003 __is_nothrow_swappable<allocator_type>::value)
3004#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003005{
Howard Hinnant499cea12013-08-23 17:37:05 +00003006#if _LIBCPP_DEBUG_LEVEL >= 2
3007 if (!__is_long())
3008 __get_db()->__invalidate_all(this);
3009 if (!__str.__is_long())
3010 __get_db()->__invalidate_all(&__str);
3011 __get_db()->swap(this, &__str);
3012#endif
Eric Fiselier47257c42016-12-28 05:53:01 +00003013 _LIBCPP_ASSERT(
3014 __alloc_traits::propagate_on_container_swap::value ||
3015 __alloc_traits::is_always_equal::value ||
3016 __alloc() == __str.__alloc(), "swapping non-equal allocators");
Howard Hinnant0949eed2011-06-30 21:18:19 +00003017 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow7d914d12015-07-13 20:04:56 +00003018 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003019}
3020
3021// find
3022
3023template <class _Traits>
3024struct _LIBCPP_HIDDEN __traits_eq
3025{
3026 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003027 _LIBCPP_INLINE_VISIBILITY
3028 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3029 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003030};
3031
3032template<class _CharT, class _Traits, class _Allocator>
3033typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003034basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003035 size_type __pos,
3036 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003037{
Alp Tokerec34c482014-05-15 11:27:39 +00003038 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003039 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003040 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003041}
3042
3043template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003044inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003045typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003046basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3047 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003048{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003049 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003050 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003051}
3052
3053template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003054inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003055typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003056basic_string<_CharT, _Traits, _Allocator>::find(__self_view __sv,
3057 size_type __pos) const _NOEXCEPT
3058{
3059 return __str_find<value_type, size_type, traits_type, npos>
3060 (data(), size(), __sv.data(), __pos, __sv.size());
3061}
3062
3063template<class _CharT, class _Traits, class _Allocator>
3064inline _LIBCPP_INLINE_VISIBILITY
3065typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003066basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003067 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003068{
Alp Tokerec34c482014-05-15 11:27:39 +00003069 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003070 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003071 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003072}
3073
3074template<class _CharT, class _Traits, class _Allocator>
3075typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003076basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3077 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003078{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003079 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003080 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003081}
3082
3083// rfind
3084
3085template<class _CharT, class _Traits, class _Allocator>
3086typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003087basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003088 size_type __pos,
3089 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003090{
Alp Tokerec34c482014-05-15 11:27:39 +00003091 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003092 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003093 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003094}
3095
3096template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003097inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003098typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003099basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3100 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003101{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003102 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003103 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003104}
3105
3106template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003107inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003108typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003109basic_string<_CharT, _Traits, _Allocator>::rfind(__self_view __sv,
3110 size_type __pos) const _NOEXCEPT
3111{
3112 return __str_rfind<value_type, size_type, traits_type, npos>
3113 (data(), size(), __sv.data(), __pos, __sv.size());
3114}
3115
3116template<class _CharT, class _Traits, class _Allocator>
3117inline _LIBCPP_INLINE_VISIBILITY
3118typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003119basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003120 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003121{
Alp Tokerec34c482014-05-15 11:27:39 +00003122 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003123 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003124 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003125}
3126
3127template<class _CharT, class _Traits, class _Allocator>
3128typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003129basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3130 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003131{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003132 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003133 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003134}
3135
3136// find_first_of
3137
3138template<class _CharT, class _Traits, class _Allocator>
3139typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003140basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003141 size_type __pos,
3142 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003143{
Alp Tokerec34c482014-05-15 11:27:39 +00003144 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003145 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003146 (data(), size(), __s, __pos, __n);
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 +00003151typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003152basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3153 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003154{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003155 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003156 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003157}
3158
3159template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003160inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003161typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003162basic_string<_CharT, _Traits, _Allocator>::find_first_of(__self_view __sv,
3163 size_type __pos) const _NOEXCEPT
3164{
3165 return __str_find_first_of<value_type, size_type, traits_type, npos>
3166 (data(), size(), __sv.data(), __pos, __sv.size());
3167}
3168
3169template<class _CharT, class _Traits, class _Allocator>
3170inline _LIBCPP_INLINE_VISIBILITY
3171typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003172basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003173 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003174{
Alp Tokerec34c482014-05-15 11:27:39 +00003175 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003176 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003177 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003178}
3179
3180template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003181inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003182typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003183basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3184 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003185{
3186 return find(__c, __pos);
3187}
3188
3189// find_last_of
3190
3191template<class _CharT, class _Traits, class _Allocator>
3192typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003193basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003194 size_type __pos,
3195 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003196{
Alp Tokerec34c482014-05-15 11:27:39 +00003197 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003198 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003199 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003200}
3201
3202template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003203inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003204typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003205basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3206 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003207{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003208 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003209 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003210}
3211
3212template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003213inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003214typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003215basic_string<_CharT, _Traits, _Allocator>::find_last_of(__self_view __sv,
3216 size_type __pos) const _NOEXCEPT
3217{
3218 return __str_find_last_of<value_type, size_type, traits_type, npos>
3219 (data(), size(), __sv.data(), __pos, __sv.size());
3220}
3221
3222template<class _CharT, class _Traits, class _Allocator>
3223inline _LIBCPP_INLINE_VISIBILITY
3224typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003225basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003226 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003227{
Alp Tokerec34c482014-05-15 11:27:39 +00003228 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003229 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003230 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003231}
3232
3233template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003234inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003235typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003236basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3237 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003238{
3239 return rfind(__c, __pos);
3240}
3241
3242// find_first_not_of
3243
3244template<class _CharT, class _Traits, class _Allocator>
3245typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003246basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003247 size_type __pos,
3248 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003249{
Alp Tokerec34c482014-05-15 11:27:39 +00003250 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003251 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003252 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003253}
3254
3255template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003256inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003257typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003258basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3259 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003260{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003261 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003262 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003263}
3264
3265template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003266inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003267typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003268basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(__self_view __sv,
3269 size_type __pos) const _NOEXCEPT
3270{
3271 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3272 (data(), size(), __sv.data(), __pos, __sv.size());
3273}
3274
3275template<class _CharT, class _Traits, class _Allocator>
3276inline _LIBCPP_INLINE_VISIBILITY
3277typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003278basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003279 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003280{
Alp Tokerec34c482014-05-15 11:27:39 +00003281 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003282 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003283 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003284}
3285
3286template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003287inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003288typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003289basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3290 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003291{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003292 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003293 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003294}
3295
3296// find_last_not_of
3297
3298template<class _CharT, class _Traits, class _Allocator>
3299typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003300basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003301 size_type __pos,
3302 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003303{
Alp Tokerec34c482014-05-15 11:27:39 +00003304 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003305 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003306 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003307}
3308
3309template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003310inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003311typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003312basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3313 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003314{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003315 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003316 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003317}
3318
3319template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003320inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003321typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003322basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(__self_view __sv,
3323 size_type __pos) const _NOEXCEPT
3324{
3325 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3326 (data(), size(), __sv.data(), __pos, __sv.size());
3327}
3328
3329template<class _CharT, class _Traits, class _Allocator>
3330inline _LIBCPP_INLINE_VISIBILITY
3331typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003332basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003333 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003334{
Alp Tokerec34c482014-05-15 11:27:39 +00003335 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003336 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003337 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003338}
3339
3340template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003341inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003342typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003343basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3344 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003345{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003346 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003347 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003348}
3349
3350// compare
3351
3352template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003353inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003354int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003355basic_string<_CharT, _Traits, _Allocator>::compare(__self_view __sv) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003356{
Howard Hinnantfa06d752011-07-24 21:45:06 +00003357 size_t __lhs_sz = size();
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003358 size_t __rhs_sz = __sv.size();
3359 int __result = traits_type::compare(data(), __sv.data(),
Howard Hinnantfa06d752011-07-24 21:45:06 +00003360 _VSTD::min(__lhs_sz, __rhs_sz));
3361 if (__result != 0)
3362 return __result;
3363 if (__lhs_sz < __rhs_sz)
3364 return -1;
3365 if (__lhs_sz > __rhs_sz)
3366 return 1;
3367 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003368}
3369
3370template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003371inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003372int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003373basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003374{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003375 return compare(__self_view(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003376}
3377
3378template <class _CharT, class _Traits, class _Allocator>
3379int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003380basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3381 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003382 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003383 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003384{
Alp Tokerec34c482014-05-15 11:27:39 +00003385 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003386 size_type __sz = size();
3387 if (__pos1 > __sz || __n2 == npos)
3388 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003389 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3390 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003391 if (__r == 0)
3392 {
3393 if (__rlen < __n2)
3394 __r = -1;
3395 else if (__rlen > __n2)
3396 __r = 1;
3397 }
3398 return __r;
3399}
3400
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003401template <class _CharT, class _Traits, class _Allocator>
3402inline _LIBCPP_INLINE_VISIBILITY
3403int
3404basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3405 size_type __n1,
3406 __self_view __sv) const
3407{
3408 return compare(__pos1, __n1, __sv.data(), __sv.size());
3409}
3410
3411template <class _CharT, class _Traits, class _Allocator>
3412inline _LIBCPP_INLINE_VISIBILITY
3413int
3414basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3415 size_type __n1,
3416 const basic_string& __str) const
3417{
3418 return compare(__pos1, __n1, __str.data(), __str.size());
3419}
3420
3421template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00003422template <class _Tp>
3423typename enable_if
3424<
3425 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3426 int
3427>::type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003428basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3429 size_type __n1,
Marshall Clow6ac8de02016-09-24 22:45:42 +00003430 const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003431 size_type __pos2,
3432 size_type __n2) const
3433{
Marshall Clow6ac8de02016-09-24 22:45:42 +00003434 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003435 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3436}
3437
3438template <class _CharT, class _Traits, class _Allocator>
3439int
3440basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3441 size_type __n1,
3442 const basic_string& __str,
3443 size_type __pos2,
3444 size_type __n2) const
3445{
3446 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3447}
3448
3449template <class _CharT, class _Traits, class _Allocator>
3450int
3451basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3452{
3453 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3454 return compare(0, npos, __s, traits_type::length(__s));
3455}
3456
3457template <class _CharT, class _Traits, class _Allocator>
3458int
3459basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3460 size_type __n1,
3461 const value_type* __s) const
3462{
3463 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3464 return compare(__pos1, __n1, __s, traits_type::length(__s));
3465}
3466
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003467// __invariants
3468
3469template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003470inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003471bool
3472basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3473{
3474 if (size() > capacity())
3475 return false;
3476 if (capacity() < __min_cap - 1)
3477 return false;
3478 if (data() == 0)
3479 return false;
3480 if (data()[size()] != value_type(0))
3481 return false;
3482 return true;
3483}
3484
3485// operator==
3486
3487template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003488inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003489bool
3490operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003491 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003492{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003493 size_t __lhs_sz = __lhs.size();
3494 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3495 __rhs.data(),
3496 __lhs_sz) == 0;
3497}
3498
3499template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003500inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:13 +00003501bool
3502operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3503 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3504{
3505 size_t __lhs_sz = __lhs.size();
3506 if (__lhs_sz != __rhs.size())
3507 return false;
3508 const char* __lp = __lhs.data();
3509 const char* __rp = __rhs.data();
3510 if (__lhs.__is_long())
3511 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3512 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3513 if (*__lp != *__rp)
3514 return false;
3515 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003516}
3517
3518template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003519inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003520bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003521operator==(const _CharT* __lhs,
3522 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003523{
Eric Fiselier4f241822015-08-28 03:02:37 +00003524 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3525 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3526 size_t __lhs_len = _Traits::length(__lhs);
3527 if (__lhs_len != __rhs.size()) return false;
3528 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003529}
3530
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003531template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003532inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003533bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003534operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3535 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003536{
Eric Fiselier4f241822015-08-28 03:02:37 +00003537 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3538 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3539 size_t __rhs_len = _Traits::length(__rhs);
3540 if (__rhs_len != __lhs.size()) return false;
3541 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003542}
3543
Howard Hinnant324bb032010-08-22 00:02:43 +00003544template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003545inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003546bool
3547operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003548 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003549{
3550 return !(__lhs == __rhs);
3551}
3552
3553template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003554inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003555bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003556operator!=(const _CharT* __lhs,
3557 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003558{
3559 return !(__lhs == __rhs);
3560}
3561
3562template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003563inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003564bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003565operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3566 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003567{
3568 return !(__lhs == __rhs);
3569}
3570
3571// operator<
3572
3573template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003574inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003575bool
3576operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003577 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003578{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003579 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003580}
3581
3582template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003583inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003584bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003585operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3586 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003587{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003588 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003589}
3590
3591template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003592inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003593bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003594operator< (const _CharT* __lhs,
3595 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003596{
3597 return __rhs.compare(__lhs) > 0;
3598}
3599
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003600// operator>
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 +00003604bool
3605operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003606 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003607{
3608 return __rhs < __lhs;
3609}
3610
3611template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003612inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003613bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003614operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3615 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003616{
3617 return __rhs < __lhs;
3618}
3619
3620template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003621inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003622bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003623operator> (const _CharT* __lhs,
3624 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003625{
3626 return __rhs < __lhs;
3627}
3628
3629// operator<=
3630
3631template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003632inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003633bool
3634operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003635 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003636{
3637 return !(__rhs < __lhs);
3638}
3639
3640template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003641inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003642bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003643operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3644 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003645{
3646 return !(__rhs < __lhs);
3647}
3648
3649template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003650inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003651bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003652operator<=(const _CharT* __lhs,
3653 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003654{
3655 return !(__rhs < __lhs);
3656}
3657
3658// operator>=
3659
3660template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003661inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003662bool
3663operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003664 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003665{
3666 return !(__lhs < __rhs);
3667}
3668
3669template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003670inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003671bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003672operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3673 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003674{
3675 return !(__lhs < __rhs);
3676}
3677
3678template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003679inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003680bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003681operator>=(const _CharT* __lhs,
3682 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003683{
3684 return !(__lhs < __rhs);
3685}
3686
3687// operator +
3688
3689template<class _CharT, class _Traits, class _Allocator>
3690basic_string<_CharT, _Traits, _Allocator>
3691operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3692 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3693{
3694 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3695 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3696 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3697 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3698 __r.append(__rhs.data(), __rhs_sz);
3699 return __r;
3700}
3701
3702template<class _CharT, class _Traits, class _Allocator>
3703basic_string<_CharT, _Traits, _Allocator>
3704operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3705{
3706 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3707 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
3708 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3709 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
3710 __r.append(__rhs.data(), __rhs_sz);
3711 return __r;
3712}
3713
3714template<class _CharT, class _Traits, class _Allocator>
3715basic_string<_CharT, _Traits, _Allocator>
3716operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3717{
3718 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3719 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3720 __r.__init(&__lhs, 1, 1 + __rhs_sz);
3721 __r.append(__rhs.data(), __rhs_sz);
3722 return __r;
3723}
3724
3725template<class _CharT, class _Traits, class _Allocator>
3726basic_string<_CharT, _Traits, _Allocator>
3727operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
3728{
3729 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3730 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3731 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
3732 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3733 __r.append(__rhs, __rhs_sz);
3734 return __r;
3735}
3736
3737template<class _CharT, class _Traits, class _Allocator>
3738basic_string<_CharT, _Traits, _Allocator>
3739operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
3740{
3741 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3742 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3743 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
3744 __r.push_back(__rhs);
3745 return __r;
3746}
3747
Howard Hinnant73d21a42010-09-04 23:28:19 +00003748#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003749
3750template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003751inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003752basic_string<_CharT, _Traits, _Allocator>
3753operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3754{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003755 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003756}
3757
3758template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003759inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003760basic_string<_CharT, _Traits, _Allocator>
3761operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3762{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003763 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003764}
3765
3766template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003767inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003768basic_string<_CharT, _Traits, _Allocator>
3769operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3770{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003771 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003772}
3773
3774template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003775inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003776basic_string<_CharT, _Traits, _Allocator>
3777operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3778{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003779 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003780}
3781
3782template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003783inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003784basic_string<_CharT, _Traits, _Allocator>
3785operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3786{
3787 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003788 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003789}
3790
3791template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003792inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003793basic_string<_CharT, _Traits, _Allocator>
3794operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
3795{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003796 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003797}
3798
3799template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003800inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003801basic_string<_CharT, _Traits, _Allocator>
3802operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
3803{
3804 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003805 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003806}
3807
Howard Hinnant73d21a42010-09-04 23:28:19 +00003808#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003809
3810// swap
3811
3812template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003813inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003814void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003815swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00003816 basic_string<_CharT, _Traits, _Allocator>& __rhs)
3817 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003818{
3819 __lhs.swap(__rhs);
3820}
3821
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003822#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
3823
3824typedef basic_string<char16_t> u16string;
3825typedef basic_string<char32_t> u32string;
3826
Howard Hinnant324bb032010-08-22 00:02:43 +00003827#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003828
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003829_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
3830_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
3831_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
3832_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
3833_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003834
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003835_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
3836_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
3837_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003838
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003839_LIBCPP_FUNC_VIS string to_string(int __val);
3840_LIBCPP_FUNC_VIS string to_string(unsigned __val);
3841_LIBCPP_FUNC_VIS string to_string(long __val);
3842_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
3843_LIBCPP_FUNC_VIS string to_string(long long __val);
3844_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
3845_LIBCPP_FUNC_VIS string to_string(float __val);
3846_LIBCPP_FUNC_VIS string to_string(double __val);
3847_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003848
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003849_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
3850_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
3851_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
3852_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
3853_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003854
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003855_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
3856_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
3857_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003858
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003859_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
3860_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
3861_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
3862_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
3863_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
3864_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
3865_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
3866_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
3867_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003868
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003869template<class _CharT, class _Traits, class _Allocator>
3870 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
3871 basic_string<_CharT, _Traits, _Allocator>::npos;
3872
3873template<class _CharT, class _Traits, class _Allocator>
Eric Fiselierc3589a82017-01-04 23:56:00 +00003874struct _LIBCPP_TEMPLATE_VIS hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003875 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
3876{
3877 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00003878 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003879};
3880
3881template<class _CharT, class _Traits, class _Allocator>
3882size_t
3883hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00003884 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003885{
Sean Huntaffd9e52011-07-29 23:31:56 +00003886 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003887}
3888
Howard Hinnant464aa5c2011-07-18 15:51:59 +00003889template<class _CharT, class _Traits, class _Allocator>
3890basic_ostream<_CharT, _Traits>&
3891operator<<(basic_ostream<_CharT, _Traits>& __os,
3892 const basic_string<_CharT, _Traits, _Allocator>& __str);
3893
3894template<class _CharT, class _Traits, class _Allocator>
3895basic_istream<_CharT, _Traits>&
3896operator>>(basic_istream<_CharT, _Traits>& __is,
3897 basic_string<_CharT, _Traits, _Allocator>& __str);
3898
3899template<class _CharT, class _Traits, class _Allocator>
3900basic_istream<_CharT, _Traits>&
3901getline(basic_istream<_CharT, _Traits>& __is,
3902 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3903
3904template<class _CharT, class _Traits, class _Allocator>
3905inline _LIBCPP_INLINE_VISIBILITY
3906basic_istream<_CharT, _Traits>&
3907getline(basic_istream<_CharT, _Traits>& __is,
3908 basic_string<_CharT, _Traits, _Allocator>& __str);
3909
3910#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3911
3912template<class _CharT, class _Traits, class _Allocator>
3913inline _LIBCPP_INLINE_VISIBILITY
3914basic_istream<_CharT, _Traits>&
3915getline(basic_istream<_CharT, _Traits>&& __is,
3916 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3917
3918template<class _CharT, class _Traits, class _Allocator>
3919inline _LIBCPP_INLINE_VISIBILITY
3920basic_istream<_CharT, _Traits>&
3921getline(basic_istream<_CharT, _Traits>&& __is,
3922 basic_string<_CharT, _Traits, _Allocator>& __str);
3923
3924#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3925
Howard Hinnant499cea12013-08-23 17:37:05 +00003926#if _LIBCPP_DEBUG_LEVEL >= 2
3927
3928template<class _CharT, class _Traits, class _Allocator>
3929bool
3930basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
3931{
3932 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
3933 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
3934}
3935
3936template<class _CharT, class _Traits, class _Allocator>
3937bool
3938basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
3939{
3940 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
3941 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
3942}
3943
3944template<class _CharT, class _Traits, class _Allocator>
3945bool
3946basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
3947{
3948 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
3949 return this->data() <= __p && __p <= this->data() + this->size();
3950}
3951
3952template<class _CharT, class _Traits, class _Allocator>
3953bool
3954basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
3955{
3956 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
3957 return this->data() <= __p && __p < this->data() + this->size();
3958}
3959
3960#endif // _LIBCPP_DEBUG_LEVEL >= 2
3961
Marshall Clow15234322013-07-23 17:05:24 +00003962#if _LIBCPP_STD_VER > 11
3963// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:32 +00003964inline namespace literals
Marshall Clow15234322013-07-23 17:05:24 +00003965{
3966 inline namespace string_literals
3967 {
Howard Hinnantab61b2c2013-08-07 19:39:48 +00003968 inline _LIBCPP_INLINE_VISIBILITY
3969 basic_string<char> operator "" s( const char *__str, size_t __len )
3970 {
3971 return basic_string<char> (__str, __len);
3972 }
Marshall Clow15234322013-07-23 17:05:24 +00003973
Howard Hinnantab61b2c2013-08-07 19:39:48 +00003974 inline _LIBCPP_INLINE_VISIBILITY
3975 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
3976 {
3977 return basic_string<wchar_t> (__str, __len);
3978 }
Marshall Clow15234322013-07-23 17:05:24 +00003979
Howard Hinnantab61b2c2013-08-07 19:39:48 +00003980 inline _LIBCPP_INLINE_VISIBILITY
3981 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
3982 {
3983 return basic_string<char16_t> (__str, __len);
3984 }
Marshall Clow15234322013-07-23 17:05:24 +00003985
Howard Hinnantab61b2c2013-08-07 19:39:48 +00003986 inline _LIBCPP_INLINE_VISIBILITY
3987 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
3988 {
3989 return basic_string<char32_t> (__str, __len);
3990 }
Marshall Clow15234322013-07-23 17:05:24 +00003991 }
3992}
3993#endif
3994
Eric Fiselier833d6442016-09-15 22:27:07 +00003995_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>)
3996_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>)
Howard Hinnant499cea12013-08-23 17:37:05 +00003997_LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003998
3999_LIBCPP_END_NAMESPACE_STD
4000
4001#endif // _LIBCPP_STRING