blob: 6666d509584674ae72679c63b048d2cb99b54c61 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
Louis Dionne9bd93882021-11-17 16:25:01 -05002//===----------------------------------------------------------------------===//
Howard Hinnantc51e1022010-05-11 19:42:16 +00003//
Chandler Carruth7642bb12019-01-19 08:50:56 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_STRING
11#define _LIBCPP_STRING
12
13/*
14 string synopsis
15
16namespace std
17{
18
19template <class stateT>
20class fpos
21{
22private:
23 stateT st;
24public:
25 fpos(streamoff = streamoff());
26
27 operator streamoff() const;
28
29 stateT state() const;
30 void state(stateT);
31
32 fpos& operator+=(streamoff);
33 fpos operator+ (streamoff) const;
34 fpos& operator-=(streamoff);
35 fpos operator- (streamoff) const;
36};
37
38template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y);
39
40template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y);
41template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y);
42
43template <class charT>
44struct char_traits
45{
46 typedef charT char_type;
47 typedef ... int_type;
48 typedef streamoff off_type;
49 typedef streampos pos_type;
50 typedef mbstate_t state_type;
51
Howard Hinnantaeb17d82011-05-29 19:57:12 +000052 static void assign(char_type& c1, const char_type& c2) noexcept;
Howard Hinnant270c00e2012-07-20 19:09:12 +000053 static constexpr bool eq(char_type c1, char_type c2) noexcept;
54 static constexpr bool lt(char_type c1, char_type c2) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000055
56 static int compare(const char_type* s1, const char_type* s2, size_t n);
57 static size_t length(const char_type* s);
58 static const char_type* find(const char_type* s, size_t n, const char_type& a);
59 static char_type* move(char_type* s1, const char_type* s2, size_t n);
60 static char_type* copy(char_type* s1, const char_type* s2, size_t n);
61 static char_type* assign(char_type* s, size_t n, char_type a);
62
Howard Hinnant270c00e2012-07-20 19:09:12 +000063 static constexpr int_type not_eof(int_type c) noexcept;
64 static constexpr char_type to_char_type(int_type c) noexcept;
65 static constexpr int_type to_int_type(char_type c) noexcept;
66 static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept;
67 static constexpr int_type eof() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000068};
69
70template <> struct char_traits<char>;
71template <> struct char_traits<wchar_t>;
Marek Kurdeje3ac4e22021-03-23 17:15:07 +010072template <> struct char_traits<char8_t>; // C++20
73template <> struct char_traits<char16_t>;
74template <> struct char_traits<char32_t>;
Howard Hinnantc51e1022010-05-11 19:42:16 +000075
Howard Hinnant3b6579a2010-08-22 00:02:43 +000076template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
Howard Hinnantc51e1022010-05-11 19:42:16 +000077class basic_string
78{
Howard Hinnant3b6579a2010-08-22 00:02:43 +000079public:
80// types:
Howard Hinnantc51e1022010-05-11 19:42:16 +000081 typedef traits traits_type;
82 typedef typename traits_type::char_type value_type;
83 typedef Allocator allocator_type;
84 typedef typename allocator_type::size_type size_type;
85 typedef typename allocator_type::difference_type difference_type;
86 typedef typename allocator_type::reference reference;
87 typedef typename allocator_type::const_reference const_reference;
88 typedef typename allocator_type::pointer pointer;
89 typedef typename allocator_type::const_pointer const_pointer;
90 typedef implementation-defined iterator;
91 typedef implementation-defined const_iterator;
92 typedef std::reverse_iterator<iterator> reverse_iterator;
93 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
94
95 static const size_type npos = -1;
96
Howard Hinnant3e276872011-06-03 18:40:47 +000097 basic_string()
Nikolas Klauser80b3cf32022-04-27 10:11:44 +020098 noexcept(is_nothrow_default_constructible<allocator_type>::value); // constexpr since C++20
99 explicit basic_string(const allocator_type& a); // constexpr since C++20
100 basic_string(const basic_string& str); // constexpr since C++20
Howard Hinnant3e276872011-06-03 18:40:47 +0000101 basic_string(basic_string&& str)
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200102 noexcept(is_nothrow_move_constructible<allocator_type>::value); // constexpr since C++20
Marshall Clow83445802016-04-07 18:13:41 +0000103 basic_string(const basic_string& str, size_type pos,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200104 const allocator_type& a = allocator_type()); // constexpr since C++20
Marshall Clow83445802016-04-07 18:13:41 +0000105 basic_string(const basic_string& str, size_type pos, size_type n,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200106 const Allocator& a = Allocator()); // constexpr since C++20
Marshall Clow78dbe462016-11-14 18:22:19 +0000107 template<class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200108 basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17, constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000109 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200110 explicit basic_string(const T& t, const Allocator& a = Allocator()); // C++17, constexpr since C++20
111 basic_string(const value_type* s, const allocator_type& a = allocator_type()); // constexpr since C++20
112 basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type()); // constexpr since C++20
Marek Kurdej90d79712021-07-27 16:16:21 +0200113 basic_string(nullptr_t) = delete; // C++2b
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200114 basic_string(size_type n, value_type c, const allocator_type& a = allocator_type()); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000115 template<class InputIterator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000116 basic_string(InputIterator begin, InputIterator end,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200117 const allocator_type& a = allocator_type()); // constexpr since C++20
118 basic_string(initializer_list<value_type>, const Allocator& = Allocator()); // constexpr since C++20
119 basic_string(const basic_string&, const Allocator&); // constexpr since C++20
120 basic_string(basic_string&&, const Allocator&); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000121
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200122 ~basic_string(); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000123
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200124 operator basic_string_view<charT, traits>() const noexcept; // constexpr since C++20
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000125
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200126 basic_string& operator=(const basic_string& str); // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000127 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200128 basic_string& operator=(const T& t); // C++17, constexpr since C++20
Howard Hinnant3e276872011-06-03 18:40:47 +0000129 basic_string& operator=(basic_string&& str)
130 noexcept(
Marshall Clow2fe8a8d2015-08-18 18:57:00 +0000131 allocator_type::propagate_on_container_move_assignment::value ||
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200132 allocator_type::is_always_equal::value ); // C++17, constexpr since C++20
133 basic_string& operator=(const value_type* s); // constexpr since C++20
Marek Kurdej90d79712021-07-27 16:16:21 +0200134 basic_string& operator=(nullptr_t) = delete; // C++2b
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200135 basic_string& operator=(value_type c); // constexpr since C++20
136 basic_string& operator=(initializer_list<value_type>); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000137
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200138 iterator begin() noexcept; // constexpr since C++20
139 const_iterator begin() const noexcept; // constexpr since C++20
140 iterator end() noexcept; // constexpr since C++20
141 const_iterator end() const noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000142
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200143 reverse_iterator rbegin() noexcept; // constexpr since C++20
144 const_reverse_iterator rbegin() const noexcept; // constexpr since C++20
145 reverse_iterator rend() noexcept; // constexpr since C++20
146 const_reverse_iterator rend() const noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000147
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200148 const_iterator cbegin() const noexcept; // constexpr since C++20
149 const_iterator cend() const noexcept; // constexpr since C++20
150 const_reverse_iterator crbegin() const noexcept; // constexpr since C++20
151 const_reverse_iterator crend() const noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000152
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200153 size_type size() const noexcept; // constexpr since C++20
154 size_type length() const noexcept; // constexpr since C++20
155 size_type max_size() const noexcept; // constexpr since C++20
156 size_type capacity() const noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000157
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200158 void resize(size_type n, value_type c); // constexpr since C++20
159 void resize(size_type n); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000160
Nikolas Klauser9e6040c2022-01-06 21:43:26 +0100161 template<class Operation>
162 constexpr void resize_and_overwrite(size_type n, Operation op); // since C++23
163
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200164 void reserve(size_type res_arg); // constexpr since C++20
Marek Kurdejc9848142020-11-26 10:07:16 +0100165 void reserve(); // deprecated in C++20
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200166 void shrink_to_fit(); // constexpr since C++20
167 void clear() noexcept; // constexpr since C++20
168 bool empty() const noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000169
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200170 const_reference operator[](size_type pos) const; // constexpr since C++20
171 reference operator[](size_type pos); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000172
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200173 const_reference at(size_type n) const; // constexpr since C++20
174 reference at(size_type n); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000175
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200176 basic_string& operator+=(const basic_string& str); // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000177 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200178 basic_string& operator+=(const T& t); // C++17, constexpr since C++20
179 basic_string& operator+=(const value_type* s); // constexpr since C++20
180 basic_string& operator+=(value_type c); // constexpr since C++20
181 basic_string& operator+=(initializer_list<value_type>); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000182
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200183 basic_string& append(const basic_string& str); // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000184 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200185 basic_string& append(const T& t); // C++17, constexpr since C++20
186 basic_string& append(const basic_string& str, size_type pos, size_type n=npos); // C++14, constexpr since C++20
Marshall Clow82513342016-09-24 22:45:42 +0000187 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200188 basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17, constexpr since C++20
189 basic_string& append(const value_type* s, size_type n); // constexpr since C++20
190 basic_string& append(const value_type* s); // constexpr since C++20
191 basic_string& append(size_type n, value_type c); // constexpr since C++20
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000192 template<class InputIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200193 basic_string& append(InputIterator first, InputIterator last); // constexpr since C++20
194 basic_string& append(initializer_list<value_type>); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000195
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200196 void push_back(value_type c); // constexpr since C++20
197 void pop_back(); // constexpr since C++20
198 reference front(); // constexpr since C++20
199 const_reference front() const; // constexpr since C++20
200 reference back(); // constexpr since C++20
201 const_reference back() const; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000202
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200203 basic_string& assign(const basic_string& str); // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000204 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200205 basic_string& assign(const T& t); // C++17, constexpr since C++20
206 basic_string& assign(basic_string&& str); // constexpr since C++20
207 basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14, constexpr since C++20
Marshall Clow82513342016-09-24 22:45:42 +0000208 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200209 basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17, constexpr since C++20
210 basic_string& assign(const value_type* s, size_type n); // constexpr since C++20
211 basic_string& assign(const value_type* s); // constexpr since C++20
212 basic_string& assign(size_type n, value_type c); // constexpr since C++20
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000213 template<class InputIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200214 basic_string& assign(InputIterator first, InputIterator last); // constexpr since C++20
215 basic_string& assign(initializer_list<value_type>); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000216
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200217 basic_string& insert(size_type pos1, const basic_string& str); // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000218 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200219 basic_string& insert(size_type pos1, const T& t); // constexpr since C++20
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000220 basic_string& insert(size_type pos1, const basic_string& str,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200221 size_type pos2, size_type n); // constexpr since C++20
Marshall Clow82513342016-09-24 22:45:42 +0000222 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200223 basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17, constexpr since C++20
224 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); // C++14, constexpr since C++20
225 basic_string& insert(size_type pos, const value_type* s); // constexpr since C++20
226 basic_string& insert(size_type pos, size_type n, value_type c); // constexpr since C++20
227 iterator insert(const_iterator p, value_type c); // constexpr since C++20
228 iterator insert(const_iterator p, size_type n, value_type c); // constexpr since C++20
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000229 template<class InputIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200230 iterator insert(const_iterator p, InputIterator first, InputIterator last); // constexpr since C++20
231 iterator insert(const_iterator p, initializer_list<value_type>); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000232
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200233 basic_string& erase(size_type pos = 0, size_type n = npos); // constexpr since C++20
234 iterator erase(const_iterator position); // constexpr since C++20
235 iterator erase(const_iterator first, const_iterator last); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000236
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200237 basic_string& replace(size_type pos1, size_type n1, const basic_string& str); // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000238 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200239 basic_string& replace(size_type pos1, size_type n1, const T& t); // C++17, constexpr since C++20
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000240 basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200241 size_type pos2, size_type n2=npos); // C++14, constexpr since C++20
Marshall Clow82513342016-09-24 22:45:42 +0000242 template <class T>
243 basic_string& replace(size_type pos1, size_type n1, const T& t,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200244 size_type pos2, size_type n); // C++17, constexpr since C++20
245 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2); // constexpr since C++20
246 basic_string& replace(size_type pos, size_type n1, const value_type* s); // constexpr since C++20
247 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c); // constexpr since C++20
248 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str); // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000249 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200250 basic_string& replace(const_iterator i1, const_iterator i2, const T& t); // C++17, constexpr since C++20
251 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n); // constexpr since C++20
252 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s); // constexpr since C++20
253 basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c); // constexpr since C++20
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000254 template<class InputIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200255 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2); // constexpr since C++20
256 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000257
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200258 size_type copy(value_type* s, size_type n, size_type pos = 0) const; // constexpr since C++20
259 basic_string substr(size_type pos = 0, size_type n = npos) const; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000260
Howard Hinnant3e276872011-06-03 18:40:47 +0000261 void swap(basic_string& str)
Marshall Clow8982dcd2015-07-13 20:04:56 +0000262 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200263 allocator_traits<allocator_type>::is_always_equal::value); // C++17, constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000264
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200265 const value_type* c_str() const noexcept; // constexpr since C++20
266 const value_type* data() const noexcept; // constexpr since C++20
267 value_type* data() noexcept; // C++17, constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000268
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200269 allocator_type get_allocator() const noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000270
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200271 size_type find(const basic_string& str, size_type pos = 0) const noexcept; // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000272 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200273 size_type find(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension, constexpr since C++20
274 size_type find(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20
275 size_type find(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20
276 size_type find(value_type c, size_type pos = 0) const noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000277
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200278 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept; // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000279 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200280 size_type rfind(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension, constexpr since C++20
281 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20
282 size_type rfind(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20
283 size_type rfind(value_type c, size_type pos = npos) const noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000284
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200285 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept; // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000286 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200287 size_type find_first_of(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension, constexpr since C++20
288 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20
289 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20
290 size_type find_first_of(value_type c, size_type pos = 0) const noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000291
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200292 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept; // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000293 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200294 size_type find_last_of(const T& t, size_type pos = npos) const noexcept noexcept; // C++17, noexcept as an extension, constexpr since C++20
295 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20
296 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20
297 size_type find_last_of(value_type c, size_type pos = npos) const noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000298
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200299 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept; // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000300 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200301 size_type find_first_not_of(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension, constexpr since C++20
302 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20
303 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20
304 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000305
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200306 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept; // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000307 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200308 size_type find_last_not_of(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension, constexpr since C++20
309 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20
310 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20
311 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000312
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200313 int compare(const basic_string& str) const noexcept; // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000314 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200315 int compare(const T& t) const noexcept; // C++17, noexcept as an extension, constexpr since C++20
316 int compare(size_type pos1, size_type n1, const basic_string& str) const; // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000317 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200318 int compare(size_type pos1, size_type n1, const T& t) const; // C++17, constexpr since C++20
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000319 int compare(size_type pos1, size_type n1, const basic_string& str,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200320 size_type pos2, size_type n2=npos) const; // C++14, constexpr since C++20
Marshall Clow82513342016-09-24 22:45:42 +0000321 template <class T>
322 int compare(size_type pos1, size_type n1, const T& t,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200323 size_type pos2, size_type n2=npos) const; // C++17, constexpr since C++20
324 int compare(const value_type* s) const noexcept; // constexpr since C++20
325 int compare(size_type pos1, size_type n1, const value_type* s) const; // constexpr since C++20
326 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000327
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200328 constexpr bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++20
329 constexpr bool starts_with(charT c) const noexcept; // C++20
330 constexpr bool starts_with(const charT* s) const; // C++20
331 constexpr bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++20
332 constexpr bool ends_with(charT c) const noexcept; // C++20
333 constexpr bool ends_with(const charT* s) const; // C++20
Marshall Clow18c293b2017-12-04 20:11:38 +0000334
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200335 constexpr bool contains(basic_string_view<charT, traits> sv) const noexcept; // C++2b
336 constexpr bool contains(charT c) const noexcept; // C++2b
337 constexpr bool contains(const charT* s) const; // C++2b
Howard Hinnantc51e1022010-05-11 19:42:16 +0000338};
339
Marshall Clowa0563332018-02-08 06:34:03 +0000340template<class InputIterator,
341 class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
342basic_string(InputIterator, InputIterator, Allocator = Allocator())
343 -> basic_string<typename iterator_traits<InputIterator>::value_type,
344 char_traits<typename iterator_traits<InputIterator>::value_type>,
345 Allocator>; // C++17
346
Howard Hinnantc51e1022010-05-11 19:42:16 +0000347template<class charT, class traits, class Allocator>
348basic_string<charT, traits, Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000349operator+(const basic_string<charT, traits, Allocator>& lhs,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200350 const basic_string<charT, traits, Allocator>& rhs); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000351
352template<class charT, class traits, class Allocator>
353basic_string<charT, traits, Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200354operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000355
356template<class charT, class traits, class Allocator>
357basic_string<charT, traits, Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200358operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000359
360template<class charT, class traits, class Allocator>
361basic_string<charT, traits, Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200362operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000363
364template<class charT, class traits, class Allocator>
365basic_string<charT, traits, Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200366operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000367
368template<class charT, class traits, class Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000369bool operator==(const basic_string<charT, traits, Allocator>& lhs,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200370 const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000371
372template<class charT, class traits, class Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200373bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000374
375template<class charT, class traits, class Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200376bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000377
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000378template<class charT, class traits, class Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000379bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200380 const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000381
382template<class charT, class traits, class Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200383bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000384
385template<class charT, class traits, class Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200386bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000387
388template<class charT, class traits, class Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000389bool operator< (const basic_string<charT, traits, Allocator>& lhs,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200390 const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000391
392template<class charT, class traits, class Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200393bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000394
395template<class charT, class traits, class Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200396bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000397
398template<class charT, class traits, class Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000399bool operator> (const basic_string<charT, traits, Allocator>& lhs,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200400 const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000401
402template<class charT, class traits, class Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200403bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000404
405template<class charT, class traits, class Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200406bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000407
408template<class charT, class traits, class Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000409bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200410 const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000411
412template<class charT, class traits, class Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200413bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000414
415template<class charT, class traits, class Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200416bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000417
418template<class charT, class traits, class Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000419bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200420 const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000421
422template<class charT, class traits, class Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200423bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000424
425template<class charT, class traits, class Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200426bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000427
428template<class charT, class traits, class Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000429void swap(basic_string<charT, traits, Allocator>& lhs,
Howard Hinnant3e276872011-06-03 18:40:47 +0000430 basic_string<charT, traits, Allocator>& rhs)
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200431 noexcept(noexcept(lhs.swap(rhs))); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000432
433template<class charT, class traits, class Allocator>
434basic_istream<charT, traits>&
435operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
436
437template<class charT, class traits, class Allocator>
438basic_ostream<charT, traits>&
439operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
440
441template<class charT, class traits, class Allocator>
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000442basic_istream<charT, traits>&
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000443getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
444 charT delim);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000445
446template<class charT, class traits, class Allocator>
447basic_istream<charT, traits>&
448getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
449
Marshall Clow29b53f22018-12-14 18:49:35 +0000450template<class charT, class traits, class Allocator, class U>
Marek Kurdeja98b1412020-05-02 13:58:03 +0200451typename basic_string<charT, traits, Allocator>::size_type
452erase(basic_string<charT, traits, Allocator>& c, const U& value); // C++20
Marshall Clow29b53f22018-12-14 18:49:35 +0000453template<class charT, class traits, class Allocator, class Predicate>
Marek Kurdeja98b1412020-05-02 13:58:03 +0200454typename basic_string<charT, traits, Allocator>::size_type
455erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); // C++20
Marshall Clow29b53f22018-12-14 18:49:35 +0000456
Howard Hinnantc51e1022010-05-11 19:42:16 +0000457typedef basic_string<char> string;
458typedef basic_string<wchar_t> wstring;
Marek Kurdeje3ac4e22021-03-23 17:15:07 +0100459typedef basic_string<char8_t> u8string; // C++20
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000460typedef basic_string<char16_t> u16string;
461typedef basic_string<char32_t> u32string;
462
Bruce Mitchener170d8972020-11-24 12:53:53 -0500463int stoi (const string& str, size_t* idx = nullptr, int base = 10);
464long stol (const string& str, size_t* idx = nullptr, int base = 10);
465unsigned long stoul (const string& str, size_t* idx = nullptr, int base = 10);
466long long stoll (const string& str, size_t* idx = nullptr, int base = 10);
467unsigned long long stoull(const string& str, size_t* idx = nullptr, int base = 10);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000468
Bruce Mitchener170d8972020-11-24 12:53:53 -0500469float stof (const string& str, size_t* idx = nullptr);
470double stod (const string& str, size_t* idx = nullptr);
471long double stold(const string& str, size_t* idx = nullptr);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000472
473string to_string(int val);
474string to_string(unsigned val);
475string to_string(long val);
476string to_string(unsigned long val);
477string to_string(long long val);
478string to_string(unsigned long long val);
479string to_string(float val);
480string to_string(double val);
481string to_string(long double val);
482
Bruce Mitchener170d8972020-11-24 12:53:53 -0500483int stoi (const wstring& str, size_t* idx = nullptr, int base = 10);
484long stol (const wstring& str, size_t* idx = nullptr, int base = 10);
485unsigned long stoul (const wstring& str, size_t* idx = nullptr, int base = 10);
486long long stoll (const wstring& str, size_t* idx = nullptr, int base = 10);
487unsigned long long stoull(const wstring& str, size_t* idx = nullptr, int base = 10);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000488
Bruce Mitchener170d8972020-11-24 12:53:53 -0500489float stof (const wstring& str, size_t* idx = nullptr);
490double stod (const wstring& str, size_t* idx = nullptr);
491long double stold(const wstring& str, size_t* idx = nullptr);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000492
493wstring to_wstring(int val);
494wstring to_wstring(unsigned val);
495wstring to_wstring(long val);
496wstring to_wstring(unsigned long val);
497wstring to_wstring(long long val);
498wstring to_wstring(unsigned long long val);
499wstring to_wstring(float val);
500wstring to_wstring(double val);
501wstring to_wstring(long double val);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000502
503template <> struct hash<string>;
Marek Kurdeje3ac4e22021-03-23 17:15:07 +0100504template <> struct hash<u8string>; // C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000505template <> struct hash<u16string>;
506template <> struct hash<u32string>;
507template <> struct hash<wstring>;
508
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200509basic_string<char> operator "" s( const char *str, size_t len ); // C++14, constexpr since C++20
510basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14, constexpr since C++20
511constexpr basic_string<char8_t> operator "" s( const char8_t *str, size_t len ); // C++20
512basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14, constexpr since C++20
513basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14, constexpr since C++20
Marshall Clowcba751f2013-07-23 17:05:24 +0000514
Howard Hinnantc51e1022010-05-11 19:42:16 +0000515} // std
516
517*/
518
Nikolas Klauserf210d8a2022-02-15 18:18:08 +0100519#include <__algorithm/max.h>
520#include <__algorithm/min.h>
521#include <__algorithm/remove.h>
522#include <__algorithm/remove_if.h>
Louis Dionneb4fce352022-03-25 12:55:36 -0400523#include <__assert> // all public C++ headers provide the assertion handler
Howard Hinnantc51e1022010-05-11 19:42:16 +0000524#include <__config>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400525#include <__debug>
Mark de Weverdf3e0d42021-09-26 15:47:42 +0200526#include <__format/enable_insertable.h>
Nikolas Klauser80840272022-02-04 13:04:33 +0100527#include <__ios/fpos.h>
Louis Dionne77249522021-06-11 09:55:11 -0400528#include <__iterator/wrap_iter.h>
Nikolas Klauserc513eba2022-04-09 09:41:19 +0200529#include <__memory/allocate_at_least.h>
Nikolas Klauser8fccd622022-03-05 19:17:07 +0100530#include <__utility/auto_cast.h>
531#include <__utility/move.h>
532#include <__utility/swap.h>
Nikolas Klauser62060be2022-04-20 10:52:04 +0200533#include <__utility/unreachable.h>
534#include <climits>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400535#include <compare>
536#include <cstdio> // EOF
Louis Dionned24191c2021-08-19 12:39:16 -0400537#include <cstdlib>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400538#include <cstring>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400539#include <initializer_list>
540#include <iosfwd>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000541#include <iterator>
Nikolas Klauser62060be2022-04-20 10:52:04 +0200542#include <limits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000543#include <memory>
544#include <stdexcept>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400545#include <string_view>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000546#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000547#include <version>
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000548
Nikolas Klauser4c1bf592022-02-11 19:15:18 +0100549// TODO: remove these headers
550#include <__functional/binary_function.h>
551#include <__functional/invoke.h>
552#include <__functional/operations.h>
553#include <__functional/reference_wrapper.h>
554#include <__functional/unary_function.h>
555#include <__functional/weak_result_type.h>
556#include <new>
557#include <typeinfo>
558
Louis Dionne89258142021-08-23 15:32:36 -0400559#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Nikolas Klauser80840272022-02-04 13:04:33 +0100560# include <cwchar>
Louis Dionne89258142021-08-23 15:32:36 -0400561#endif
562
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400563#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
Nikolas Klauser80840272022-02-04 13:04:33 +0100564# include <cstdint>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400565#endif
Eric Fiselier14b6de92014-08-10 23:53:08 +0000566
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000567#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Arthur O'Dwyer6eeaa002022-02-01 20:16:40 -0500568# pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000569#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000570
Eric Fiselierf4433a32017-05-31 22:07:49 +0000571_LIBCPP_PUSH_MACROS
572#include <__undef_macros>
573
574
Howard Hinnantc51e1022010-05-11 19:42:16 +0000575_LIBCPP_BEGIN_NAMESPACE_STD
576
Howard Hinnantc51e1022010-05-11 19:42:16 +0000577// basic_string
578
579template<class _CharT, class _Traits, class _Allocator>
580basic_string<_CharT, _Traits, _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200581_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant944510a2011-06-14 19:58:17 +0000582operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
583 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000584
585template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200586_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000587basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant944510a2011-06-14 19:58:17 +0000588operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000589
590template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200591_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000592basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant944510a2011-06-14 19:58:17 +0000593operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000594
595template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200596inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000597basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant944510a2011-06-14 19:58:17 +0000598operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000599
600template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200601_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000602basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant944510a2011-06-14 19:58:17 +0000603operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000604
Shoaib Meenaiea363712017-07-29 02:54:41 +0000605_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
606
Marshall Clow039b2f02016-01-13 21:54:34 +0000607template <class _Iter>
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -0400608struct __string_is_trivial_iterator : public false_type {};
609
610template <class _Tp>
611struct __string_is_trivial_iterator<_Tp*>
612 : public is_arithmetic<_Tp> {};
Marshall Clow039b2f02016-01-13 21:54:34 +0000613
Louis Dionne173f29e2019-05-29 16:01:36 +0000614template <class _Iter>
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -0400615struct __string_is_trivial_iterator<__wrap_iter<_Iter> >
616 : public __string_is_trivial_iterator<_Iter> {};
Marshall Clow039b2f02016-01-13 21:54:34 +0000617
Marshall Clow82513342016-09-24 22:45:42 +0000618template <class _CharT, class _Traits, class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -0500619struct __can_be_converted_to_string_view : public _BoolConstant<
620 is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
621 !is_convertible<const _Tp&, const _CharT*>::value
622 > {};
Marshall Clow82513342016-09-24 22:45:42 +0000623
Arthur O'Dwyerafa5d5f2021-04-18 21:47:08 -0400624#ifndef _LIBCPP_HAS_NO_CHAR8_T
Richard Smith256954d2020-11-11 17:12:18 -0800625typedef basic_string<char8_t> u8string;
626#endif
627
628#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
629typedef basic_string<char16_t> u16string;
630typedef basic_string<char32_t> u32string;
Louis Dionne96fc5f52021-09-09 11:25:10 -0400631#endif
Richard Smith256954d2020-11-11 17:12:18 -0800632
Nikolas Klauser55dc8082022-04-09 16:19:45 +0200633struct __uninitialized_size_tag {};
634
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000635template<class _CharT, class _Traits, class _Allocator>
Richard Smith256954d2020-11-11 17:12:18 -0800636class
637 _LIBCPP_TEMPLATE_VIS
Arthur O'Dwyerafa5d5f2021-04-18 21:47:08 -0400638#ifndef _LIBCPP_HAS_NO_CHAR8_T
Richard Smith256954d2020-11-11 17:12:18 -0800639 _LIBCPP_PREFERRED_NAME(u8string)
640#endif
641#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
642 _LIBCPP_PREFERRED_NAME(u16string)
643 _LIBCPP_PREFERRED_NAME(u32string)
644#endif
645 basic_string
Howard Hinnantc51e1022010-05-11 19:42:16 +0000646{
647public:
648 typedef basic_string __self;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000649 typedef basic_string_view<_CharT, _Traits> __self_view;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000650 typedef _Traits traits_type;
Marshall Clowa3a74e02017-03-15 18:41:11 +0000651 typedef _CharT value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000652 typedef _Allocator allocator_type;
Howard Hinnantea8f7e12010-11-17 17:55:08 +0000653 typedef allocator_traits<allocator_type> __alloc_traits;
654 typedef typename __alloc_traits::size_type size_type;
655 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant3e276872011-06-03 18:40:47 +0000656 typedef value_type& reference;
657 typedef const value_type& const_reference;
Howard Hinnantea8f7e12010-11-17 17:55:08 +0000658 typedef typename __alloc_traits::pointer pointer;
659 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000660
Marshall Clow79f33542018-03-21 00:36:05 +0000661 static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array");
662 static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout");
663 static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial");
664 static_assert(( is_same<_CharT, typename traits_type::char_type>::value),
Howard Hinnant8ea98242013-08-23 17:37:05 +0000665 "traits_type::char_type must be the same type as CharT");
Marshall Clow79f33542018-03-21 00:36:05 +0000666 static_assert(( is_same<typename allocator_type::value_type, value_type>::value),
Howard Hinnant8ea98242013-08-23 17:37:05 +0000667 "Allocator::value_type must be same type as value_type");
Marshall Clowe46031a2018-07-02 18:41:15 +0000668
Howard Hinnantc51e1022010-05-11 19:42:16 +0000669 typedef __wrap_iter<pointer> iterator;
670 typedef __wrap_iter<const_pointer> const_iterator;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200671 typedef std::reverse_iterator<iterator> reverse_iterator;
672 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000673
674private:
Howard Hinnant68bf1812013-04-30 21:44:48 +0000675
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +0000676#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant68bf1812013-04-30 21:44:48 +0000677
678 struct __long
679 {
680 pointer __data_;
681 size_type __size_;
Nikolas Klauser62060be2022-04-20 10:52:04 +0200682 size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1;
683 size_type __is_long_ : 1;
Howard Hinnant68bf1812013-04-30 21:44:48 +0000684 };
685
Howard Hinnant68bf1812013-04-30 21:44:48 +0000686 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
687 (sizeof(__long) - 1)/sizeof(value_type) : 2};
688
689 struct __short
690 {
691 value_type __data_[__min_cap];
Azat Khuzhin1995f722022-04-08 16:13:46 -0400692 unsigned char __padding[sizeof(value_type) - 1];
Nikolas Klauser62060be2022-04-20 10:52:04 +0200693 unsigned char __size_ : 7;
694 unsigned char __is_long_ : 1;
Howard Hinnant68bf1812013-04-30 21:44:48 +0000695 };
696
Nikolas Klauser62060be2022-04-20 10:52:04 +0200697// The __endian_factor is required because the field we use to store the size
698// (either size_type or unsigned char depending on long/short) has one fewer
699// bit than it would if it were not a bitfield.
700//
701// If the LSB is used to store the short-flag in the short string representation,
702// we have to multiply the size by two when it is stored and divide it by two when
703// it is loaded to make sure that we always store an even number. In the long string
704// representation, we can ignore this because we can assume that we always allocate
705// an even amount of value_types.
706//
707// If the MSB is used for the short-flag, the max_size() is numeric_limits<size_type>::max() / 2.
708// This does not impact the short string representation, since we never need the MSB
709// for representing the size of a short string anyway.
710
711#ifdef _LIBCPP_BIG_ENDIAN
712 static const size_type __endian_factor = 2;
Howard Hinnant68bf1812013-04-30 21:44:48 +0000713#else
Nikolas Klauser62060be2022-04-20 10:52:04 +0200714 static const size_type __endian_factor = 1;
715#endif
716
717#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
718
719#ifdef _LIBCPP_BIG_ENDIAN
720 static const size_type __endian_factor = 1;
721#else
722 static const size_type __endian_factor = 2;
723#endif
Howard Hinnant68bf1812013-04-30 21:44:48 +0000724
Howard Hinnantc51e1022010-05-11 19:42:16 +0000725 struct __long
726 {
Nikolas Klauser62060be2022-04-20 10:52:04 +0200727 size_type __is_long_ : 1;
728 size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000729 size_type __size_;
730 pointer __data_;
731 };
732
Howard Hinnantc51e1022010-05-11 19:42:16 +0000733 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
734 (sizeof(__long) - 1)/sizeof(value_type) : 2};
735
736 struct __short
737 {
738 union
739 {
Nikolas Klauser62060be2022-04-20 10:52:04 +0200740 struct {
741 unsigned char __is_long_ : 1;
742 unsigned char __size_ : 7;
743 };
Howard Hinnant49e145e2012-10-30 19:06:59 +0000744 value_type __lx;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000745 };
746 value_type __data_[__min_cap];
747 };
748
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400749#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant68bf1812013-04-30 21:44:48 +0000750
Howard Hinnant8ea98242013-08-23 17:37:05 +0000751 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000752
Howard Hinnant8ea98242013-08-23 17:37:05 +0000753 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000754
755 struct __raw
756 {
757 size_type __words[__n_words];
758 };
759
760 struct __rep
761 {
762 union
763 {
764 __long __l;
765 __short __s;
766 __raw __r;
767 };
768 };
769
770 __compressed_pair<__rep, allocator_type> __r_;
771
Nikolas Klauser55dc8082022-04-09 16:19:45 +0200772 // Construct a string with the given allocator and enough storage to hold `__size` characters, but
773 // don't initialize the characters. The contents of the string, including the null terminator, must be
774 // initialized separately.
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200775 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
776 explicit basic_string(__uninitialized_size_tag, size_type __size, const allocator_type& __a)
Nikolas Klauser55dc8082022-04-09 16:19:45 +0200777 : __r_(__default_init_tag(), __a) {
778 if (__size > max_size())
779 __throw_length_error();
780 if (__fits_in_sso(__size)) {
781 __zero();
782 __set_short_size(__size);
783 } else {
784 auto __capacity = __recommend(__size) + 1;
785 auto __allocation = __alloc_traits::allocate(__alloc(), __capacity);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200786 __begin_lifetime(__allocation, __capacity);
Nikolas Klauser55dc8082022-04-09 16:19:45 +0200787 __set_long_cap(__capacity);
788 __set_long_pointer(__allocation);
789 __set_long_size(__size);
790 }
791 std::__debug_db_insert_c(this);
792 }
793
Howard Hinnantc51e1022010-05-11 19:42:16 +0000794public:
Martin Storsjö88890c22021-02-22 01:13:13 +0200795 _LIBCPP_TEMPLATE_DATA_VIS
Howard Hinnantc51e1022010-05-11 19:42:16 +0000796 static const size_type npos = -1;
797
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200798 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string()
Howard Hinnant3e276872011-06-03 18:40:47 +0000799 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clowa80abc72015-06-03 19:56:43 +0000800
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200801 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit basic_string(const allocator_type& __a)
Marshall Clowa80abc72015-06-03 19:56:43 +0000802#if _LIBCPP_STD_VER <= 14
803 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
804#else
805 _NOEXCEPT;
806#endif
807
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200808 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(const basic_string& __str);
809 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(const basic_string& __str, const allocator_type& __a);
Marshall Clowa80abc72015-06-03 19:56:43 +0000810
Eric Fiselierfc92be82017-04-19 00:28:44 +0000811#ifndef _LIBCPP_CXX03_LANG
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200812 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant3e276872011-06-03 18:40:47 +0000813 basic_string(basic_string&& __str)
Marshall Clowa80abc72015-06-03 19:56:43 +0000814#if _LIBCPP_STD_VER <= 14
Howard Hinnant3e276872011-06-03 18:40:47 +0000815 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clowa80abc72015-06-03 19:56:43 +0000816#else
817 _NOEXCEPT;
818#endif
819
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200820 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000821 basic_string(basic_string&& __str, const allocator_type& __a);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400822#endif // _LIBCPP_CXX03_LANG
Marshall Clowe46031a2018-07-02 18:41:15 +0000823
Louis Dionne9ce598d2021-09-08 09:14:43 -0400824 template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> >
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200825 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier5169d1c2019-12-16 19:03:23 -0500826 basic_string(const _CharT* __s) : __r_(__default_init_tag(), __default_init_tag()) {
Eric Fiseliera8567862018-07-17 05:48:48 +0000827 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
828 __init(__s, traits_type::length(__s));
Nikolas Klauserf2807732022-01-11 00:33:35 +0100829 _VSTD::__debug_db_insert_c(this);
Eric Fiseliera8567862018-07-17 05:48:48 +0000830 }
Marshall Clowe46031a2018-07-02 18:41:15 +0000831
Louis Dionne9ce598d2021-09-08 09:14:43 -0400832 template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> >
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200833 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowe46031a2018-07-02 18:41:15 +0000834 basic_string(const _CharT* __s, const _Allocator& __a);
835
Marek Kurdej90d79712021-07-27 16:16:21 +0200836#if _LIBCPP_STD_VER > 20
837 basic_string(nullptr_t) = delete;
838#endif
839
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200840 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier812882b2017-02-17 01:17:10 +0000841 basic_string(const _CharT* __s, size_type __n);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200842 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier812882b2017-02-17 01:17:10 +0000843 basic_string(const _CharT* __s, size_type __n, const _Allocator& __a);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200844 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier812882b2017-02-17 01:17:10 +0000845 basic_string(size_type __n, _CharT __c);
Marshall Clowe46031a2018-07-02 18:41:15 +0000846
Louis Dionne9ce598d2021-09-08 09:14:43 -0400847 template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> >
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200848 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowe46031a2018-07-02 18:41:15 +0000849 basic_string(size_type __n, _CharT __c, const _Allocator& __a);
850
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200851 _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clow83445802016-04-07 18:13:41 +0000852 basic_string(const basic_string& __str, size_type __pos, size_type __n,
Eric Fiselier812882b2017-02-17 01:17:10 +0000853 const _Allocator& __a = _Allocator());
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200854 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clow83445802016-04-07 18:13:41 +0000855 basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier812882b2017-02-17 01:17:10 +0000856 const _Allocator& __a = _Allocator());
Marshall Clowe46031a2018-07-02 18:41:15 +0000857
Louis Dionne9ce598d2021-09-08 09:14:43 -0400858 template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200859 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier812882b2017-02-17 01:17:10 +0000860 basic_string(const _Tp& __t, size_type __pos, size_type __n,
Eric Fiselierc522ceb2020-01-15 16:57:08 -0500861 const allocator_type& __a = allocator_type());
Marshall Clowe46031a2018-07-02 18:41:15 +0000862
Louis Dionne9ce598d2021-09-08 09:14:43 -0400863 template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
Eric Fiselierc522ceb2020-01-15 16:57:08 -0500864 !__is_same_uncvref<_Tp, basic_string>::value> >
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200865 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowe46031a2018-07-02 18:41:15 +0000866 explicit basic_string(const _Tp& __t);
867
Louis Dionne9ce598d2021-09-08 09:14:43 -0400868 template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> >
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200869 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowe46031a2018-07-02 18:41:15 +0000870 explicit basic_string(const _Tp& __t, const allocator_type& __a);
871
Louis Dionne9ce598d2021-09-08 09:14:43 -0400872 template<class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> >
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200873 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000874 basic_string(_InputIterator __first, _InputIterator __last);
Louis Dionne9ce598d2021-09-08 09:14:43 -0400875 template<class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> >
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200876 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000877 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Eric Fiselierfc92be82017-04-19 00:28:44 +0000878#ifndef _LIBCPP_CXX03_LANG
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200879 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier812882b2017-02-17 01:17:10 +0000880 basic_string(initializer_list<_CharT> __il);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200881 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier812882b2017-02-17 01:17:10 +0000882 basic_string(initializer_list<_CharT> __il, const _Allocator& __a);
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400883#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000884
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200885 inline _LIBCPP_CONSTEXPR_AFTER_CXX17 ~basic_string();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000886
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200887 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000888 operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
889
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200890 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator=(const basic_string& __str);
Eric Fiselier5ec13b12017-01-23 21:24:58 +0000891
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200892 template <class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
893 !__is_same_uncvref<_Tp, basic_string>::value> >
894 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator=(const _Tp& __t) {
895 __self_view __sv = __t;
896 return assign(__sv);
897 }
Marshall Clowe46031a2018-07-02 18:41:15 +0000898
Eric Fiselierfc92be82017-04-19 00:28:44 +0000899#ifndef _LIBCPP_CXX03_LANG
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200900 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant3e276872011-06-03 18:40:47 +0000901 basic_string& operator=(basic_string&& __str)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +0000902 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200903 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselierfc92be82017-04-19 00:28:44 +0000904 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000905#endif
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200906 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
907 basic_string& operator=(const value_type* __s) {return assign(__s);}
Marek Kurdej90d79712021-07-27 16:16:21 +0200908#if _LIBCPP_STD_VER > 20
909 basic_string& operator=(nullptr_t) = delete;
910#endif
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200911 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator=(value_type __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000912
Louis Dionneba400782020-10-02 15:02:52 -0400913#if _LIBCPP_DEBUG_LEVEL == 2
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200914 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant8ea98242013-08-23 17:37:05 +0000915 iterator begin() _NOEXCEPT
916 {return iterator(this, __get_pointer());}
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200917 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant8ea98242013-08-23 17:37:05 +0000918 const_iterator begin() const _NOEXCEPT
919 {return const_iterator(this, __get_pointer());}
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200920 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant8ea98242013-08-23 17:37:05 +0000921 iterator end() _NOEXCEPT
922 {return iterator(this, __get_pointer() + size());}
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200923 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant8ea98242013-08-23 17:37:05 +0000924 const_iterator end() const _NOEXCEPT
925 {return const_iterator(this, __get_pointer() + size());}
926#else
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200927 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000928 iterator begin() _NOEXCEPT
929 {return iterator(__get_pointer());}
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200930 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000931 const_iterator begin() const _NOEXCEPT
Howard Hinnantd17880b2013-06-28 16:59:19 +0000932 {return const_iterator(__get_pointer());}
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200933 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000934 iterator end() _NOEXCEPT
935 {return iterator(__get_pointer() + size());}
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200936 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000937 const_iterator end() const _NOEXCEPT
Howard Hinnantd17880b2013-06-28 16:59:19 +0000938 {return const_iterator(__get_pointer() + size());}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400939#endif // _LIBCPP_DEBUG_LEVEL == 2
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200940 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000941 reverse_iterator rbegin() _NOEXCEPT
942 {return reverse_iterator(end());}
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200943 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000944 const_reverse_iterator rbegin() const _NOEXCEPT
945 {return const_reverse_iterator(end());}
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200946 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000947 reverse_iterator rend() _NOEXCEPT
948 {return reverse_iterator(begin());}
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200949 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000950 const_reverse_iterator rend() const _NOEXCEPT
951 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000952
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200953 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000954 const_iterator cbegin() const _NOEXCEPT
955 {return begin();}
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200956 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000957 const_iterator cend() const _NOEXCEPT
958 {return end();}
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200959 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000960 const_reverse_iterator crbegin() const _NOEXCEPT
961 {return rbegin();}
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200962 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +0000963 const_reverse_iterator crend() const _NOEXCEPT
964 {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000965
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200966 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type size() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +0000967 {return __is_long() ? __get_long_size() : __get_short_size();}
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200968 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type length() const _NOEXCEPT {return size();}
969 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type max_size() const _NOEXCEPT;
970 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type capacity() const _NOEXCEPT {
971 return (__is_long() ? __get_long_cap() : static_cast<size_type>(__min_cap)) - 1;
972 }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000973
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200974 _LIBCPP_CONSTEXPR_AFTER_CXX17 void resize(size_type __n, value_type __c);
975 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void resize(size_type __n) { resize(__n, value_type()); }
Howard Hinnantc51e1022010-05-11 19:42:16 +0000976
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200977 _LIBCPP_CONSTEXPR_AFTER_CXX17 void reserve(size_type __requested_capacity);
Nikolas Klauser9e6040c2022-01-06 21:43:26 +0100978
979#if _LIBCPP_STD_VER > 20
980 template <class _Op>
981 _LIBCPP_HIDE_FROM_ABI constexpr
982 void resize_and_overwrite(size_type __n, _Op __op) {
983 __resize_default_init(__n);
Nikolas Klausera4a76a12022-01-20 13:53:59 +0100984 __erase_to_end(_VSTD::move(__op)(data(), _LIBCPP_AUTO_CAST(__n)));
Nikolas Klauser9e6040c2022-01-06 21:43:26 +0100985 }
986#endif
987
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200988 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void __resize_default_init(size_type __n);
Eric Fiselier451d5582018-11-26 20:15:38 +0000989
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200990 _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_INLINE_VISIBILITY void reserve() _NOEXCEPT { shrink_to_fit(); }
991 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void shrink_to_fit() _NOEXCEPT;
992 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void clear() _NOEXCEPT;
993
994 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowb7db4972017-11-15 20:02:27 +0000995 bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000996
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200997 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
998 const_reference operator[](size_type __pos) const _NOEXCEPT;
999 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 reference operator[](size_type __pos) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001000
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001001 _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference at(size_type __n) const;
1002 _LIBCPP_CONSTEXPR_AFTER_CXX17 reference at(size_type __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001003
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001004 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator+=(const basic_string& __str) {
1005 return append(__str);
1006 }
Marshall Clowe46031a2018-07-02 18:41:15 +00001007
1008 template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001009 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001010 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001011 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001012 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1013 && !__is_same_uncvref<_Tp, basic_string >::value,
Marshall Clowe46031a2018-07-02 18:41:15 +00001014 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001015 >
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001016 operator+=(const _Tp& __t) {
1017 __self_view __sv = __t; return append(__sv);
1018 }
1019
1020 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator+=(const value_type* __s) {
1021 return append(__s);
1022 }
1023
1024 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator+=(value_type __c) {
1025 push_back(__c);
1026 return *this;
1027 }
1028
Eric Fiselierfc92be82017-04-19 00:28:44 +00001029#ifndef _LIBCPP_CXX03_LANG
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001030 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1031 basic_string& operator+=(initializer_list<value_type> __il) { return append(__il); }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001032#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001033
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001034 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001035 basic_string& append(const basic_string& __str);
Marshall Clowe46031a2018-07-02 18:41:15 +00001036
1037 template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001038 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001039 __enable_if_t<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001040 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1041 && !__is_same_uncvref<_Tp, basic_string>::value,
Marshall Clowe46031a2018-07-02 18:41:15 +00001042 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001043 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001044 append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); }
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001045 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clowe46031a2018-07-02 18:41:15 +00001046
Marshall Clow62953962016-10-03 23:40:48 +00001047 template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001048 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001049 __enable_if_t
Marshall Clow82513342016-09-24 22:45:42 +00001050 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001051 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1052 && !__is_same_uncvref<_Tp, basic_string>::value,
Marshall Clow82513342016-09-24 22:45:42 +00001053 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001054 >
Marshall Clow82513342016-09-24 22:45:42 +00001055 append(const _Tp& __t, size_type __pos, size_type __n=npos);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001056 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& append(const value_type* __s, size_type __n);
1057 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& append(const value_type* __s);
1058 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& append(size_type __n, value_type __c);
Eric Fiselier451d5582018-11-26 20:15:38 +00001059
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001060 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier451d5582018-11-26 20:15:38 +00001061 void __append_default_init(size_type __n);
1062
Howard Hinnantc51e1022010-05-11 19:42:16 +00001063 template<class _InputIterator>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001064 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Louis Dionne9ce598d2021-09-08 09:14:43 -04001065 __enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00001066 <
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04001067 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001068 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001069 >
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001070 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +00001071 append(_InputIterator __first, _InputIterator __last) {
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04001072 const basic_string __temp(__first, __last, __alloc());
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +00001073 append(__temp.data(), __temp.size());
1074 return *this;
1075 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001076 template<class _ForwardIterator>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001077 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Louis Dionne9ce598d2021-09-08 09:14:43 -04001078 __enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00001079 <
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04001080 __is_cpp17_forward_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001081 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001082 >
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001083 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04001084 append(_ForwardIterator __first, _ForwardIterator __last);
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +00001085
Eric Fiselierfc92be82017-04-19 00:28:44 +00001086#ifndef _LIBCPP_CXX03_LANG
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001087 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001088 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001089#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001090
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001091 _LIBCPP_CONSTEXPR_AFTER_CXX17 void push_back(value_type __c);
1092 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void pop_back();
1093 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 reference front() _NOEXCEPT;
1094 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference front() const _NOEXCEPT;
1095 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 reference back() _NOEXCEPT;
1096 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference back() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001097
Marshall Clowe46031a2018-07-02 18:41:15 +00001098 template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001099 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001100 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001101 <
1102 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1103 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001104 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001105 assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); }
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001106 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clow95d5e9a2016-03-09 18:08:29 +00001107 basic_string& assign(const basic_string& __str) { return *this = __str; }
Eric Fiselierfc92be82017-04-19 00:28:44 +00001108#ifndef _LIBCPP_CXX03_LANG
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001109 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001110 basic_string& assign(basic_string&& __str)
Marshall Clow5aa9e942015-10-05 16:17:34 +00001111 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001112 {*this = _VSTD::move(__str); return *this;}
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001113#endif
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001114 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow62953962016-10-03 23:40:48 +00001115 template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001116 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001117 __enable_if_t
Marshall Clow82513342016-09-24 22:45:42 +00001118 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001119 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1120 && !__is_same_uncvref<_Tp, basic_string>::value,
Marshall Clow82513342016-09-24 22:45:42 +00001121 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001122 >
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001123 assign(const _Tp & __t, size_type __pos, size_type __n=npos);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001124 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& assign(const value_type* __s, size_type __n);
1125 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& assign(const value_type* __s);
1126 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& assign(size_type __n, value_type __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001127 template<class _InputIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001128 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001129 __enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00001130 <
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04001131 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001132 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001133 >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001134 assign(_InputIterator __first, _InputIterator __last);
1135 template<class _ForwardIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001136 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001137 __enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00001138 <
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04001139 __is_cpp17_forward_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001140 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001141 >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001142 assign(_ForwardIterator __first, _ForwardIterator __last);
Eric Fiselierfc92be82017-04-19 00:28:44 +00001143#ifndef _LIBCPP_CXX03_LANG
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001144 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001145 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001146#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001147
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001148 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001149 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clowe46031a2018-07-02 18:41:15 +00001150
1151 template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001152 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001153 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001154 <
1155 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1156 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001157 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001158 insert(size_type __pos1, const _Tp& __t)
1159 { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); }
1160
Marshall Clow82513342016-09-24 22:45:42 +00001161 template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001162 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001163 __enable_if_t
Marshall Clow82513342016-09-24 22:45:42 +00001164 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001165 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
Marshall Clow82513342016-09-24 22:45:42 +00001166 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001167 >
Marshall Clow82513342016-09-24 22:45:42 +00001168 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001169 _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clow8db7fb02014-03-04 19:17:19 +00001170 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001171 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1172 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& insert(size_type __pos, const value_type* __s);
1173 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1174 _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator insert(const_iterator __pos, value_type __c);
1175 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001176 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1177 template<class _InputIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001178 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001179 __enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00001180 <
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04001181 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001182 iterator
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001183 >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001184 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1185 template<class _ForwardIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001186 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001187 __enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00001188 <
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04001189 __is_cpp17_forward_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001190 iterator
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001191 >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001192 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Eric Fiselierfc92be82017-04-19 00:28:44 +00001193#ifndef _LIBCPP_CXX03_LANG
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001194 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001195 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1196 {return insert(__pos, __il.begin(), __il.end());}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001197#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001198
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001199 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& erase(size_type __pos = 0, size_type __n = npos);
1200 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001201 iterator erase(const_iterator __pos);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001202 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001203 iterator erase(const_iterator __first, const_iterator __last);
1204
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001205 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001206 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clowe46031a2018-07-02 18:41:15 +00001207
1208 template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001209 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001210 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001211 <
1212 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1213 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001214 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001215 replace(size_type __pos1, size_type __n1, const _Tp& __t) { __self_view __sv = __t; return replace(__pos1, __n1, __sv.data(), __sv.size()); }
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001216 _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clow8db7fb02014-03-04 19:17:19 +00001217 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
Marshall Clow82513342016-09-24 22:45:42 +00001218 template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001219 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001220 __enable_if_t
Marshall Clow82513342016-09-24 22:45:42 +00001221 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001222 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
Marshall Clow82513342016-09-24 22:45:42 +00001223 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001224 >
Marshall Clow82513342016-09-24 22:45:42 +00001225 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001226 _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantd17880b2013-06-28 16:59:19 +00001227 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001228 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
1229 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
1230 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant990d6e82010-11-17 21:11:40 +00001231 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Marshall Clowe46031a2018-07-02 18:41:15 +00001232
1233 template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001234 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001235 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001236 <
1237 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1238 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001239 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001240 replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); }
1241
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001242 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantd17880b2013-06-28 16:59:19 +00001243 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001244 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantd17880b2013-06-28 16:59:19 +00001245 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001246 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant990d6e82010-11-17 21:11:40 +00001247 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001248 template<class _InputIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001249 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001250 __enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00001251 <
Eric Fiseliercd5a6772019-11-18 01:46:58 -05001252 __is_cpp17_input_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001253 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001254 >
Howard Hinnant990d6e82010-11-17 21:11:40 +00001255 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Eric Fiselierfc92be82017-04-19 00:28:44 +00001256#ifndef _LIBCPP_CXX03_LANG
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001257 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant990d6e82010-11-17 21:11:40 +00001258 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001259 {return replace(__i1, __i2, __il.begin(), __il.end());}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001260#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001261
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001262 _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
1263 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001264 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1265
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001266 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant3e276872011-06-03 18:40:47 +00001267 void swap(basic_string& __str)
Marshall Clow8982dcd2015-07-13 20:04:56 +00001268#if _LIBCPP_STD_VER >= 14
Eric Fiselier873b8d32019-03-18 21:50:12 +00001269 _NOEXCEPT;
Marshall Clow8982dcd2015-07-13 20:04:56 +00001270#else
Eric Fiselier873b8d32019-03-18 21:50:12 +00001271 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow8982dcd2015-07-13 20:04:56 +00001272 __is_nothrow_swappable<allocator_type>::value);
1273#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001274
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001275 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantd17880b2013-06-28 16:59:19 +00001276 const value_type* c_str() const _NOEXCEPT {return data();}
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001277 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001278 const value_type* data() const _NOEXCEPT {return _VSTD::__to_address(__get_pointer());}
Eric Fiselier4ee2a892017-11-20 20:23:27 +00001279#if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY)
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001280 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001281 value_type* data() _NOEXCEPT {return _VSTD::__to_address(__get_pointer());}
Marshall Clowd3c22392016-03-08 15:44:30 +00001282#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001283
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001284 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001285 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001286
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001287 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001288 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001289
1290 template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001291 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001292 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001293 <
1294 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1295 size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001296 >
zoecarver1997e0a2021-02-05 11:54:47 -08001297 find(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001298 _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantd17880b2013-06-28 16:59:19 +00001299 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001300 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantd17880b2013-06-28 16:59:19 +00001301 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001302 _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001303
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001304 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001305 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001306
1307 template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001308 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001309 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001310 <
1311 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1312 size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001313 >
zoecarver1997e0a2021-02-05 11:54:47 -08001314 rfind(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001315 _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantd17880b2013-06-28 16:59:19 +00001316 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001317 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantd17880b2013-06-28 16:59:19 +00001318 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001319 _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001320
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001321 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001322 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001323
1324 template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001325 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001326 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001327 <
1328 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1329 size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001330 >
zoecarver1997e0a2021-02-05 11:54:47 -08001331 find_first_of(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001332 _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantd17880b2013-06-28 16:59:19 +00001333 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001334 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantd17880b2013-06-28 16:59:19 +00001335 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001336 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001337 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001338
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001339 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001340 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001341
1342 template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001343 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001344 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001345 <
1346 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1347 size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001348 >
zoecarver1997e0a2021-02-05 11:54:47 -08001349 find_last_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001350 _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantd17880b2013-06-28 16:59:19 +00001351 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001352 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantd17880b2013-06-28 16:59:19 +00001353 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001354 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001355 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001356
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001357 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001358 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001359
1360 template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001361 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001362 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001363 <
1364 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1365 size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001366 >
zoecarver1997e0a2021-02-05 11:54:47 -08001367 find_first_not_of(const _Tp &__t, size_type __pos = 0) const _NOEXCEPT;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001368 _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantd17880b2013-06-28 16:59:19 +00001369 size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001370 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantd17880b2013-06-28 16:59:19 +00001371 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001372 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001373 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1374
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001375 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001376 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001377
1378 template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001379 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001380 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001381 <
1382 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1383 size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001384 >
zoecarver1997e0a2021-02-05 11:54:47 -08001385 find_last_not_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001386 _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantd17880b2013-06-28 16:59:19 +00001387 size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001388 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantd17880b2013-06-28 16:59:19 +00001389 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001390 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001391 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1392
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001393 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001394 int compare(const basic_string& __str) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001395
1396 template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001397 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001398 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001399 <
1400 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1401 int
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001402 >
zoecarver1997e0a2021-02-05 11:54:47 -08001403 compare(const _Tp &__t) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001404
1405 template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001406 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001407 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001408 <
1409 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1410 int
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001411 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001412 compare(size_type __pos1, size_type __n1, const _Tp& __t) const;
1413
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001414 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001415 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001416 _LIBCPP_CONSTEXPR_AFTER_CXX17
1417 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2,
1418 size_type __n2 = npos) const;
Marshall Clowe46031a2018-07-02 18:41:15 +00001419
Marshall Clow82513342016-09-24 22:45:42 +00001420 template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001421 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001422 __enable_if_t
Marshall Clow82513342016-09-24 22:45:42 +00001423 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001424 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
Marshall Clow82513342016-09-24 22:45:42 +00001425 int
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001426 >
Marshall Clow82513342016-09-24 22:45:42 +00001427 compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001428 _LIBCPP_CONSTEXPR_AFTER_CXX17 int compare(const value_type* __s) const _NOEXCEPT;
1429 _LIBCPP_CONSTEXPR_AFTER_CXX17 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1430 _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantd17880b2013-06-28 16:59:19 +00001431 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001432
Marshall Clow18c293b2017-12-04 20:11:38 +00001433#if _LIBCPP_STD_VER > 17
Arthur O'Dwyera0cb1e82021-09-28 12:19:35 -04001434 constexpr _LIBCPP_INLINE_VISIBILITY
1435 bool starts_with(__self_view __sv) const noexcept
Marshall Clow18c293b2017-12-04 20:11:38 +00001436 { return __self_view(data(), size()).starts_with(__sv); }
1437
Arthur O'Dwyera0cb1e82021-09-28 12:19:35 -04001438 constexpr _LIBCPP_INLINE_VISIBILITY
1439 bool starts_with(value_type __c) const noexcept
Marshall Clow18c293b2017-12-04 20:11:38 +00001440 { return !empty() && _Traits::eq(front(), __c); }
1441
Arthur O'Dwyera0cb1e82021-09-28 12:19:35 -04001442 constexpr _LIBCPP_INLINE_VISIBILITY
1443 bool starts_with(const value_type* __s) const noexcept
Marshall Clow18c293b2017-12-04 20:11:38 +00001444 { return starts_with(__self_view(__s)); }
1445
Arthur O'Dwyera0cb1e82021-09-28 12:19:35 -04001446 constexpr _LIBCPP_INLINE_VISIBILITY
1447 bool ends_with(__self_view __sv) const noexcept
Marshall Clow18c293b2017-12-04 20:11:38 +00001448 { return __self_view(data(), size()).ends_with( __sv); }
1449
Arthur O'Dwyera0cb1e82021-09-28 12:19:35 -04001450 constexpr _LIBCPP_INLINE_VISIBILITY
1451 bool ends_with(value_type __c) const noexcept
Marshall Clow18c293b2017-12-04 20:11:38 +00001452 { return !empty() && _Traits::eq(back(), __c); }
1453
Arthur O'Dwyera0cb1e82021-09-28 12:19:35 -04001454 constexpr _LIBCPP_INLINE_VISIBILITY
1455 bool ends_with(const value_type* __s) const noexcept
Marshall Clow18c293b2017-12-04 20:11:38 +00001456 { return ends_with(__self_view(__s)); }
1457#endif
1458
Wim Leflere023c3542021-01-19 14:33:30 -05001459#if _LIBCPP_STD_VER > 20
1460 constexpr _LIBCPP_INLINE_VISIBILITY
1461 bool contains(__self_view __sv) const noexcept
1462 { return __self_view(data(), size()).contains(__sv); }
1463
1464 constexpr _LIBCPP_INLINE_VISIBILITY
1465 bool contains(value_type __c) const noexcept
1466 { return __self_view(data(), size()).contains(__c); }
1467
1468 constexpr _LIBCPP_INLINE_VISIBILITY
1469 bool contains(const value_type* __s) const
1470 { return __self_view(data(), size()).contains(__s); }
1471#endif
1472
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001473 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool __invariants() const;
Howard Hinnantaaeb1132013-04-22 23:55:13 +00001474
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001475 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void __clear_and_shrink() _NOEXCEPT;
Howard Hinnantaaeb1132013-04-22 23:55:13 +00001476
Louis Dionneba400782020-10-02 15:02:52 -04001477#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant8ea98242013-08-23 17:37:05 +00001478
1479 bool __dereferenceable(const const_iterator* __i) const;
1480 bool __decrementable(const const_iterator* __i) const;
1481 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1482 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1483
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001484#endif // _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant8ea98242013-08-23 17:37:05 +00001485
Howard Hinnantc51e1022010-05-11 19:42:16 +00001486private:
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001487 template<class _Alloc>
1488 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1489 bool friend operator==(const basic_string<char, char_traits<char>, _Alloc>& __lhs,
1490 const basic_string<char, char_traits<char>, _Alloc>& __rhs) _NOEXCEPT;
1491
1492 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void __shrink_or_extend(size_type __target_capacity);
1493
1494 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1495 bool __is_long() const _NOEXCEPT {
1496 if (__libcpp_is_constant_evaluated())
1497 return true;
1498 return __r_.first().__s.__is_long_;
1499 }
1500
1501 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __begin_lifetime(pointer __begin, size_type __n) {
1502#if _LIBCPP_STD_VER > 17
1503 if (__libcpp_is_constant_evaluated()) {
1504 for (size_type __i = 0; __i != __n; ++__i)
1505 std::construct_at(std::addressof(__begin[__i]));
1506 }
1507#else
1508 (void)__begin;
1509 (void)__n;
1510#endif // _LIBCPP_STD_VER > 17
1511 }
1512
1513 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __default_init() {
1514 __zero();
1515 if (__libcpp_is_constant_evaluated()) {
1516 size_type __sz = __recommend(0) + 1;
1517 pointer __ptr = __alloc_traits::allocate(__alloc(), __sz);
1518 __begin_lifetime(__ptr, __sz);
1519 __set_long_pointer(__ptr);
1520 __set_long_cap(__sz);
1521 __set_long_size(0);
1522 }
1523 }
1524
1525 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __deallocate_constexpr() {
1526 if (__libcpp_is_constant_evaluated() && __get_pointer() != nullptr)
1527 __alloc_traits::deallocate(__alloc(), __get_pointer(), __get_long_cap());
1528 }
1529
Nikolas Klauser93826d12022-01-04 17:24:03 +01001530 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI static bool __fits_in_sso(size_type __sz) {
1531 // SSO is disabled during constant evaluation because `__is_long` isn't constexpr friendly
1532 return !__libcpp_is_constant_evaluated() && (__sz < __min_cap);
1533 }
1534
Nikolas Klauser48d680d2022-02-26 13:28:33 +01001535 template <class _ForwardIterator>
1536 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
1537 iterator __insert_from_safe_copy(size_type __n, size_type __ip, _ForwardIterator __first, _ForwardIterator __last) {
1538 size_type __sz = size();
1539 size_type __cap = capacity();
1540 value_type* __p;
1541 if (__cap - __sz >= __n)
1542 {
1543 __p = std::__to_address(__get_pointer());
1544 size_type __n_move = __sz - __ip;
1545 if (__n_move != 0)
1546 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
1547 }
1548 else
1549 {
1550 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
1551 __p = std::__to_address(__get_long_pointer());
1552 }
1553 __sz += __n;
1554 __set_size(__sz);
1555 traits_type::assign(__p[__sz], value_type());
1556 for (__p += __ip; __first != __last; ++__p, ++__first)
1557 traits_type::assign(*__p, *__first);
1558
1559 return begin() + __ip;
1560 }
1561
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001562 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 allocator_type& __alloc() _NOEXCEPT { return __r_.second(); }
1563 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const allocator_type& __alloc() const _NOEXCEPT { return __r_.second(); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001564
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001565 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Nikolas Klauser62060be2022-04-20 10:52:04 +02001566 void __set_short_size(size_type __s) _NOEXCEPT {
1567 _LIBCPP_ASSERT(__s < __min_cap, "__s should never be greater than or equal to the short string capacity");
1568 __r_.first().__s.__size_ = __s;
1569 __r_.first().__s.__is_long_ = false;
1570 }
Howard Hinnant68bf1812013-04-30 21:44:48 +00001571
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001572 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Nikolas Klauser62060be2022-04-20 10:52:04 +02001573 size_type __get_short_size() const _NOEXCEPT {
1574 _LIBCPP_ASSERT(!__r_.first().__s.__is_long_, "String has to be short when trying to get the short size");
1575 return __r_.first().__s.__size_;
1576 }
Howard Hinnant68bf1812013-04-30 21:44:48 +00001577
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001578 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001579 void __set_long_size(size_type __s) _NOEXCEPT
1580 {__r_.first().__l.__size_ = __s;}
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001581 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001582 size_type __get_long_size() const _NOEXCEPT
1583 {return __r_.first().__l.__size_;}
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001584 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001585 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001586 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1587
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001588 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Nikolas Klauser62060be2022-04-20 10:52:04 +02001589 void __set_long_cap(size_type __s) _NOEXCEPT {
1590 __r_.first().__l.__cap_ = __s / __endian_factor;
1591 __r_.first().__l.__is_long_ = true;
1592 }
1593
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001594 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Nikolas Klauser62060be2022-04-20 10:52:04 +02001595 size_type __get_long_cap() const _NOEXCEPT {
1596 return __r_.first().__l.__cap_ * __endian_factor;
1597 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001598
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001599 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001600 void __set_long_pointer(pointer __p) _NOEXCEPT
1601 {__r_.first().__l.__data_ = __p;}
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001602 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001603 pointer __get_long_pointer() _NOEXCEPT
1604 {return __r_.first().__l.__data_;}
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001605 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001606 const_pointer __get_long_pointer() const _NOEXCEPT
1607 {return __r_.first().__l.__data_;}
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001608 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001609 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnantd17880b2013-06-28 16:59:19 +00001610 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001611 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001612 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnantd17880b2013-06-28 16:59:19 +00001613 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001614 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001615 pointer __get_pointer() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001616 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001617 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001618 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001619 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1620
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001621 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1622 void __zero() _NOEXCEPT {
1623 __r_.first() = __rep();
1624 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001625
1626 template <size_type __a> static
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001627 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantea382952013-08-14 18:00:20 +00001628 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiselier8599fcc2015-08-28 07:02:42 +00001629 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001630 enum {__alignment = 16};
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001631 static _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001632 size_type __recommend(size_type __s) _NOEXCEPT
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001633 {
1634 if (__s < __min_cap) {
1635 if (__libcpp_is_constant_evaluated())
1636 return static_cast<size_type>(__min_cap);
1637 else
1638 return static_cast<size_type>(__min_cap) - 1;
1639 }
Marshall Clow80584522018-02-07 21:30:17 +00001640 size_type __guess = __align_it<sizeof(value_type) < __alignment ?
1641 __alignment/sizeof(value_type) : 1 > (__s+1) - 1;
1642 if (__guess == __min_cap) ++__guess;
1643 return __guess;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001644 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001645
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001646 inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantd17880b2013-06-28 16:59:19 +00001647 void __init(const value_type* __s, size_type __sz, size_type __reserve);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001648 inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantd17880b2013-06-28 16:59:19 +00001649 void __init(const value_type* __s, size_type __sz);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001650 inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001651 void __init(size_type __n, value_type __c);
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001652
Martijn Vels5e7c9752020-03-04 17:52:46 -05001653 // Slow path for the (inlined) copy constructor for 'long' strings.
1654 // Always externally instantiated and not inlined.
1655 // Requires that __s is zero terminated.
1656 // The main reason for this function to exist is because for unstable, we
1657 // want to allow inlining of the copy constructor. However, we don't want
1658 // to call the __init() functions as those are marked as inline which may
1659 // result in over-aggressive inlining by the compiler, where our aim is
1660 // to only inline the fast path code directly in the ctor.
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001661 _LIBCPP_CONSTEXPR_AFTER_CXX17 void __init_copy_ctor_external(const value_type* __s, size_type __sz);
Martijn Vels5e7c9752020-03-04 17:52:46 -05001662
Howard Hinnantc51e1022010-05-11 19:42:16 +00001663 template <class _InputIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001664 inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001665 __enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00001666 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001667 __is_exactly_cpp17_input_iterator<_InputIterator>::value
1668 >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001669 __init(_InputIterator __first, _InputIterator __last);
1670
1671 template <class _ForwardIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001672 inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04001673 __enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00001674 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001675 __is_cpp17_forward_iterator<_ForwardIterator>::value
1676 >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001677 __init(_ForwardIterator __first, _ForwardIterator __last);
1678
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001679 _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001680 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001681 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001682 _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001683 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1684 size_type __n_copy, size_type __n_del,
Howard Hinnantd17880b2013-06-28 16:59:19 +00001685 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001686
Martijn Vels596e3de2020-02-26 15:55:49 -05001687 // __assign_no_alias is invoked for assignment operations where we
1688 // have proof that the input does not alias the current instance.
1689 // For example, operator=(basic_string) performs a 'self' check.
1690 template <bool __is_short>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001691 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& __assign_no_alias(const value_type* __s, size_type __n);
Martijn Vels596e3de2020-02-26 15:55:49 -05001692
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001693 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001694 void __erase_to_end(size_type __pos);
1695
Martijn Velsa81fc792020-02-26 13:25:43 -05001696 // __erase_external_with_move is invoked for erase() invocations where
1697 // `n ~= npos`, likely requiring memory moves on the string data.
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001698 _LIBCPP_CONSTEXPR_AFTER_CXX17 void __erase_external_with_move(size_type __pos, size_type __n);
Martijn Velsa81fc792020-02-26 13:25:43 -05001699
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001700 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001701 void __copy_assign_alloc(const basic_string& __str)
1702 {__copy_assign_alloc(__str, integral_constant<bool,
1703 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1704
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001705 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001706 void __copy_assign_alloc(const basic_string& __str, true_type)
1707 {
Marshall Clowf258c202017-01-31 03:40:52 +00001708 if (__alloc() == __str.__alloc())
1709 __alloc() = __str.__alloc();
1710 else
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001711 {
Marshall Clowf258c202017-01-31 03:40:52 +00001712 if (!__str.__is_long())
1713 {
Vedant Kumar55e007e2018-03-08 21:15:26 +00001714 __clear_and_shrink();
Marshall Clowf258c202017-01-31 03:40:52 +00001715 __alloc() = __str.__alloc();
1716 }
1717 else
1718 {
1719 allocator_type __a = __str.__alloc();
Nikolas Klauserc513eba2022-04-09 09:41:19 +02001720 auto __allocation = std::__allocate_at_least(__a, __str.__get_long_cap());
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001721 __begin_lifetime(__allocation.ptr, __allocation.count);
Vedant Kumar55e007e2018-03-08 21:15:26 +00001722 __clear_and_shrink();
Marshall Clowf258c202017-01-31 03:40:52 +00001723 __alloc() = _VSTD::move(__a);
Nikolas Klauserc513eba2022-04-09 09:41:19 +02001724 __set_long_pointer(__allocation.ptr);
1725 __set_long_cap(__allocation.count);
Marshall Clowf258c202017-01-31 03:40:52 +00001726 __set_long_size(__str.size());
1727 }
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001728 }
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001729 }
1730
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001731 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant28b24882011-12-01 20:21:04 +00001732 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001733 {}
1734
Eric Fiselierfc92be82017-04-19 00:28:44 +00001735#ifndef _LIBCPP_CXX03_LANG
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001736 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00001737 void __move_assign(basic_string& __str, false_type)
1738 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001739 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant3e276872011-06-03 18:40:47 +00001740 void __move_assign(basic_string& __str, true_type)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00001741#if _LIBCPP_STD_VER > 14
1742 _NOEXCEPT;
1743#else
Howard Hinnant3e276872011-06-03 18:40:47 +00001744 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001745#endif
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00001746#endif
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001747
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001748 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant58fe91b2011-08-17 20:36:18 +00001749 void
Howard Hinnantc2734962011-09-02 20:42:31 +00001750 __move_assign_alloc(basic_string& __str)
Howard Hinnant58fe91b2011-08-17 20:36:18 +00001751 _NOEXCEPT_(
1752 !__alloc_traits::propagate_on_container_move_assignment::value ||
1753 is_nothrow_move_assignable<allocator_type>::value)
1754 {__move_assign_alloc(__str, integral_constant<bool,
1755 __alloc_traits::propagate_on_container_move_assignment::value>());}
1756
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001757 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc2734962011-09-02 20:42:31 +00001758 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant58fe91b2011-08-17 20:36:18 +00001759 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1760 {
1761 __alloc() = _VSTD::move(__c.__alloc());
1762 }
1763
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001764 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant28b24882011-12-01 20:21:04 +00001765 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant58fe91b2011-08-17 20:36:18 +00001766 _NOEXCEPT
1767 {}
1768
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001769 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& __assign_external(const value_type* __s);
1770 _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& __assign_external(const value_type* __s, size_type __n);
Martijn Velsda7d94f2020-06-19 14:24:03 -04001771
1772 // Assigns the value in __s, guaranteed to be __n < __min_cap in length.
1773 inline basic_string& __assign_short(const value_type* __s, size_type __n) {
1774 pointer __p = __is_long()
1775 ? (__set_long_size(__n), __get_long_pointer())
1776 : (__set_short_size(__n), __get_short_pointer());
1777 traits_type::move(_VSTD::__to_address(__p), __s, __n);
1778 traits_type::assign(__p[__n], value_type());
1779 return *this;
1780 }
1781
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001782 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
1783 basic_string& __null_terminate_at(value_type* __p, size_type __newsz) {
Nikolas Klauser3ec7fb22021-12-14 01:20:53 +01001784 __set_size(__newsz);
1785 __invalidate_iterators_past(__newsz);
1786 traits_type::assign(__p[__newsz], value_type());
1787 return *this;
1788 }
1789
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001790 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void __invalidate_all_iterators();
1791 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void __invalidate_iterators_past(size_type);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001792
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04001793 template<class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001794 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04001795 bool __addr_in_range(_Tp&& __t) const {
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001796 // assume that the ranges overlap, because we can't check during constant evaluation
1797 if (__libcpp_is_constant_evaluated())
1798 return true;
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04001799 const volatile void *__p = _VSTD::addressof(__t);
1800 return data() <= __p && __p <= data() + size();
1801 }
1802
Louis Dionned24191c2021-08-19 12:39:16 -04001803 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
1804 void __throw_length_error() const {
Nikolas Klauserf89bb932022-01-24 19:44:34 +01001805 _VSTD::__throw_length_error("basic_string");
Louis Dionned24191c2021-08-19 12:39:16 -04001806 }
1807
1808 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
1809 void __throw_out_of_range() const {
Nikolas Klauserf89bb932022-01-24 19:44:34 +01001810 _VSTD::__throw_out_of_range("basic_string");
Louis Dionned24191c2021-08-19 12:39:16 -04001811 }
1812
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001813 friend _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string operator+<>(const basic_string&, const basic_string&);
1814 friend _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string operator+<>(const value_type*, const basic_string&);
1815 friend _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string operator+<>(value_type, const basic_string&);
1816 friend _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string operator+<>(const basic_string&, const value_type*);
1817 friend _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string operator+<>(const basic_string&, value_type);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001818};
1819
Eric Fiselier2ed640b2020-03-04 13:54:04 -05001820// These declarations must appear before any functions are implicitly used
1821// so that they have the correct visibility specifier.
1822#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
Louis Dionne89258142021-08-23 15:32:36 -04001823 _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
1824# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1825 _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
1826# endif
Eric Fiselier2ed640b2020-03-04 13:54:04 -05001827#else
Louis Dionne89258142021-08-23 15:32:36 -04001828 _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char)
1829# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1830 _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t)
1831# endif
Eric Fiselier2ed640b2020-03-04 13:54:04 -05001832#endif
1833
1834
Louis Dionned59f8a52021-08-17 11:59:07 -04001835#if _LIBCPP_STD_VER >= 17
Marshall Clowa0563332018-02-08 06:34:03 +00001836template<class _InputIterator,
Arthur O'Dwyer56226762021-03-03 23:02:20 -05001837 class _CharT = __iter_value_type<_InputIterator>,
Marshall Clowa0563332018-02-08 06:34:03 +00001838 class _Allocator = allocator<_CharT>,
Louis Dionne25547162021-08-17 12:26:09 -04001839 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1840 class = enable_if_t<__is_allocator<_Allocator>::value>
Marshall Clowa0563332018-02-08 06:34:03 +00001841 >
1842basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
1843 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
Marshall Clowe46031a2018-07-02 18:41:15 +00001844
1845template<class _CharT,
1846 class _Traits,
1847 class _Allocator = allocator<_CharT>,
Louis Dionne25547162021-08-17 12:26:09 -04001848 class = enable_if_t<__is_allocator<_Allocator>::value>
Marshall Clowe46031a2018-07-02 18:41:15 +00001849 >
1850explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
1851 -> basic_string<_CharT, _Traits, _Allocator>;
1852
1853template<class _CharT,
1854 class _Traits,
1855 class _Allocator = allocator<_CharT>,
Louis Dionne25547162021-08-17 12:26:09 -04001856 class = enable_if_t<__is_allocator<_Allocator>::value>,
Marshall Clowe46031a2018-07-02 18:41:15 +00001857 class _Sz = typename allocator_traits<_Allocator>::size_type
1858 >
1859basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator())
1860 -> basic_string<_CharT, _Traits, _Allocator>;
Marshall Clowa0563332018-02-08 06:34:03 +00001861#endif
1862
Howard Hinnantc51e1022010-05-11 19:42:16 +00001863template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001864inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001865void
1866basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1867{
Louis Dionneba400782020-10-02 15:02:52 -04001868#if _LIBCPP_DEBUG_LEVEL == 2
Nikolas Klauser1a7d9f02021-12-16 14:55:03 +01001869 if (!__libcpp_is_constant_evaluated())
1870 __get_db()->__invalidate_all(this);
Louis Dionneba400782020-10-02 15:02:52 -04001871#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001872}
1873
1874template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001875inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001876void
Arthur O'Dwyerb3db4542021-04-27 09:10:04 -04001877basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001878{
Louis Dionneba400782020-10-02 15:02:52 -04001879#if _LIBCPP_DEBUG_LEVEL == 2
Nikolas Klauser1a7d9f02021-12-16 14:55:03 +01001880 if (!__libcpp_is_constant_evaluated()) {
1881 __c_node* __c = __get_db()->__find_c_and_lock(this);
1882 if (__c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001883 {
Nikolas Klauser1a7d9f02021-12-16 14:55:03 +01001884 const_pointer __new_last = __get_pointer() + __pos;
1885 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantc51e1022010-05-11 19:42:16 +00001886 {
Nikolas Klauser1a7d9f02021-12-16 14:55:03 +01001887 --__p;
1888 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1889 if (__i->base() > __new_last)
1890 {
1891 (*__p)->__c_ = nullptr;
1892 if (--__c->end_ != __p)
1893 _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1894 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001895 }
Nikolas Klauser1a7d9f02021-12-16 14:55:03 +01001896 __get_db()->unlock();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001897 }
1898 }
Arthur O'Dwyerb3db4542021-04-27 09:10:04 -04001899#else
1900 (void)__pos;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001901#endif // _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnantc51e1022010-05-11 19:42:16 +00001902}
1903
1904template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001905inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant3e276872011-06-03 18:40:47 +00001906basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowe546cbb2015-06-04 02:05:41 +00001907 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001908 : __r_(__default_init_tag(), __default_init_tag())
Howard Hinnantc51e1022010-05-11 19:42:16 +00001909{
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001910 std::__debug_db_insert_c(this);
1911 __default_init();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001912}
1913
1914template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001915inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001916basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiseliere012bf22015-07-18 20:40:46 +00001917#if _LIBCPP_STD_VER <= 14
1918 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1919#else
1920 _NOEXCEPT
1921#endif
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001922: __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001923{
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001924 std::__debug_db_insert_c(this);
1925 __default_init();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001926}
1927
1928template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001929_LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier815ed732016-09-16 00:00:48 +00001930void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1931 size_type __sz,
1932 size_type __reserve)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001933{
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001934 if (__libcpp_is_constant_evaluated())
1935 __zero();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001936 if (__reserve > max_size())
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01001937 __throw_length_error();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001938 pointer __p;
Nikolas Klauser93826d12022-01-04 17:24:03 +01001939 if (__fits_in_sso(__reserve))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001940 {
1941 __set_short_size(__sz);
1942 __p = __get_short_pointer();
1943 }
1944 else
1945 {
Nikolas Klauserc513eba2022-04-09 09:41:19 +02001946 auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__reserve) + 1);
1947 __p = __allocation.ptr;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001948 __begin_lifetime(__p, __allocation.count);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001949 __set_long_pointer(__p);
Nikolas Klauserc513eba2022-04-09 09:41:19 +02001950 __set_long_cap(__allocation.count);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001951 __set_long_size(__sz);
1952 }
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001953 traits_type::copy(_VSTD::__to_address(__p), __s, __sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001954 traits_type::assign(__p[__sz], value_type());
1955}
1956
1957template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001958_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00001959void
Howard Hinnantd17880b2013-06-28 16:59:19 +00001960basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001961{
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001962 if (__libcpp_is_constant_evaluated())
1963 __zero();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001964 if (__sz > max_size())
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01001965 __throw_length_error();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001966 pointer __p;
Nikolas Klauser93826d12022-01-04 17:24:03 +01001967 if (__fits_in_sso(__sz))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001968 {
1969 __set_short_size(__sz);
1970 __p = __get_short_pointer();
1971 }
1972 else
1973 {
Nikolas Klauserc513eba2022-04-09 09:41:19 +02001974 auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1);
1975 __p = __allocation.ptr;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001976 __begin_lifetime(__p, __allocation.count);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001977 __set_long_pointer(__p);
Nikolas Klauserc513eba2022-04-09 09:41:19 +02001978 __set_long_cap(__allocation.count);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001979 __set_long_size(__sz);
1980 }
Eric Fiselierc1b87a72019-11-16 17:13:26 -05001981 traits_type::copy(_VSTD::__to_address(__p), __s, __sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001982 traits_type::assign(__p[__sz], value_type());
1983}
1984
1985template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00001986template <class>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001987_LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier812882b2017-02-17 01:17:10 +00001988basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001989 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001990{
Howard Hinnant8ea98242013-08-23 17:37:05 +00001991 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00001992 __init(__s, traits_type::length(__s));
Nikolas Klauserf2807732022-01-11 00:33:35 +01001993 _VSTD::__debug_db_insert_c(this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001994}
1995
1996template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001997inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier812882b2017-02-17 01:17:10 +00001998basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05001999 : __r_(__default_init_tag(), __default_init_tag())
Howard Hinnantc51e1022010-05-11 19:42:16 +00002000{
Nikolas Klauserf2807732022-01-11 00:33:35 +01002001 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
2002 __init(__s, __n);
2003 _VSTD::__debug_db_insert_c(this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002004}
2005
2006template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002007inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier812882b2017-02-17 01:17:10 +00002008basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002009 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002010{
Howard Hinnant8ea98242013-08-23 17:37:05 +00002011 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002012 __init(__s, __n);
Nikolas Klauserf2807732022-01-11 00:33:35 +01002013 _VSTD::__debug_db_insert_c(this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002014}
2015
2016template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002017_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002018basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002019 : __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002020{
2021 if (!__str.__is_long())
2022 __r_.first().__r = __str.__r_.first().__r;
2023 else
Martijn Vels5e7c9752020-03-04 17:52:46 -05002024 __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()),
2025 __str.__get_long_size());
Nikolas Klauserf2807732022-01-11 00:33:35 +01002026 _VSTD::__debug_db_insert_c(this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002027}
2028
2029template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002030_LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier812882b2017-02-17 01:17:10 +00002031basic_string<_CharT, _Traits, _Allocator>::basic_string(
2032 const basic_string& __str, const allocator_type& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002033 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002034{
2035 if (!__str.__is_long())
2036 __r_.first().__r = __str.__r_.first().__r;
2037 else
Martijn Vels5e7c9752020-03-04 17:52:46 -05002038 __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()),
2039 __str.__get_long_size());
Nikolas Klauserf2807732022-01-11 00:33:35 +01002040 _VSTD::__debug_db_insert_c(this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002041}
2042
Martijn Vels5e7c9752020-03-04 17:52:46 -05002043template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002044_LIBCPP_CONSTEXPR_AFTER_CXX17
Martijn Vels5e7c9752020-03-04 17:52:46 -05002045void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(
2046 const value_type* __s, size_type __sz) {
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002047 if (__libcpp_is_constant_evaluated())
2048 __zero();
Martijn Vels5e7c9752020-03-04 17:52:46 -05002049 pointer __p;
Nikolas Klauser93826d12022-01-04 17:24:03 +01002050 if (__fits_in_sso(__sz)) {
Martijn Vels5e7c9752020-03-04 17:52:46 -05002051 __p = __get_short_pointer();
2052 __set_short_size(__sz);
2053 } else {
2054 if (__sz > max_size())
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002055 __throw_length_error();
Nikolas Klauserc513eba2022-04-09 09:41:19 +02002056 auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1);
2057 __p = __allocation.ptr;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002058 __begin_lifetime(__p, __allocation.count);
Martijn Vels5e7c9752020-03-04 17:52:46 -05002059 __set_long_pointer(__p);
Nikolas Klauserc513eba2022-04-09 09:41:19 +02002060 __set_long_cap(__allocation.count);
Martijn Vels5e7c9752020-03-04 17:52:46 -05002061 __set_long_size(__sz);
2062 }
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002063 traits_type::copy(std::__to_address(__p), __s, __sz + 1);
Martijn Vels5e7c9752020-03-04 17:52:46 -05002064}
2065
Eric Fiselierfc92be82017-04-19 00:28:44 +00002066#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002067
2068template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002069inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant3e276872011-06-03 18:40:47 +00002070basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clowa80abc72015-06-03 19:56:43 +00002071#if _LIBCPP_STD_VER <= 14
Howard Hinnant3e276872011-06-03 18:40:47 +00002072 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clowa80abc72015-06-03 19:56:43 +00002073#else
2074 _NOEXCEPT
2075#endif
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002076 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002077{
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002078 __str.__default_init();
Nikolas Klauserf2807732022-01-11 00:33:35 +01002079 _VSTD::__debug_db_insert_c(this);
Louis Dionneba400782020-10-02 15:02:52 -04002080#if _LIBCPP_DEBUG_LEVEL == 2
Nikolas Klauserf2807732022-01-11 00:33:35 +01002081 if (!__libcpp_is_constant_evaluated() && __is_long())
2082 __get_db()->swap(this, &__str);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002083#endif
2084}
2085
2086template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002087inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002088basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002089 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002090{
Marshall Clowd2d24692014-07-17 15:32:20 +00002091 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002092 __init(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd2d24692014-07-17 15:32:20 +00002093 else
2094 {
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002095 if (__libcpp_is_constant_evaluated()) {
2096 __zero();
2097 __r_.first().__l = __str.__r_.first().__l;
2098 } else {
2099 __r_.first().__r = __str.__r_.first().__r;
2100 }
2101 __str.__default_init();
Marshall Clowd2d24692014-07-17 15:32:20 +00002102 }
Nikolas Klauserf2807732022-01-11 00:33:35 +01002103 _VSTD::__debug_db_insert_c(this);
Louis Dionneba400782020-10-02 15:02:52 -04002104#if _LIBCPP_DEBUG_LEVEL == 2
Nikolas Klauserf2807732022-01-11 00:33:35 +01002105 if (!__libcpp_is_constant_evaluated() && __is_long())
2106 __get_db()->swap(this, &__str);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002107#endif
2108}
2109
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002110#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002111
2112template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002113_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002114void
2115basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
2116{
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002117 if (__libcpp_is_constant_evaluated())
2118 __zero();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002119 if (__n > max_size())
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002120 __throw_length_error();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002121 pointer __p;
Nikolas Klauser93826d12022-01-04 17:24:03 +01002122 if (__fits_in_sso(__n))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002123 {
2124 __set_short_size(__n);
2125 __p = __get_short_pointer();
2126 }
2127 else
2128 {
Nikolas Klauserc513eba2022-04-09 09:41:19 +02002129 auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__n) + 1);
2130 __p = __allocation.ptr;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002131 __begin_lifetime(__p, __allocation.count);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002132 __set_long_pointer(__p);
Nikolas Klauserc513eba2022-04-09 09:41:19 +02002133 __set_long_cap(__allocation.count);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002134 __set_long_size(__n);
2135 }
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002136 traits_type::assign(_VSTD::__to_address(__p), __n, __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002137 traits_type::assign(__p[__n], value_type());
2138}
2139
2140template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002141inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier812882b2017-02-17 01:17:10 +00002142basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002143 : __r_(__default_init_tag(), __default_init_tag())
Howard Hinnantc51e1022010-05-11 19:42:16 +00002144{
2145 __init(__n, __c);
Nikolas Klauserf2807732022-01-11 00:33:35 +01002146 _VSTD::__debug_db_insert_c(this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002147}
2148
2149template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00002150template <class>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002151_LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier812882b2017-02-17 01:17:10 +00002152basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002153 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002154{
2155 __init(__n, __c);
Nikolas Klauserf2807732022-01-11 00:33:35 +01002156 _VSTD::__debug_db_insert_c(this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002157}
2158
Howard Hinnantc51e1022010-05-11 19:42:16 +00002159template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002160_LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier812882b2017-02-17 01:17:10 +00002161basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
2162 size_type __pos, size_type __n,
2163 const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002164 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002165{
2166 size_type __str_sz = __str.size();
2167 if (__pos > __str_sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002168 __throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002169 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Nikolas Klauserf2807732022-01-11 00:33:35 +01002170 _VSTD::__debug_db_insert_c(this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002171}
2172
2173template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002174inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clow83445802016-04-07 18:13:41 +00002175basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
Eric Fiselier812882b2017-02-17 01:17:10 +00002176 const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002177 : __r_(__default_init_tag(), __a)
Marshall Clow83445802016-04-07 18:13:41 +00002178{
2179 size_type __str_sz = __str.size();
2180 if (__pos > __str_sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002181 __throw_out_of_range();
Marshall Clow83445802016-04-07 18:13:41 +00002182 __init(__str.data() + __pos, __str_sz - __pos);
Nikolas Klauserf2807732022-01-11 00:33:35 +01002183 _VSTD::__debug_db_insert_c(this);
Marshall Clow83445802016-04-07 18:13:41 +00002184}
2185
2186template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00002187template <class _Tp, class>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002188_LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clow78dbe462016-11-14 18:22:19 +00002189basic_string<_CharT, _Traits, _Allocator>::basic_string(
Marshall Clowe46031a2018-07-02 18:41:15 +00002190 const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002191 : __r_(__default_init_tag(), __a)
Marshall Clow78dbe462016-11-14 18:22:19 +00002192{
Marshall Clowe46031a2018-07-02 18:41:15 +00002193 __self_view __sv0 = __t;
2194 __self_view __sv = __sv0.substr(__pos, __n);
Marshall Clow78dbe462016-11-14 18:22:19 +00002195 __init(__sv.data(), __sv.size());
Nikolas Klauserf2807732022-01-11 00:33:35 +01002196 _VSTD::__debug_db_insert_c(this);
Marshall Clow78dbe462016-11-14 18:22:19 +00002197}
2198
2199template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00002200template <class _Tp, class>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002201_LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowe46031a2018-07-02 18:41:15 +00002202basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002203 : __r_(__default_init_tag(), __default_init_tag())
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002204{
Marshall Clowe46031a2018-07-02 18:41:15 +00002205 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002206 __init(__sv.data(), __sv.size());
Nikolas Klauserf2807732022-01-11 00:33:35 +01002207 _VSTD::__debug_db_insert_c(this);
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002208}
2209
2210template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00002211template <class _Tp, class>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002212_LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowe46031a2018-07-02 18:41:15 +00002213basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002214 : __r_(__default_init_tag(), __a)
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002215{
Marshall Clowe46031a2018-07-02 18:41:15 +00002216 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002217 __init(__sv.data(), __sv.size());
Nikolas Klauserf2807732022-01-11 00:33:35 +01002218 _VSTD::__debug_db_insert_c(this);
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002219}
2220
2221template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002222template <class _InputIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002223_LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04002224__enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00002225<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002226 __is_exactly_cpp17_input_iterator<_InputIterator>::value
2227>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002228basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2229{
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002230 __default_init();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002231#ifndef _LIBCPP_NO_EXCEPTIONS
2232 try
2233 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002234#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002235 for (; __first != __last; ++__first)
2236 push_back(*__first);
2237#ifndef _LIBCPP_NO_EXCEPTIONS
2238 }
2239 catch (...)
2240 {
2241 if (__is_long())
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002242 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002243 throw;
2244 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002245#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002246}
2247
2248template <class _CharT, class _Traits, class _Allocator>
2249template <class _ForwardIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002250_LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04002251__enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00002252<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002253 __is_cpp17_forward_iterator<_ForwardIterator>::value
2254>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002255basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2256{
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002257 if (__libcpp_is_constant_evaluated())
2258 __zero();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002259 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002260 if (__sz > max_size())
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002261 __throw_length_error();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002262 pointer __p;
Nikolas Klauser93826d12022-01-04 17:24:03 +01002263 if (__fits_in_sso(__sz))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002264 {
2265 __set_short_size(__sz);
2266 __p = __get_short_pointer();
2267 }
2268 else
2269 {
Nikolas Klauserc513eba2022-04-09 09:41:19 +02002270 auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1);
2271 __p = __allocation.ptr;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002272 __begin_lifetime(__p, __allocation.count);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002273 __set_long_pointer(__p);
Nikolas Klauserc513eba2022-04-09 09:41:19 +02002274 __set_long_cap(__allocation.count);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002275 __set_long_size(__sz);
2276 }
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002277
2278#ifndef _LIBCPP_NO_EXCEPTIONS
2279 try
2280 {
2281#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiseliera09a3b42014-10-27 19:28:20 +00002282 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002283 traits_type::assign(*__p, *__first);
2284 traits_type::assign(*__p, value_type());
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002285#ifndef _LIBCPP_NO_EXCEPTIONS
2286 }
2287 catch (...)
2288 {
2289 if (__is_long())
2290 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
2291 throw;
2292 }
2293#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002294}
2295
2296template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierc0f566d2019-03-14 12:31:10 +00002297template<class _InputIterator, class>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002298inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002299basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002300 : __r_(__default_init_tag(), __default_init_tag())
Howard Hinnantc51e1022010-05-11 19:42:16 +00002301{
2302 __init(__first, __last);
Nikolas Klauserf2807732022-01-11 00:33:35 +01002303 _VSTD::__debug_db_insert_c(this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002304}
2305
2306template <class _CharT, class _Traits, class _Allocator>
Eric Fiselierc0f566d2019-03-14 12:31:10 +00002307template<class _InputIterator, class>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002308inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002309basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2310 const allocator_type& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002311 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002312{
2313 __init(__first, __last);
Nikolas Klauserf2807732022-01-11 00:33:35 +01002314 _VSTD::__debug_db_insert_c(this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002315}
2316
Eric Fiselierfc92be82017-04-19 00:28:44 +00002317#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant33711792011-08-12 21:56:02 +00002318
Howard Hinnantc51e1022010-05-11 19:42:16 +00002319template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002320inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier812882b2017-02-17 01:17:10 +00002321basic_string<_CharT, _Traits, _Allocator>::basic_string(
2322 initializer_list<_CharT> __il)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002323 : __r_(__default_init_tag(), __default_init_tag())
Howard Hinnantc51e1022010-05-11 19:42:16 +00002324{
2325 __init(__il.begin(), __il.end());
Nikolas Klauserf2807732022-01-11 00:33:35 +01002326 _VSTD::__debug_db_insert_c(this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002327}
2328
2329template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002330inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier812882b2017-02-17 01:17:10 +00002331basic_string<_CharT, _Traits, _Allocator>::basic_string(
2332 initializer_list<_CharT> __il, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002333 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002334{
2335 __init(__il.begin(), __il.end());
Nikolas Klauserf2807732022-01-11 00:33:35 +01002336 _VSTD::__debug_db_insert_c(this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002337}
2338
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002339#endif // _LIBCPP_CXX03_LANG
Howard Hinnant33711792011-08-12 21:56:02 +00002340
Howard Hinnantc51e1022010-05-11 19:42:16 +00002341template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002342_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002343basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2344{
Louis Dionneba400782020-10-02 15:02:52 -04002345#if _LIBCPP_DEBUG_LEVEL == 2
Nikolas Klauser1a7d9f02021-12-16 14:55:03 +01002346 if (!__libcpp_is_constant_evaluated())
2347 __get_db()->__erase_c(this);
Howard Hinnant8ea98242013-08-23 17:37:05 +00002348#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002349 if (__is_long())
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002350 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002351}
2352
2353template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002354_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002355void
2356basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2357 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnantd17880b2013-06-28 16:59:19 +00002358 size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002359{
2360 size_type __ms = max_size();
2361 if (__delta_cap > __ms - __old_cap - 1)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002362 __throw_length_error();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002363 pointer __old_p = __get_pointer();
2364 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002365 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantc51e1022010-05-11 19:42:16 +00002366 __ms - 1;
Nikolas Klauserc513eba2022-04-09 09:41:19 +02002367 auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1);
2368 pointer __p = __allocation.ptr;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002369 __begin_lifetime(__p, __allocation.count);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002370 __invalidate_all_iterators();
2371 if (__n_copy != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002372 traits_type::copy(_VSTD::__to_address(__p),
2373 _VSTD::__to_address(__old_p), __n_copy);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002374 if (__n_add != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002375 traits_type::copy(_VSTD::__to_address(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002376 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2377 if (__sec_cp_sz != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002378 traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add,
2379 _VSTD::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002380 if (__old_cap+1 != __min_cap || __libcpp_is_constant_evaluated())
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002381 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002382 __set_long_pointer(__p);
Nikolas Klauserc513eba2022-04-09 09:41:19 +02002383 __set_long_cap(__allocation.count);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002384 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2385 __set_long_size(__old_sz);
2386 traits_type::assign(__p[__old_sz], value_type());
2387}
2388
2389template <class _CharT, class _Traits, class _Allocator>
2390void
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002391_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002392basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2393 size_type __n_copy, size_type __n_del, size_type __n_add)
2394{
2395 size_type __ms = max_size();
Marshall Clow2267c5d2013-11-06 14:24:38 +00002396 if (__delta_cap > __ms - __old_cap)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002397 __throw_length_error();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002398 pointer __old_p = __get_pointer();
2399 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002400 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantc51e1022010-05-11 19:42:16 +00002401 __ms - 1;
Nikolas Klauserc513eba2022-04-09 09:41:19 +02002402 auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1);
2403 pointer __p = __allocation.ptr;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002404 __begin_lifetime(__p, __allocation.count);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002405 __invalidate_all_iterators();
2406 if (__n_copy != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002407 traits_type::copy(_VSTD::__to_address(__p),
2408 _VSTD::__to_address(__old_p), __n_copy);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002409 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2410 if (__sec_cp_sz != 0)
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002411 traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add,
2412 _VSTD::__to_address(__old_p) + __n_copy + __n_del,
Howard Hinnantd17880b2013-06-28 16:59:19 +00002413 __sec_cp_sz);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002414 if (__libcpp_is_constant_evaluated() || __old_cap + 1 != __min_cap)
2415 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap + 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002416 __set_long_pointer(__p);
Nikolas Klauserc513eba2022-04-09 09:41:19 +02002417 __set_long_cap(__allocation.count);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002418}
2419
2420// assign
2421
2422template <class _CharT, class _Traits, class _Allocator>
Martijn Vels596e3de2020-02-26 15:55:49 -05002423template <bool __is_short>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002424_LIBCPP_CONSTEXPR_AFTER_CXX17
Martijn Velsb6a08b62020-04-10 18:36:31 -04002425basic_string<_CharT, _Traits, _Allocator>&
2426basic_string<_CharT, _Traits, _Allocator>::__assign_no_alias(
Martijn Vels596e3de2020-02-26 15:55:49 -05002427 const value_type* __s, size_type __n) {
Louis Dionne6209e9f2022-03-03 13:39:12 -05002428 size_type __cap = __is_short ? static_cast<size_type>(__min_cap) : __get_long_cap();
Martijn Vels596e3de2020-02-26 15:55:49 -05002429 if (__n < __cap) {
2430 pointer __p = __is_short ? __get_short_pointer() : __get_long_pointer();
2431 __is_short ? __set_short_size(__n) : __set_long_size(__n);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002432 traits_type::copy(std::__to_address(__p), __s, __n);
Martijn Vels596e3de2020-02-26 15:55:49 -05002433 traits_type::assign(__p[__n], value_type());
2434 __invalidate_iterators_past(__n);
2435 } else {
2436 size_type __sz = __is_short ? __get_short_size() : __get_long_size();
2437 __grow_by_and_replace(__cap - 1, __n - __cap + 1, __sz, 0, __sz, __n, __s);
2438 }
Martijn Velsb6a08b62020-04-10 18:36:31 -04002439 return *this;
Martijn Vels596e3de2020-02-26 15:55:49 -05002440}
2441
2442template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002443_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002444basic_string<_CharT, _Traits, _Allocator>&
Martijn Velsda7d94f2020-06-19 14:24:03 -04002445basic_string<_CharT, _Traits, _Allocator>::__assign_external(
2446 const value_type* __s, size_type __n) {
2447 size_type __cap = capacity();
2448 if (__cap >= __n) {
2449 value_type* __p = _VSTD::__to_address(__get_pointer());
2450 traits_type::move(__p, __s, __n);
Nikolas Klauser3ec7fb22021-12-14 01:20:53 +01002451 return __null_terminate_at(__p, __n);
Martijn Velsda7d94f2020-06-19 14:24:03 -04002452 } else {
2453 size_type __sz = size();
2454 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
Nikolas Klauser3ec7fb22021-12-14 01:20:53 +01002455 return *this;
Martijn Velsda7d94f2020-06-19 14:24:03 -04002456 }
Martijn Velsda7d94f2020-06-19 14:24:03 -04002457}
2458
2459template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002460_LIBCPP_CONSTEXPR_AFTER_CXX17
Martijn Velsda7d94f2020-06-19 14:24:03 -04002461basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002462basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002463{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002464 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Nikolas Klauser93826d12022-01-04 17:24:03 +01002465 return (__builtin_constant_p(__n) && __fits_in_sso(__n))
Martijn Velsda7d94f2020-06-19 14:24:03 -04002466 ? __assign_short(__s, __n)
2467 : __assign_external(__s, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002468}
2469
2470template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002471_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002472basic_string<_CharT, _Traits, _Allocator>&
2473basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2474{
2475 size_type __cap = capacity();
2476 if (__cap < __n)
2477 {
2478 size_type __sz = size();
2479 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2480 }
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002481 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002482 traits_type::assign(__p, __n, __c);
Nikolas Klauser3ec7fb22021-12-14 01:20:53 +01002483 return __null_terminate_at(__p, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002484}
2485
2486template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002487_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002488basic_string<_CharT, _Traits, _Allocator>&
2489basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2490{
2491 pointer __p;
2492 if (__is_long())
2493 {
2494 __p = __get_long_pointer();
2495 __set_long_size(1);
2496 }
2497 else
2498 {
2499 __p = __get_short_pointer();
2500 __set_short_size(1);
2501 }
2502 traits_type::assign(*__p, __c);
2503 traits_type::assign(*++__p, value_type());
2504 __invalidate_iterators_past(1);
2505 return *this;
2506}
2507
2508template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002509_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002510basic_string<_CharT, _Traits, _Allocator>&
2511basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2512{
Martijn Vels596e3de2020-02-26 15:55:49 -05002513 if (this != &__str) {
2514 __copy_assign_alloc(__str);
2515 if (!__is_long()) {
2516 if (!__str.__is_long()) {
Eric Fiselier03bbc922020-01-15 17:27:10 -05002517 __r_.first().__r = __str.__r_.first().__r;
Martijn Vels596e3de2020-02-26 15:55:49 -05002518 } else {
Martijn Velsb6a08b62020-04-10 18:36:31 -04002519 return __assign_no_alias<true>(__str.data(), __str.size());
Martijn Vels596e3de2020-02-26 15:55:49 -05002520 }
2521 } else {
Martijn Velsb6a08b62020-04-10 18:36:31 -04002522 return __assign_no_alias<false>(__str.data(), __str.size());
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002523 }
Martijn Vels596e3de2020-02-26 15:55:49 -05002524 }
2525 return *this;
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002526}
2527
Eric Fiselierfc92be82017-04-19 00:28:44 +00002528#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002529
2530template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002531inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002532void
2533basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002534 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002535{
2536 if (__alloc() != __str.__alloc())
2537 assign(__str);
2538 else
2539 __move_assign(__str, true_type());
2540}
2541
2542template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002543inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002544void
2545basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002546#if _LIBCPP_STD_VER > 14
2547 _NOEXCEPT
2548#else
Howard Hinnant3e276872011-06-03 18:40:47 +00002549 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002550#endif
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002551{
marshall2ed41622019-11-27 07:13:00 -08002552 if (__is_long()) {
2553 __alloc_traits::deallocate(__alloc(), __get_long_pointer(),
2554 __get_long_cap());
2555#if _LIBCPP_STD_VER <= 14
2556 if (!is_nothrow_move_assignable<allocator_type>::value) {
2557 __set_short_size(0);
2558 traits_type::assign(__get_short_pointer()[0], value_type());
2559 }
2560#endif
2561 }
2562 __move_assign_alloc(__str);
2563 __r_.first() = __str.__r_.first();
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002564 if (__libcpp_is_constant_evaluated()) {
2565 __str.__default_init();
2566 } else {
2567 __str.__set_short_size(0);
2568 traits_type::assign(__str.__get_short_pointer()[0], value_type());
2569 }
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002570}
2571
2572template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002573inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002574basic_string<_CharT, _Traits, _Allocator>&
2575basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002576 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002577{
2578 __move_assign(__str, integral_constant<bool,
2579 __alloc_traits::propagate_on_container_move_assignment::value>());
2580 return *this;
2581}
2582
2583#endif
2584
2585template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002586template<class _InputIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002587_LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04002588__enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00002589<
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002590 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002591 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002592>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002593basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2594{
Marshall Clow958362f2016-09-05 01:54:30 +00002595 const basic_string __temp(__first, __last, __alloc());
Marshall Clow039b2f02016-01-13 21:54:34 +00002596 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00002597 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002598}
2599
2600template <class _CharT, class _Traits, class _Allocator>
2601template<class _ForwardIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002602_LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04002603__enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00002604<
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002605 __is_cpp17_forward_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002606 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002607>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002608basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2609{
Howard Hinnantc51e1022010-05-11 19:42:16 +00002610 size_type __cap = capacity();
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002611 size_type __n = __string_is_trivial_iterator<_ForwardIterator>::value ?
2612 static_cast<size_type>(_VSTD::distance(__first, __last)) : 0;
2613
2614 if (__string_is_trivial_iterator<_ForwardIterator>::value &&
2615 (__cap >= __n || !__addr_in_range(*__first)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002616 {
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002617 if (__cap < __n)
2618 {
2619 size_type __sz = size();
2620 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2621 }
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002622 pointer __p = __get_pointer();
Arthur O'Dwyer80dbcbe2021-09-07 21:35:37 -04002623 for (; __first != __last; ++__p, (void) ++__first)
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002624 traits_type::assign(*__p, *__first);
2625 traits_type::assign(*__p, value_type());
2626 __set_size(__n);
Arthur O'Dwyerb3db4542021-04-27 09:10:04 -04002627 __invalidate_iterators_past(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002628 }
2629 else
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002630 {
2631 const basic_string __temp(__first, __last, __alloc());
2632 assign(__temp.data(), __temp.size());
2633 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002634 return *this;
2635}
2636
2637template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002638_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002639basic_string<_CharT, _Traits, _Allocator>&
2640basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2641{
2642 size_type __sz = __str.size();
2643 if (__pos > __sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002644 __throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002645 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002646}
2647
2648template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00002649template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002650_LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04002651__enable_if_t
Marshall Clow82513342016-09-24 22:45:42 +00002652<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002653 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
2654 && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
Marshall Clowb7db4972017-11-15 20:02:27 +00002655 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002656>
Marshall Clow82513342016-09-24 22:45:42 +00002657basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002658{
Marshall Clow82513342016-09-24 22:45:42 +00002659 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002660 size_type __sz = __sv.size();
2661 if (__pos > __sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002662 __throw_out_of_range();
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002663 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2664}
2665
2666
2667template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002668_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002669basic_string<_CharT, _Traits, _Allocator>&
Martijn Velsda7d94f2020-06-19 14:24:03 -04002670basic_string<_CharT, _Traits, _Allocator>::__assign_external(const value_type* __s) {
2671 return __assign_external(__s, traits_type::length(__s));
2672}
2673
2674template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002675_LIBCPP_CONSTEXPR_AFTER_CXX17
Martijn Velsda7d94f2020-06-19 14:24:03 -04002676basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002677basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002678{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002679 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Louis Dionne3e0c4332021-08-31 10:49:06 -04002680 return __builtin_constant_p(*__s)
Nikolas Klauser93826d12022-01-04 17:24:03 +01002681 ? (__fits_in_sso(traits_type::length(__s))
Martijn Velsda7d94f2020-06-19 14:24:03 -04002682 ? __assign_short(__s, traits_type::length(__s))
2683 : __assign_external(__s, traits_type::length(__s)))
2684 : __assign_external(__s);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002685}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002686// append
2687
2688template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002689_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002690basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002691basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002692{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002693 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002694 size_type __cap = capacity();
2695 size_type __sz = size();
2696 if (__cap - __sz >= __n)
2697 {
2698 if (__n)
2699 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002700 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002701 traits_type::copy(__p + __sz, __s, __n);
2702 __sz += __n;
2703 __set_size(__sz);
2704 traits_type::assign(__p[__sz], value_type());
2705 }
2706 }
2707 else
2708 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2709 return *this;
2710}
2711
2712template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002713_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002714basic_string<_CharT, _Traits, _Allocator>&
2715basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2716{
2717 if (__n)
2718 {
2719 size_type __cap = capacity();
2720 size_type __sz = size();
2721 if (__cap - __sz < __n)
2722 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2723 pointer __p = __get_pointer();
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002724 traits_type::assign(_VSTD::__to_address(__p) + __sz, __n, __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002725 __sz += __n;
2726 __set_size(__sz);
2727 traits_type::assign(__p[__sz], value_type());
2728 }
2729 return *this;
2730}
2731
2732template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002733_LIBCPP_CONSTEXPR_AFTER_CXX17 inline void
Eric Fiselier451d5582018-11-26 20:15:38 +00002734basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n)
2735{
2736 if (__n)
2737 {
2738 size_type __cap = capacity();
2739 size_type __sz = size();
2740 if (__cap - __sz < __n)
2741 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2742 pointer __p = __get_pointer();
2743 __sz += __n;
2744 __set_size(__sz);
2745 traits_type::assign(__p[__sz], value_type());
2746 }
2747}
2748
2749template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002750_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002751void
2752basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2753{
Howard Hinnant68bf1812013-04-30 21:44:48 +00002754 bool __is_short = !__is_long();
2755 size_type __cap;
2756 size_type __sz;
2757 if (__is_short)
2758 {
2759 __cap = __min_cap - 1;
2760 __sz = __get_short_size();
2761 }
2762 else
2763 {
2764 __cap = __get_long_cap() - 1;
2765 __sz = __get_long_size();
2766 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002767 if (__sz == __cap)
Howard Hinnant68bf1812013-04-30 21:44:48 +00002768 {
Howard Hinnantc51e1022010-05-11 19:42:16 +00002769 __grow_by(__cap, 1, __sz, __sz, 0);
Louis Dionne82d2b2c2021-11-16 11:26:56 -05002770 __is_short = false; // the string is always long after __grow_by
Howard Hinnant68bf1812013-04-30 21:44:48 +00002771 }
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002772 pointer __p = __get_pointer();
Howard Hinnant68bf1812013-04-30 21:44:48 +00002773 if (__is_short)
2774 {
2775 __p = __get_short_pointer() + __sz;
2776 __set_short_size(__sz+1);
2777 }
2778 else
2779 {
2780 __p = __get_long_pointer() + __sz;
2781 __set_long_size(__sz+1);
2782 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002783 traits_type::assign(*__p, __c);
2784 traits_type::assign(*++__p, value_type());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002785}
2786
Howard Hinnantc51e1022010-05-11 19:42:16 +00002787template <class _CharT, class _Traits, class _Allocator>
2788template<class _ForwardIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002789_LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04002790__enable_if_t
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002791<
2792 __is_cpp17_forward_iterator<_ForwardIterator>::value,
2793 basic_string<_CharT, _Traits, _Allocator>&
2794>
2795basic_string<_CharT, _Traits, _Allocator>::append(
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +00002796 _ForwardIterator __first, _ForwardIterator __last)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002797{
2798 size_type __sz = size();
2799 size_type __cap = capacity();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002800 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002801 if (__n)
2802 {
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002803 if (__string_is_trivial_iterator<_ForwardIterator>::value &&
2804 !__addr_in_range(*__first))
Marshall Clow958362f2016-09-05 01:54:30 +00002805 {
2806 if (__cap - __sz < __n)
2807 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2808 pointer __p = __get_pointer() + __sz;
Arthur O'Dwyer80dbcbe2021-09-07 21:35:37 -04002809 for (; __first != __last; ++__p, (void) ++__first)
Marshall Clow958362f2016-09-05 01:54:30 +00002810 traits_type::assign(*__p, *__first);
2811 traits_type::assign(*__p, value_type());
2812 __set_size(__sz + __n);
2813 }
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002814 else
2815 {
2816 const basic_string __temp(__first, __last, __alloc());
2817 append(__temp.data(), __temp.size());
2818 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002819 }
2820 return *this;
2821}
2822
2823template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002824inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002825basic_string<_CharT, _Traits, _Allocator>&
2826basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2827{
2828 return append(__str.data(), __str.size());
2829}
2830
2831template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002832_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002833basic_string<_CharT, _Traits, _Allocator>&
2834basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2835{
2836 size_type __sz = __str.size();
2837 if (__pos > __sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002838 __throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002839 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002840}
2841
2842template <class _CharT, class _Traits, class _Allocator>
Marshall Clow62953962016-10-03 23:40:48 +00002843template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002844_LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04002845 __enable_if_t
Marshall Clow82513342016-09-24 22:45:42 +00002846 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002847 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
Marshall Clow82513342016-09-24 22:45:42 +00002848 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002849 >
Marshall Clow82513342016-09-24 22:45:42 +00002850basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002851{
Marshall Clow82513342016-09-24 22:45:42 +00002852 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002853 size_type __sz = __sv.size();
2854 if (__pos > __sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002855 __throw_out_of_range();
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002856 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2857}
2858
2859template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002860_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002861basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002862basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002863{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002864 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002865 return append(__s, traits_type::length(__s));
2866}
2867
2868// insert
2869
2870template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002871_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002872basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002873basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002874{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002875 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002876 size_type __sz = size();
2877 if (__pos > __sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002878 __throw_out_of_range();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002879 size_type __cap = capacity();
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002880 if (__libcpp_is_constant_evaluated()) {
2881 if (__cap - __sz >= __n)
2882 __grow_by_and_replace(__cap, 0, __sz, __pos, 0, __n, __s);
2883 else
2884 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2885 return *this;
2886 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002887 if (__cap - __sz >= __n)
2888 {
2889 if (__n)
2890 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002891 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002892 size_type __n_move = __sz - __pos;
2893 if (__n_move != 0)
2894 {
2895 if (__p + __pos <= __s && __s < __p + __sz)
2896 __s += __n;
2897 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2898 }
2899 traits_type::move(__p + __pos, __s, __n);
2900 __sz += __n;
2901 __set_size(__sz);
2902 traits_type::assign(__p[__sz], value_type());
2903 }
2904 }
2905 else
2906 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2907 return *this;
2908}
2909
2910template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002911_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002912basic_string<_CharT, _Traits, _Allocator>&
2913basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2914{
2915 size_type __sz = size();
2916 if (__pos > __sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002917 __throw_out_of_range();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002918 if (__n)
2919 {
2920 size_type __cap = capacity();
Howard Hinnantd17880b2013-06-28 16:59:19 +00002921 value_type* __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002922 if (__cap - __sz >= __n)
2923 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002924 __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002925 size_type __n_move = __sz - __pos;
2926 if (__n_move != 0)
2927 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2928 }
2929 else
2930 {
2931 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05002932 __p = _VSTD::__to_address(__get_long_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002933 }
2934 traits_type::assign(__p + __pos, __n, __c);
2935 __sz += __n;
2936 __set_size(__sz);
2937 traits_type::assign(__p[__sz], value_type());
2938 }
2939 return *this;
2940}
2941
2942template <class _CharT, class _Traits, class _Allocator>
2943template<class _InputIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002944_LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04002945__enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00002946<
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002947 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
Marshall Clow039b2f02016-01-13 21:54:34 +00002948 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002949>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002950basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2951{
Nikolas Klausereed25832021-12-15 01:32:30 +01002952 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2953 "string::insert(iterator, range) called with an iterator not"
2954 " referring to this string");
2955 const basic_string __temp(__first, __last, __alloc());
2956 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002957}
2958
2959template <class _CharT, class _Traits, class _Allocator>
2960template<class _ForwardIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002961_LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04002962__enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00002963<
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002964 __is_cpp17_forward_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002965 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002966>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002967basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2968{
Nikolas Klauser48d680d2022-02-26 13:28:33 +01002969 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2970 "string::insert(iterator, range) called with an iterator not referring to this string");
Nikolas Klausereed25832021-12-15 01:32:30 +01002971
Howard Hinnantc51e1022010-05-11 19:42:16 +00002972 size_type __ip = static_cast<size_type>(__pos - begin());
Nikolas Klauser48d680d2022-02-26 13:28:33 +01002973 size_type __n = static_cast<size_type>(std::distance(__first, __last));
2974 if (__n == 0)
2975 return begin() + __ip;
2976
2977 if (__string_is_trivial_iterator<_ForwardIterator>::value && !__addr_in_range(*__first))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002978 {
Nikolas Klauser48d680d2022-02-26 13:28:33 +01002979 return __insert_from_safe_copy(__n, __ip, __first, __last);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002980 }
Nikolas Klauser48d680d2022-02-26 13:28:33 +01002981 else
2982 {
2983 const basic_string __temp(__first, __last, __alloc());
2984 return __insert_from_safe_copy(__n, __ip, __temp.begin(), __temp.end());
2985 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002986}
2987
2988template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002989inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002990basic_string<_CharT, _Traits, _Allocator>&
2991basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2992{
2993 return insert(__pos1, __str.data(), __str.size());
2994}
2995
2996template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002997_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00002998basic_string<_CharT, _Traits, _Allocator>&
2999basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
3000 size_type __pos2, size_type __n)
3001{
3002 size_type __str_sz = __str.size();
3003 if (__pos2 > __str_sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01003004 __throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003005 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003006}
3007
3008template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00003009template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003010_LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04003011__enable_if_t
Marshall Clow82513342016-09-24 22:45:42 +00003012<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003013 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
Marshall Clowb7db4972017-11-15 20:02:27 +00003014 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003015>
Marshall Clow82513342016-09-24 22:45:42 +00003016basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003017 size_type __pos2, size_type __n)
3018{
Marshall Clow82513342016-09-24 22:45:42 +00003019 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003020 size_type __str_sz = __sv.size();
3021 if (__pos2 > __str_sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01003022 __throw_out_of_range();
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003023 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
3024}
3025
3026template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003027_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003028basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00003029basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003030{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003031 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003032 return insert(__pos, __s, traits_type::length(__s));
3033}
3034
3035template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003036_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003037typename basic_string<_CharT, _Traits, _Allocator>::iterator
3038basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
3039{
Louis Dionnef4cc6fb2022-02-15 15:47:45 -05003040 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
3041 "string::insert(iterator, character) called with an iterator not"
3042 " referring to this string");
3043
Howard Hinnantc51e1022010-05-11 19:42:16 +00003044 size_type __ip = static_cast<size_type>(__pos - begin());
3045 size_type __sz = size();
3046 size_type __cap = capacity();
Howard Hinnantd17880b2013-06-28 16:59:19 +00003047 value_type* __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003048 if (__cap == __sz)
3049 {
3050 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05003051 __p = _VSTD::__to_address(__get_long_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003052 }
3053 else
3054 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05003055 __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003056 size_type __n_move = __sz - __ip;
3057 if (__n_move != 0)
3058 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
3059 }
3060 traits_type::assign(__p[__ip], __c);
3061 traits_type::assign(__p[++__sz], value_type());
3062 __set_size(__sz);
3063 return begin() + static_cast<difference_type>(__ip);
3064}
3065
3066template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003067inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003068typename basic_string<_CharT, _Traits, _Allocator>::iterator
3069basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
3070{
Nikolas Klausereed25832021-12-15 01:32:30 +01003071 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
3072 "string::insert(iterator, n, value) called with an iterator not"
3073 " referring to this string");
3074 difference_type __p = __pos - begin();
3075 insert(static_cast<size_type>(__p), __n, __c);
3076 return begin() + __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003077}
3078
3079// replace
3080
3081template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003082_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003083basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00003084basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
Eric Fiseliere5b21842017-03-09 01:54:13 +00003085 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantc51e1022010-05-11 19:42:16 +00003086{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003087 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003088 size_type __sz = size();
3089 if (__pos > __sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01003090 __throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003091 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003092 size_type __cap = capacity();
3093 if (__cap - __sz + __n1 >= __n2)
3094 {
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003095 if (__libcpp_is_constant_evaluated()) {
3096 __grow_by_and_replace(__cap, 0, __sz, __pos, __n1, __n2, __s);
3097 return *this;
3098 }
Eric Fiselierc1b87a72019-11-16 17:13:26 -05003099 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003100 if (__n1 != __n2)
3101 {
3102 size_type __n_move = __sz - __pos - __n1;
3103 if (__n_move != 0)
3104 {
3105 if (__n1 > __n2)
3106 {
3107 traits_type::move(__p + __pos, __s, __n2);
3108 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
Nikolas Klauser3ec7fb22021-12-14 01:20:53 +01003109 return __null_terminate_at(__p, __sz + (__n2 - __n1));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003110 }
3111 if (__p + __pos < __s && __s < __p + __sz)
3112 {
3113 if (__p + __pos + __n1 <= __s)
3114 __s += __n2 - __n1;
3115 else // __p + __pos < __s < __p + __pos + __n1
3116 {
3117 traits_type::move(__p + __pos, __s, __n1);
3118 __pos += __n1;
3119 __s += __n2;
3120 __n2 -= __n1;
3121 __n1 = 0;
3122 }
3123 }
3124 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
3125 }
3126 }
3127 traits_type::move(__p + __pos, __s, __n2);
Nikolas Klauser3ec7fb22021-12-14 01:20:53 +01003128 return __null_terminate_at(__p, __sz + (__n2 - __n1));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003129 }
3130 else
3131 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
3132 return *this;
3133}
3134
3135template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003136_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003137basic_string<_CharT, _Traits, _Allocator>&
3138basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
3139{
3140 size_type __sz = size();
3141 if (__pos > __sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01003142 __throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003143 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003144 size_type __cap = capacity();
Howard Hinnantd17880b2013-06-28 16:59:19 +00003145 value_type* __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003146 if (__cap - __sz + __n1 >= __n2)
3147 {
Eric Fiselierc1b87a72019-11-16 17:13:26 -05003148 __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003149 if (__n1 != __n2)
3150 {
3151 size_type __n_move = __sz - __pos - __n1;
3152 if (__n_move != 0)
3153 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
3154 }
3155 }
3156 else
3157 {
3158 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Eric Fiselierc1b87a72019-11-16 17:13:26 -05003159 __p = _VSTD::__to_address(__get_long_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003160 }
3161 traits_type::assign(__p + __pos, __n2, __c);
Nikolas Klauser3ec7fb22021-12-14 01:20:53 +01003162 return __null_terminate_at(__p, __sz - (__n1 - __n2));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003163}
3164
3165template <class _CharT, class _Traits, class _Allocator>
3166template<class _InputIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003167_LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04003168__enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00003169<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05003170 __is_cpp17_input_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00003171 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003172>
Howard Hinnant990d6e82010-11-17 21:11:40 +00003173basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantc51e1022010-05-11 19:42:16 +00003174 _InputIterator __j1, _InputIterator __j2)
3175{
Marshall Clow958362f2016-09-05 01:54:30 +00003176 const basic_string __temp(__j1, __j2, __alloc());
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01003177 return replace(__i1, __i2, __temp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003178}
3179
3180template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003181inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003182basic_string<_CharT, _Traits, _Allocator>&
3183basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
3184{
3185 return replace(__pos1, __n1, __str.data(), __str.size());
3186}
3187
3188template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003189_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003190basic_string<_CharT, _Traits, _Allocator>&
3191basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
3192 size_type __pos2, size_type __n2)
3193{
3194 size_type __str_sz = __str.size();
3195 if (__pos2 > __str_sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01003196 __throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003197 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003198}
3199
3200template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00003201template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003202_LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04003203__enable_if_t
Marshall Clow82513342016-09-24 22:45:42 +00003204<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003205 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
Marshall Clowb7db4972017-11-15 20:02:27 +00003206 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003207>
Marshall Clow82513342016-09-24 22:45:42 +00003208basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003209 size_type __pos2, size_type __n2)
3210{
Marshall Clow82513342016-09-24 22:45:42 +00003211 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003212 size_type __str_sz = __sv.size();
3213 if (__pos2 > __str_sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01003214 __throw_out_of_range();
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003215 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
3216}
3217
3218template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003219_LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003220basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00003221basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003222{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003223 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003224 return replace(__pos, __n1, __s, traits_type::length(__s));
3225}
3226
3227template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003228inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003229basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant990d6e82010-11-17 21:11:40 +00003230basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003231{
3232 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
3233 __str.data(), __str.size());
3234}
3235
3236template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003237inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003238basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00003239basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003240{
3241 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
3242}
3243
3244template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003245inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003246basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00003247basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003248{
3249 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
3250}
3251
3252template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003253inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003254basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant990d6e82010-11-17 21:11:40 +00003255basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003256{
3257 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
3258}
3259
3260// erase
3261
Martijn Velsa81fc792020-02-26 13:25:43 -05003262// 'externally instantiated' erase() implementation, called when __n != npos.
3263// Does not check __pos against size()
Howard Hinnantc51e1022010-05-11 19:42:16 +00003264template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003265_LIBCPP_CONSTEXPR_AFTER_CXX17
Martijn Velsa81fc792020-02-26 13:25:43 -05003266void
3267basic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move(
3268 size_type __pos, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003269{
Howard Hinnantc51e1022010-05-11 19:42:16 +00003270 if (__n)
3271 {
Martijn Velsa81fc792020-02-26 13:25:43 -05003272 size_type __sz = size();
Eric Fiselierc1b87a72019-11-16 17:13:26 -05003273 value_type* __p = _VSTD::__to_address(__get_pointer());
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003274 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003275 size_type __n_move = __sz - __pos - __n;
3276 if (__n_move != 0)
3277 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
Nikolas Klauser3ec7fb22021-12-14 01:20:53 +01003278 __null_terminate_at(__p, __sz - __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003279 }
Martijn Velsa81fc792020-02-26 13:25:43 -05003280}
3281
3282template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003283_LIBCPP_CONSTEXPR_AFTER_CXX17
Martijn Velsa81fc792020-02-26 13:25:43 -05003284basic_string<_CharT, _Traits, _Allocator>&
3285basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos,
3286 size_type __n) {
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01003287 if (__pos > size())
3288 __throw_out_of_range();
Martijn Velsa81fc792020-02-26 13:25:43 -05003289 if (__n == npos) {
3290 __erase_to_end(__pos);
3291 } else {
3292 __erase_external_with_move(__pos, __n);
3293 }
3294 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003295}
3296
3297template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003298inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003299typename basic_string<_CharT, _Traits, _Allocator>::iterator
3300basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
3301{
Nikolas Klausereed25832021-12-15 01:32:30 +01003302 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
3303 "string::erase(iterator) called with an iterator not"
3304 " referring to this string");
3305
3306 _LIBCPP_ASSERT(__pos != end(), "string::erase(iterator) called with a non-dereferenceable iterator");
3307 iterator __b = begin();
3308 size_type __r = static_cast<size_type>(__pos - __b);
3309 erase(__r, 1);
3310 return __b + static_cast<difference_type>(__r);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003311}
3312
3313template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003314inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003315typename basic_string<_CharT, _Traits, _Allocator>::iterator
3316basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
3317{
Nikolas Klausereed25832021-12-15 01:32:30 +01003318 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
3319 "string::erase(iterator, iterator) called with an iterator not"
3320 " referring to this string");
3321
3322 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
3323 iterator __b = begin();
3324 size_type __r = static_cast<size_type>(__first - __b);
3325 erase(__r, static_cast<size_type>(__last - __first));
3326 return __b + static_cast<difference_type>(__r);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003327}
3328
3329template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003330inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003331void
3332basic_string<_CharT, _Traits, _Allocator>::pop_back()
3333{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003334 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Nikolas Klauser3ec7fb22021-12-14 01:20:53 +01003335 __erase_to_end(size() - 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003336}
3337
3338template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003339inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003340void
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003341basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003342{
3343 __invalidate_all_iterators();
3344 if (__is_long())
3345 {
3346 traits_type::assign(*__get_long_pointer(), value_type());
3347 __set_long_size(0);
3348 }
3349 else
3350 {
3351 traits_type::assign(*__get_short_pointer(), value_type());
3352 __set_short_size(0);
3353 }
3354}
3355
3356template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003357inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003358void
3359basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3360{
Nikolas Klauser3ec7fb22021-12-14 01:20:53 +01003361 __null_terminate_at(_VSTD::__to_address(__get_pointer()), __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003362}
3363
3364template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003365_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003366void
3367basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3368{
3369 size_type __sz = size();
3370 if (__n > __sz)
3371 append(__n - __sz, __c);
3372 else
3373 __erase_to_end(__n);
3374}
3375
3376template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003377_LIBCPP_CONSTEXPR_AFTER_CXX17 inline void
Eric Fiselier451d5582018-11-26 20:15:38 +00003378basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n)
3379{
3380 size_type __sz = size();
3381 if (__n > __sz) {
3382 __append_default_init(__n - __sz);
3383 } else
3384 __erase_to_end(__n);
3385}
3386
3387template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003388inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003389typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003390basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003391{
Howard Hinnantea8f7e12010-11-17 17:55:08 +00003392 size_type __m = __alloc_traits::max_size(__alloc());
Nikolas Klauser62060be2022-04-20 10:52:04 +02003393 if (__m <= std::numeric_limits<size_type>::max() / 2) {
3394 return __m - __alignment;
3395 } else {
3396 bool __uses_lsb = __endian_factor == 2;
3397 return __uses_lsb ? __m - __alignment : (__m / 2) - __alignment;
3398 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00003399}
3400
3401template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003402_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003403void
Marek Kurdejc9848142020-11-26 10:07:16 +01003404basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacity)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003405{
Marek Kurdejc9848142020-11-26 10:07:16 +01003406 if (__requested_capacity > max_size())
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01003407 __throw_length_error();
Marek Kurdejc9848142020-11-26 10:07:16 +01003408
Louis Dionne05b6d3e2022-01-14 12:30:22 -05003409 // Make sure reserve(n) never shrinks. This is technically only required in C++20
3410 // and later (since P0966R1), however we provide consistent behavior in all Standard
3411 // modes because this function is instantiated in the shared library.
3412 if (__requested_capacity <= capacity())
3413 return;
Marek Kurdejc9848142020-11-26 10:07:16 +01003414
3415 size_type __target_capacity = _VSTD::max(__requested_capacity, size());
3416 __target_capacity = __recommend(__target_capacity);
3417 if (__target_capacity == capacity()) return;
3418
3419 __shrink_or_extend(__target_capacity);
3420}
3421
3422template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003423inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Marek Kurdejc9848142020-11-26 10:07:16 +01003424void
3425basic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT
3426{
3427 size_type __target_capacity = __recommend(size());
3428 if (__target_capacity == capacity()) return;
3429
3430 __shrink_or_extend(__target_capacity);
3431}
3432
3433template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003434inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Marek Kurdejc9848142020-11-26 10:07:16 +01003435void
3436basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target_capacity)
3437{
Howard Hinnantc51e1022010-05-11 19:42:16 +00003438 size_type __cap = capacity();
3439 size_type __sz = size();
Marek Kurdejc9848142020-11-26 10:07:16 +01003440
3441 pointer __new_data, __p;
3442 bool __was_long, __now_long;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003443 if (__fits_in_sso(__target_capacity))
Howard Hinnantc51e1022010-05-11 19:42:16 +00003444 {
Marek Kurdejc9848142020-11-26 10:07:16 +01003445 __was_long = true;
3446 __now_long = false;
3447 __new_data = __get_short_pointer();
3448 __p = __get_long_pointer();
Howard Hinnantc51e1022010-05-11 19:42:16 +00003449 }
Marek Kurdejc9848142020-11-26 10:07:16 +01003450 else
3451 {
Nikolas Klauserc513eba2022-04-09 09:41:19 +02003452 if (__target_capacity > __cap) {
3453 auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1);
3454 __new_data = __allocation.ptr;
3455 __target_capacity = __allocation.count - 1;
3456 }
Marek Kurdejc9848142020-11-26 10:07:16 +01003457 else
3458 {
3459 #ifndef _LIBCPP_NO_EXCEPTIONS
3460 try
3461 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04003462 #endif // _LIBCPP_NO_EXCEPTIONS
Nikolas Klauserc513eba2022-04-09 09:41:19 +02003463 auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1);
3464 __new_data = __allocation.ptr;
3465 __target_capacity = __allocation.count - 1;
Marek Kurdejc9848142020-11-26 10:07:16 +01003466 #ifndef _LIBCPP_NO_EXCEPTIONS
3467 }
3468 catch (...)
3469 {
3470 return;
3471 }
3472 #else // _LIBCPP_NO_EXCEPTIONS
3473 if (__new_data == nullptr)
3474 return;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04003475 #endif // _LIBCPP_NO_EXCEPTIONS
Marek Kurdejc9848142020-11-26 10:07:16 +01003476 }
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003477 __begin_lifetime(__new_data, __target_capacity + 1);
Marek Kurdejc9848142020-11-26 10:07:16 +01003478 __now_long = true;
3479 __was_long = __is_long();
3480 __p = __get_pointer();
3481 }
3482 traits_type::copy(_VSTD::__to_address(__new_data),
3483 _VSTD::__to_address(__p), size()+1);
3484 if (__was_long)
3485 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
3486 if (__now_long)
3487 {
3488 __set_long_cap(__target_capacity+1);
3489 __set_long_size(__sz);
3490 __set_long_pointer(__new_data);
3491 }
3492 else
3493 __set_short_size(__sz);
3494 __invalidate_all_iterators();
Howard Hinnantc51e1022010-05-11 19:42:16 +00003495}
3496
3497template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003498inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003499typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003500basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003501{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003502 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003503 return *(data() + __pos);
3504}
3505
3506template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003507inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003508typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003509basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003510{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003511 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003512 return *(__get_pointer() + __pos);
3513}
3514
3515template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003516_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003517typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3518basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3519{
3520 if (__n >= size())
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01003521 __throw_out_of_range();
Howard Hinnantc51e1022010-05-11 19:42:16 +00003522 return (*this)[__n];
3523}
3524
3525template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003526_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003527typename basic_string<_CharT, _Traits, _Allocator>::reference
3528basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3529{
3530 if (__n >= size())
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01003531 __throw_out_of_range();
Howard Hinnantc51e1022010-05-11 19:42:16 +00003532 return (*this)[__n];
3533}
3534
3535template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003536inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003537typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003538basic_string<_CharT, _Traits, _Allocator>::front() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003539{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003540 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003541 return *__get_pointer();
3542}
3543
3544template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003545inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003546typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003547basic_string<_CharT, _Traits, _Allocator>::front() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003548{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003549 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003550 return *data();
3551}
3552
3553template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003554inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003555typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003556basic_string<_CharT, _Traits, _Allocator>::back() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003557{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003558 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003559 return *(__get_pointer() + size() - 1);
3560}
3561
3562template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003563inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003564typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003565basic_string<_CharT, _Traits, _Allocator>::back() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003566{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003567 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003568 return *(data() + size() - 1);
3569}
3570
3571template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003572_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003573typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003574basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00003575{
3576 size_type __sz = size();
3577 if (__pos > __sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01003578 __throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003579 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003580 traits_type::copy(__s, data() + __pos, __rlen);
3581 return __rlen;
3582}
3583
3584template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003585inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003586basic_string<_CharT, _Traits, _Allocator>
3587basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3588{
3589 return basic_string(*this, __pos, __n, __alloc());
3590}
3591
3592template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003593inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003594void
3595basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow8982dcd2015-07-13 20:04:56 +00003596#if _LIBCPP_STD_VER >= 14
Eric Fiselier873b8d32019-03-18 21:50:12 +00003597 _NOEXCEPT
Marshall Clow8982dcd2015-07-13 20:04:56 +00003598#else
Eric Fiselier873b8d32019-03-18 21:50:12 +00003599 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow8982dcd2015-07-13 20:04:56 +00003600 __is_nothrow_swappable<allocator_type>::value)
3601#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003602{
Louis Dionneba400782020-10-02 15:02:52 -04003603#if _LIBCPP_DEBUG_LEVEL == 2
Nikolas Klauser1a7d9f02021-12-16 14:55:03 +01003604 if (!__libcpp_is_constant_evaluated()) {
3605 if (!__is_long())
3606 __get_db()->__invalidate_all(this);
3607 if (!__str.__is_long())
3608 __get_db()->__invalidate_all(&__str);
3609 __get_db()->swap(this, &__str);
3610 }
Howard Hinnant8ea98242013-08-23 17:37:05 +00003611#endif
Eric Fiselier9bf691f2016-12-28 05:53:01 +00003612 _LIBCPP_ASSERT(
3613 __alloc_traits::propagate_on_container_swap::value ||
3614 __alloc_traits::is_always_equal::value ||
3615 __alloc() == __str.__alloc(), "swapping non-equal allocators");
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003616 _VSTD::swap(__r_.first(), __str.__r_.first());
Arthur O'Dwyer4e0de312020-11-18 18:54:38 -05003617 _VSTD::__swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003618}
3619
3620// find
3621
3622template <class _Traits>
3623struct _LIBCPP_HIDDEN __traits_eq
3624{
3625 typedef typename _Traits::char_type char_type;
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003626 _LIBCPP_INLINE_VISIBILITY
3627 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3628 {return _Traits::eq(__x, __y);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003629};
3630
3631template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003632_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003633typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003634basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003635 size_type __pos,
3636 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003637{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003638 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003639 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003640 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003641}
3642
3643template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003644inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003645typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003646basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3647 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003648{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003649 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003650 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003651}
3652
3653template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003654template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003655_LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04003656__enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00003657<
3658 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3659 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003660>
Marshall Clowe46031a2018-07-02 18:41:15 +00003661basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t,
zoecarver1997e0a2021-02-05 11:54:47 -08003662 size_type __pos) const _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003663{
Marshall Clowe46031a2018-07-02 18:41:15 +00003664 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003665 return __str_find<value_type, size_type, traits_type, npos>
3666 (data(), size(), __sv.data(), __pos, __sv.size());
3667}
3668
3669template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003670inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003671typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003672basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003673 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003674{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003675 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003676 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003677 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003678}
3679
3680template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003681_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003682typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003683basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3684 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003685{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003686 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003687 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003688}
3689
3690// rfind
3691
3692template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003693_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003694typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003695basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003696 size_type __pos,
3697 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003698{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003699 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003700 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003701 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003702}
3703
3704template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003705inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003706typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003707basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3708 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003709{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003710 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003711 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003712}
3713
3714template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003715template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003716_LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04003717__enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00003718<
3719 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3720 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003721>
Marshall Clowe46031a2018-07-02 18:41:15 +00003722basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t,
zoecarver1997e0a2021-02-05 11:54:47 -08003723 size_type __pos) const _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003724{
Marshall Clowe46031a2018-07-02 18:41:15 +00003725 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003726 return __str_rfind<value_type, size_type, traits_type, npos>
3727 (data(), size(), __sv.data(), __pos, __sv.size());
3728}
3729
3730template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003731inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003732typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003733basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003734 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003735{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003736 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003737 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003738 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003739}
3740
3741template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003742_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003743typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003744basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3745 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003746{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003747 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003748 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003749}
3750
3751// find_first_of
3752
3753template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003754_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003755typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003756basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003757 size_type __pos,
3758 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003759{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003760 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003761 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003762 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003763}
3764
3765template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003766inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003767typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003768basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3769 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003770{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003771 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003772 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003773}
3774
3775template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003776template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003777_LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04003778__enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00003779<
3780 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3781 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003782>
Marshall Clowe46031a2018-07-02 18:41:15 +00003783basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t,
zoecarver1997e0a2021-02-05 11:54:47 -08003784 size_type __pos) const _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003785{
Marshall Clowe46031a2018-07-02 18:41:15 +00003786 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003787 return __str_find_first_of<value_type, size_type, traits_type, npos>
3788 (data(), size(), __sv.data(), __pos, __sv.size());
3789}
3790
3791template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003792inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003793typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003794basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003795 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003796{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003797 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003798 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003799 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003800}
3801
3802template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003803inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003804typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003805basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3806 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003807{
3808 return find(__c, __pos);
3809}
3810
3811// find_last_of
3812
3813template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003814inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003815typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003816basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003817 size_type __pos,
3818 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003819{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003820 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003821 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003822 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003823}
3824
3825template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003826inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003827typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003828basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3829 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003830{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003831 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003832 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003833}
3834
3835template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003836template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003837_LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04003838__enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00003839<
3840 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3841 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003842>
Marshall Clowe46031a2018-07-02 18:41:15 +00003843basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t,
zoecarver1997e0a2021-02-05 11:54:47 -08003844 size_type __pos) const _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003845{
Marshall Clowe46031a2018-07-02 18:41:15 +00003846 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003847 return __str_find_last_of<value_type, size_type, traits_type, npos>
3848 (data(), size(), __sv.data(), __pos, __sv.size());
3849}
3850
3851template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003852inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003853typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003854basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003855 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003856{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003857 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003858 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003859 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003860}
3861
3862template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003863inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003864typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003865basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3866 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003867{
3868 return rfind(__c, __pos);
3869}
3870
3871// find_first_not_of
3872
3873template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003874_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003875typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003876basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003877 size_type __pos,
3878 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003879{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003880 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003881 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003882 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003883}
3884
3885template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003886inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003887typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003888basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3889 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003890{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003891 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003892 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003893}
3894
3895template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003896template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003897_LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04003898__enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00003899<
3900 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3901 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003902>
Marshall Clowe46031a2018-07-02 18:41:15 +00003903basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t,
zoecarver1997e0a2021-02-05 11:54:47 -08003904 size_type __pos) const _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003905{
Marshall Clowe46031a2018-07-02 18:41:15 +00003906 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003907 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3908 (data(), size(), __sv.data(), __pos, __sv.size());
3909}
3910
3911template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003912inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003913typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003914basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003915 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003916{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003917 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003918 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003919 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003920}
3921
3922template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003923inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003924typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003925basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3926 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003927{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003928 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003929 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003930}
3931
3932// find_last_not_of
3933
3934template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003935_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003936typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003937basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003938 size_type __pos,
3939 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003940{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003941 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003942 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003943 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003944}
3945
3946template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003947inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003948typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003949basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3950 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003951{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003952 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003953 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003954}
3955
3956template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003957template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003958_LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04003959__enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00003960<
3961 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3962 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003963>
Marshall Clowe46031a2018-07-02 18:41:15 +00003964basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t,
zoecarver1997e0a2021-02-05 11:54:47 -08003965 size_type __pos) const _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003966{
Marshall Clowe46031a2018-07-02 18:41:15 +00003967 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003968 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3969 (data(), size(), __sv.data(), __pos, __sv.size());
3970}
3971
3972template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003973inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003974typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003975basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003976 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003977{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003978 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003979 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003980 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003981}
3982
3983template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003984inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00003985typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003986basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3987 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003988{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003989 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003990 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003991}
3992
3993// compare
3994
3995template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003996template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003997_LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04003998__enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00003999<
4000 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
4001 int
Eric Fiselierc522ceb2020-01-15 16:57:08 -05004002>
zoecarver1997e0a2021-02-05 11:54:47 -08004003basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004004{
Marshall Clowe46031a2018-07-02 18:41:15 +00004005 __self_view __sv = __t;
Howard Hinnantb0485532011-07-24 21:45:06 +00004006 size_t __lhs_sz = size();
Marshall Clowdf63a6d2016-07-21 05:31:24 +00004007 size_t __rhs_sz = __sv.size();
4008 int __result = traits_type::compare(data(), __sv.data(),
Howard Hinnantb0485532011-07-24 21:45:06 +00004009 _VSTD::min(__lhs_sz, __rhs_sz));
4010 if (__result != 0)
4011 return __result;
4012 if (__lhs_sz < __rhs_sz)
4013 return -1;
4014 if (__lhs_sz > __rhs_sz)
4015 return 1;
4016 return 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004017}
4018
4019template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004020inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00004021int
Marshall Clowdf63a6d2016-07-21 05:31:24 +00004022basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004023{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00004024 return compare(__self_view(__str));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004025}
4026
4027template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004028inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00004029int
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004030basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
4031 size_type __n1,
Howard Hinnantd17880b2013-06-28 16:59:19 +00004032 const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004033 size_type __n2) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00004034{
Alp Tokerb8a95f52014-05-15 11:27:39 +00004035 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00004036 size_type __sz = size();
4037 if (__pos1 > __sz || __n2 == npos)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01004038 __throw_out_of_range();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004039 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
4040 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004041 if (__r == 0)
4042 {
4043 if (__rlen < __n2)
4044 __r = -1;
4045 else if (__rlen > __n2)
4046 __r = 1;
4047 }
4048 return __r;
4049}
4050
Marshall Clowdf63a6d2016-07-21 05:31:24 +00004051template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00004052template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004053_LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04004054__enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00004055<
4056 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
4057 int
Eric Fiselierc522ceb2020-01-15 16:57:08 -05004058>
Marshall Clowdf63a6d2016-07-21 05:31:24 +00004059basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
4060 size_type __n1,
Marshall Clowe46031a2018-07-02 18:41:15 +00004061 const _Tp& __t) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00004062{
Marshall Clowe46031a2018-07-02 18:41:15 +00004063 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00004064 return compare(__pos1, __n1, __sv.data(), __sv.size());
4065}
4066
4067template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004068inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowdf63a6d2016-07-21 05:31:24 +00004069int
4070basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
4071 size_type __n1,
4072 const basic_string& __str) const
4073{
4074 return compare(__pos1, __n1, __str.data(), __str.size());
4075}
4076
4077template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00004078template <class _Tp>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004079_LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne9ce598d2021-09-08 09:14:43 -04004080__enable_if_t
Marshall Clow82513342016-09-24 22:45:42 +00004081<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05004082 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
4083 && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
Marshall Clowb7db4972017-11-15 20:02:27 +00004084 int
Eric Fiselierc522ceb2020-01-15 16:57:08 -05004085>
Marshall Clowdf63a6d2016-07-21 05:31:24 +00004086basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
4087 size_type __n1,
Marshall Clow82513342016-09-24 22:45:42 +00004088 const _Tp& __t,
Marshall Clowdf63a6d2016-07-21 05:31:24 +00004089 size_type __pos2,
4090 size_type __n2) const
4091{
Marshall Clow82513342016-09-24 22:45:42 +00004092 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00004093 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
4094}
4095
4096template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004097_LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowdf63a6d2016-07-21 05:31:24 +00004098int
4099basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
4100 size_type __n1,
4101 const basic_string& __str,
4102 size_type __pos2,
4103 size_type __n2) const
4104{
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01004105 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
Marshall Clowdf63a6d2016-07-21 05:31:24 +00004106}
4107
4108template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004109_LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowdf63a6d2016-07-21 05:31:24 +00004110int
4111basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
4112{
4113 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
4114 return compare(0, npos, __s, traits_type::length(__s));
4115}
4116
4117template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004118_LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowdf63a6d2016-07-21 05:31:24 +00004119int
4120basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
4121 size_type __n1,
4122 const value_type* __s) const
4123{
4124 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
4125 return compare(__pos1, __n1, __s, traits_type::length(__s));
4126}
4127
Howard Hinnantc51e1022010-05-11 19:42:16 +00004128// __invariants
4129
4130template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004131inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00004132bool
4133basic_string<_CharT, _Traits, _Allocator>::__invariants() const
4134{
4135 if (size() > capacity())
4136 return false;
4137 if (capacity() < __min_cap - 1)
4138 return false;
Bruce Mitchener170d8972020-11-24 12:53:53 -05004139 if (data() == nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004140 return false;
Louis Dionne663415f2020-10-05 16:16:13 -04004141 if (data()[size()] != value_type())
Howard Hinnantc51e1022010-05-11 19:42:16 +00004142 return false;
4143 return true;
4144}
4145
Vedant Kumar55e007e2018-03-08 21:15:26 +00004146// __clear_and_shrink
4147
4148template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004149inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne173f29e2019-05-29 16:01:36 +00004150void
Marshall Clowe60a7182018-05-29 17:04:37 +00004151basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT
Vedant Kumar55e007e2018-03-08 21:15:26 +00004152{
4153 clear();
4154 if(__is_long())
4155 {
4156 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
4157 __set_long_cap(0);
4158 __set_short_size(0);
Louis Dionne663415f2020-10-05 16:16:13 -04004159 traits_type::assign(*__get_short_pointer(), value_type());
Vedant Kumar55e007e2018-03-08 21:15:26 +00004160 }
Louis Dionne173f29e2019-05-29 16:01:36 +00004161}
Vedant Kumar55e007e2018-03-08 21:15:26 +00004162
Howard Hinnantc51e1022010-05-11 19:42:16 +00004163// operator==
4164
4165template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004166inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004167bool
4168operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004169 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004170{
Howard Hinnantaaeb1132013-04-22 23:55:13 +00004171 size_t __lhs_sz = __lhs.size();
4172 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
4173 __rhs.data(),
4174 __lhs_sz) == 0;
4175}
4176
4177template<class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004178inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaaeb1132013-04-22 23:55:13 +00004179bool
4180operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
4181 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
4182{
4183 size_t __lhs_sz = __lhs.size();
4184 if (__lhs_sz != __rhs.size())
4185 return false;
4186 const char* __lp = __lhs.data();
4187 const char* __rp = __rhs.data();
4188 if (__lhs.__is_long())
4189 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
4190 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
4191 if (*__lp != *__rp)
4192 return false;
4193 return true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004194}
4195
4196template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004197inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004198bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004199operator==(const _CharT* __lhs,
4200 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004201{
Eric Fiselier0cafa3f2015-08-28 03:02:37 +00004202 typedef basic_string<_CharT, _Traits, _Allocator> _String;
4203 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
4204 size_t __lhs_len = _Traits::length(__lhs);
4205 if (__lhs_len != __rhs.size()) return false;
4206 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004207}
4208
Howard Hinnantc51e1022010-05-11 19:42:16 +00004209template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004210inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004211bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004212operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
4213 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004214{
Eric Fiselier0cafa3f2015-08-28 03:02:37 +00004215 typedef basic_string<_CharT, _Traits, _Allocator> _String;
4216 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
4217 size_t __rhs_len = _Traits::length(__rhs);
4218 if (__rhs_len != __lhs.size()) return false;
4219 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004220}
4221
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004222template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004223inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004224bool
4225operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004226 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004227{
4228 return !(__lhs == __rhs);
4229}
4230
4231template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004232inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004233bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004234operator!=(const _CharT* __lhs,
4235 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004236{
4237 return !(__lhs == __rhs);
4238}
4239
4240template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004241inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004242bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004243operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4244 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004245{
4246 return !(__lhs == __rhs);
4247}
4248
4249// operator<
4250
4251template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004252inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004253bool
4254operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004255 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004256{
Howard Hinnanta2660c12011-07-24 15:07:21 +00004257 return __lhs.compare(__rhs) < 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004258}
4259
4260template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004261inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004262bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004263operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4264 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004265{
Howard Hinnanta2660c12011-07-24 15:07:21 +00004266 return __lhs.compare(__rhs) < 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004267}
4268
4269template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004270inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004271bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004272operator< (const _CharT* __lhs,
4273 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004274{
4275 return __rhs.compare(__lhs) > 0;
4276}
4277
Howard Hinnantc51e1022010-05-11 19:42:16 +00004278// operator>
4279
4280template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004281inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004282bool
4283operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004284 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004285{
4286 return __rhs < __lhs;
4287}
4288
4289template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004290inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004291bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004292operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4293 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004294{
4295 return __rhs < __lhs;
4296}
4297
4298template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004299inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004300bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004301operator> (const _CharT* __lhs,
4302 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004303{
4304 return __rhs < __lhs;
4305}
4306
4307// operator<=
4308
4309template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004310inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004311bool
4312operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004313 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004314{
4315 return !(__rhs < __lhs);
4316}
4317
4318template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004319inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004320bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004321operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4322 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004323{
4324 return !(__rhs < __lhs);
4325}
4326
4327template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004328inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004329bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004330operator<=(const _CharT* __lhs,
4331 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004332{
4333 return !(__rhs < __lhs);
4334}
4335
4336// operator>=
4337
4338template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004339inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004340bool
4341operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004342 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004343{
4344 return !(__lhs < __rhs);
4345}
4346
4347template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004348inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004349bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004350operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4351 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004352{
4353 return !(__lhs < __rhs);
4354}
4355
4356template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004357inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00004358bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004359operator>=(const _CharT* __lhs,
4360 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004361{
4362 return !(__lhs < __rhs);
4363}
4364
4365// operator +
4366
4367template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004368_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00004369basic_string<_CharT, _Traits, _Allocator>
4370operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4371 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4372{
Nikolas Klauser38631bf2022-02-11 19:24:31 +01004373 using _String = basic_string<_CharT, _Traits, _Allocator>;
Nikolas Klauser55dc8082022-04-09 16:19:45 +02004374 auto __lhs_sz = __lhs.size();
4375 auto __rhs_sz = __rhs.size();
4376 _String __r(__uninitialized_size_tag(),
4377 __lhs_sz + __rhs_sz,
4378 _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
4379 auto __ptr = std::__to_address(__r.__get_pointer());
4380 _Traits::copy(__ptr, __lhs.data(), __lhs_sz);
4381 _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz);
4382 _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004383 return __r;
4384}
4385
4386template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004387_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00004388basic_string<_CharT, _Traits, _Allocator>
4389operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4390{
Nikolas Klauser38631bf2022-02-11 19:24:31 +01004391 using _String = basic_string<_CharT, _Traits, _Allocator>;
Nikolas Klauser55dc8082022-04-09 16:19:45 +02004392 auto __lhs_sz = _Traits::length(__lhs);
4393 auto __rhs_sz = __rhs.size();
4394 _String __r(__uninitialized_size_tag(),
4395 __lhs_sz + __rhs_sz,
4396 _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator()));
4397 auto __ptr = std::__to_address(__r.__get_pointer());
4398 _Traits::copy(__ptr, __lhs, __lhs_sz);
4399 _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz);
4400 _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004401 return __r;
4402}
4403
4404template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004405_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00004406basic_string<_CharT, _Traits, _Allocator>
4407operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4408{
Nikolas Klauser38631bf2022-02-11 19:24:31 +01004409 using _String = basic_string<_CharT, _Traits, _Allocator>;
Nikolas Klauser38631bf2022-02-11 19:24:31 +01004410 typename _String::size_type __rhs_sz = __rhs.size();
Nikolas Klauser55dc8082022-04-09 16:19:45 +02004411 _String __r(__uninitialized_size_tag(),
4412 __rhs_sz + 1,
4413 _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator()));
4414 auto __ptr = std::__to_address(__r.__get_pointer());
4415 _Traits::assign(__ptr, 1, __lhs);
4416 _Traits::copy(__ptr + 1, __rhs.data(), __rhs_sz);
4417 _Traits::assign(__ptr + 1 + __rhs_sz, 1, _CharT());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004418 return __r;
4419}
4420
4421template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004422inline _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00004423basic_string<_CharT, _Traits, _Allocator>
4424operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
4425{
Nikolas Klauser38631bf2022-02-11 19:24:31 +01004426 using _String = basic_string<_CharT, _Traits, _Allocator>;
Nikolas Klauser38631bf2022-02-11 19:24:31 +01004427 typename _String::size_type __lhs_sz = __lhs.size();
4428 typename _String::size_type __rhs_sz = _Traits::length(__rhs);
Nikolas Klauser55dc8082022-04-09 16:19:45 +02004429 _String __r(__uninitialized_size_tag(),
4430 __lhs_sz + __rhs_sz,
4431 _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
4432 auto __ptr = std::__to_address(__r.__get_pointer());
4433 _Traits::copy(__ptr, __lhs.data(), __lhs_sz);
4434 _Traits::copy(__ptr + __lhs_sz, __rhs, __rhs_sz);
4435 _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004436 return __r;
4437}
4438
4439template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004440_LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00004441basic_string<_CharT, _Traits, _Allocator>
4442operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
4443{
Nikolas Klauser38631bf2022-02-11 19:24:31 +01004444 using _String = basic_string<_CharT, _Traits, _Allocator>;
Nikolas Klauser38631bf2022-02-11 19:24:31 +01004445 typename _String::size_type __lhs_sz = __lhs.size();
Nikolas Klauser55dc8082022-04-09 16:19:45 +02004446 _String __r(__uninitialized_size_tag(),
4447 __lhs_sz + 1,
4448 _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
4449 auto __ptr = std::__to_address(__r.__get_pointer());
4450 _Traits::copy(__ptr, __lhs.data(), __lhs_sz);
4451 _Traits::assign(__ptr + __lhs_sz, 1, __rhs);
4452 _Traits::assign(__ptr + 1 + __lhs_sz, 1, _CharT());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004453 return __r;
4454}
4455
Eric Fiselierfc92be82017-04-19 00:28:44 +00004456#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00004457
4458template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004459inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00004460basic_string<_CharT, _Traits, _Allocator>
4461operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4462{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004463 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004464}
4465
4466template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004467inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00004468basic_string<_CharT, _Traits, _Allocator>
4469operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4470{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004471 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004472}
4473
4474template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004475inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00004476basic_string<_CharT, _Traits, _Allocator>
4477operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4478{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004479 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004480}
4481
4482template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004483inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00004484basic_string<_CharT, _Traits, _Allocator>
4485operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4486{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004487 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004488}
4489
4490template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004491inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00004492basic_string<_CharT, _Traits, _Allocator>
4493operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4494{
4495 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004496 return _VSTD::move(__rhs);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004497}
4498
4499template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004500inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00004501basic_string<_CharT, _Traits, _Allocator>
4502operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
4503{
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004504 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004505}
4506
4507template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004508inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00004509basic_string<_CharT, _Traits, _Allocator>
4510operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
4511{
4512 __lhs.push_back(__rhs);
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00004513 return _VSTD::move(__lhs);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004514}
4515
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04004516#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00004517
4518// swap
4519
4520template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004521inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc51e1022010-05-11 19:42:16 +00004522void
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004523swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant3e276872011-06-03 18:40:47 +00004524 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4525 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00004526{
4527 __lhs.swap(__rhs);
4528}
4529
Bruce Mitchener170d8972020-11-24 12:53:53 -05004530_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = nullptr, int __base = 10);
4531_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = nullptr, int __base = 10);
4532_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = nullptr, int __base = 10);
4533_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = nullptr, int __base = 10);
4534_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = nullptr, int __base = 10);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004535
Bruce Mitchener170d8972020-11-24 12:53:53 -05004536_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = nullptr);
4537_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = nullptr);
4538_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = nullptr);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004539
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004540_LIBCPP_FUNC_VIS string to_string(int __val);
4541_LIBCPP_FUNC_VIS string to_string(unsigned __val);
4542_LIBCPP_FUNC_VIS string to_string(long __val);
4543_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4544_LIBCPP_FUNC_VIS string to_string(long long __val);
4545_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4546_LIBCPP_FUNC_VIS string to_string(float __val);
4547_LIBCPP_FUNC_VIS string to_string(double __val);
4548_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004549
Louis Dionne89258142021-08-23 15:32:36 -04004550#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Bruce Mitchener170d8972020-11-24 12:53:53 -05004551_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
4552_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
4553_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
4554_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
4555_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = nullptr, int __base = 10);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004556
Bruce Mitchener170d8972020-11-24 12:53:53 -05004557_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = nullptr);
4558_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = nullptr);
4559_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = nullptr);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004560
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004561_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4562_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4563_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4564_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4565_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4566_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4567_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4568_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4569_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Louis Dionne89258142021-08-23 15:32:36 -04004570#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004571
Howard Hinnantc51e1022010-05-11 19:42:16 +00004572template<class _CharT, class _Traits, class _Allocator>
Martin Storsjö88890c22021-02-22 01:13:13 +02004573_LIBCPP_TEMPLATE_DATA_VIS
Eric Fiselierc9fdaf12020-01-15 17:02:17 -05004574const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4575 basic_string<_CharT, _Traits, _Allocator>::npos;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004576
Marshall Clow851b9ec2019-05-20 21:56:51 +00004577template <class _CharT, class _Allocator>
4578struct _LIBCPP_TEMPLATE_VIS
4579 hash<basic_string<_CharT, char_traits<_CharT>, _Allocator> >
4580 : public unary_function<
4581 basic_string<_CharT, char_traits<_CharT>, _Allocator>, size_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00004582{
4583 size_t
Marshall Clow851b9ec2019-05-20 21:56:51 +00004584 operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT
4585 { return __do_string_hash(__val.data(), __val.data() + __val.size()); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00004586};
4587
Howard Hinnantc51e1022010-05-11 19:42:16 +00004588
Howard Hinnantdc095972011-07-18 15:51:59 +00004589template<class _CharT, class _Traits, class _Allocator>
4590basic_ostream<_CharT, _Traits>&
4591operator<<(basic_ostream<_CharT, _Traits>& __os,
4592 const basic_string<_CharT, _Traits, _Allocator>& __str);
4593
4594template<class _CharT, class _Traits, class _Allocator>
4595basic_istream<_CharT, _Traits>&
4596operator>>(basic_istream<_CharT, _Traits>& __is,
4597 basic_string<_CharT, _Traits, _Allocator>& __str);
4598
4599template<class _CharT, class _Traits, class _Allocator>
4600basic_istream<_CharT, _Traits>&
4601getline(basic_istream<_CharT, _Traits>& __is,
4602 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4603
4604template<class _CharT, class _Traits, class _Allocator>
4605inline _LIBCPP_INLINE_VISIBILITY
4606basic_istream<_CharT, _Traits>&
4607getline(basic_istream<_CharT, _Traits>& __is,
4608 basic_string<_CharT, _Traits, _Allocator>& __str);
4609
Howard Hinnantdc095972011-07-18 15:51:59 +00004610template<class _CharT, class _Traits, class _Allocator>
4611inline _LIBCPP_INLINE_VISIBILITY
4612basic_istream<_CharT, _Traits>&
4613getline(basic_istream<_CharT, _Traits>&& __is,
4614 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4615
4616template<class _CharT, class _Traits, class _Allocator>
4617inline _LIBCPP_INLINE_VISIBILITY
4618basic_istream<_CharT, _Traits>&
4619getline(basic_istream<_CharT, _Traits>&& __is,
4620 basic_string<_CharT, _Traits, _Allocator>& __str);
4621
Marshall Clow29b53f22018-12-14 18:49:35 +00004622#if _LIBCPP_STD_VER > 17
Marek Kurdeja98b1412020-05-02 13:58:03 +02004623template <class _CharT, class _Traits, class _Allocator, class _Up>
Marshall Clow29b53f22018-12-14 18:49:35 +00004624inline _LIBCPP_INLINE_VISIBILITY
Marek Kurdeja98b1412020-05-02 13:58:03 +02004625 typename basic_string<_CharT, _Traits, _Allocator>::size_type
4626 erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v) {
4627 auto __old_size = __str.size();
4628 __str.erase(_VSTD::remove(__str.begin(), __str.end(), __v), __str.end());
4629 return __old_size - __str.size();
4630}
Marshall Clow29b53f22018-12-14 18:49:35 +00004631
Marek Kurdeja98b1412020-05-02 13:58:03 +02004632template <class _CharT, class _Traits, class _Allocator, class _Predicate>
Marshall Clow29b53f22018-12-14 18:49:35 +00004633inline _LIBCPP_INLINE_VISIBILITY
Marek Kurdeja98b1412020-05-02 13:58:03 +02004634 typename basic_string<_CharT, _Traits, _Allocator>::size_type
4635 erase_if(basic_string<_CharT, _Traits, _Allocator>& __str,
4636 _Predicate __pred) {
4637 auto __old_size = __str.size();
4638 __str.erase(_VSTD::remove_if(__str.begin(), __str.end(), __pred),
4639 __str.end());
4640 return __old_size - __str.size();
4641}
Marshall Clow29b53f22018-12-14 18:49:35 +00004642#endif
4643
Louis Dionneba400782020-10-02 15:02:52 -04004644#if _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant8ea98242013-08-23 17:37:05 +00004645
4646template<class _CharT, class _Traits, class _Allocator>
4647bool
4648basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4649{
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01004650 return data() <= _VSTD::__to_address(__i->base()) &&
4651 _VSTD::__to_address(__i->base()) < data() + size();
Howard Hinnant8ea98242013-08-23 17:37:05 +00004652}
4653
4654template<class _CharT, class _Traits, class _Allocator>
4655bool
4656basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4657{
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01004658 return data() < _VSTD::__to_address(__i->base()) &&
4659 _VSTD::__to_address(__i->base()) <= data() + size();
Howard Hinnant8ea98242013-08-23 17:37:05 +00004660}
4661
4662template<class _CharT, class _Traits, class _Allocator>
4663bool
4664basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4665{
Eric Fiselierc1b87a72019-11-16 17:13:26 -05004666 const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01004667 return data() <= __p && __p <= data() + size();
Howard Hinnant8ea98242013-08-23 17:37:05 +00004668}
4669
4670template<class _CharT, class _Traits, class _Allocator>
4671bool
4672basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4673{
Eric Fiselierc1b87a72019-11-16 17:13:26 -05004674 const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01004675 return data() <= __p && __p < data() + size();
Howard Hinnant8ea98242013-08-23 17:37:05 +00004676}
4677
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04004678#endif // _LIBCPP_DEBUG_LEVEL == 2
Howard Hinnant8ea98242013-08-23 17:37:05 +00004679
Louis Dionne173f29e2019-05-29 16:01:36 +00004680#if _LIBCPP_STD_VER > 11
Marshall Clowcba751f2013-07-23 17:05:24 +00004681// Literal suffixes for basic_string [basic.string.literals]
Marshall Clowac868372013-10-05 21:18:32 +00004682inline namespace literals
Marshall Clowcba751f2013-07-23 17:05:24 +00004683{
4684 inline namespace string_literals
4685 {
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004686 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant5c167562013-08-07 19:39:48 +00004687 basic_string<char> operator "" s( const char *__str, size_t __len )
4688 {
4689 return basic_string<char> (__str, __len);
4690 }
Marshall Clowcba751f2013-07-23 17:05:24 +00004691
Louis Dionne89258142021-08-23 15:32:36 -04004692#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004693 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant5c167562013-08-07 19:39:48 +00004694 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4695 {
4696 return basic_string<wchar_t> (__str, __len);
4697 }
Louis Dionne89258142021-08-23 15:32:36 -04004698#endif
Marshall Clowcba751f2013-07-23 17:05:24 +00004699
Arthur O'Dwyerafa5d5f2021-04-18 21:47:08 -04004700#ifndef _LIBCPP_HAS_NO_CHAR8_T
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004701 inline _LIBCPP_INLINE_VISIBILITY constexpr
Marshall Clow8732fed2018-12-11 04:35:44 +00004702 basic_string<char8_t> operator "" s(const char8_t *__str, size_t __len) _NOEXCEPT
4703 {
4704 return basic_string<char8_t> (__str, __len);
4705 }
4706#endif
4707
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004708 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant5c167562013-08-07 19:39:48 +00004709 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4710 {
4711 return basic_string<char16_t> (__str, __len);
4712 }
Marshall Clowcba751f2013-07-23 17:05:24 +00004713
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02004714 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnant5c167562013-08-07 19:39:48 +00004715 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4716 {
4717 return basic_string<char32_t> (__str, __len);
4718 }
Nikolas Klauserd26407a2021-12-02 14:12:51 +01004719 } // namespace string_literals
4720} // namespace literals
Mark de Weverdf3e0d42021-09-26 15:47:42 +02004721
4722#if _LIBCPP_STD_VER > 17
4723template <>
4724inline constexpr bool __format::__enable_insertable<std::basic_string<char>> = true;
4725#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4726template <>
4727inline constexpr bool __format::__enable_insertable<std::basic_string<wchar_t>> = true;
4728#endif
4729#endif
4730
Marshall Clowcba751f2013-07-23 17:05:24 +00004731#endif
4732
Howard Hinnantc51e1022010-05-11 19:42:16 +00004733_LIBCPP_END_NAMESPACE_STD
4734
Eric Fiselierf4433a32017-05-31 22:07:49 +00004735_LIBCPP_POP_MACROS
4736
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04004737#endif // _LIBCPP_STRING