blob: 652fa32070352a2bce2515fd33b8ba0df719a394 [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
Mark de Weverb4830e62022-07-19 07:56:23 +020016#include <compare>
17#include <initializer_list>
18
Howard Hinnantc51e1022010-05-11 19:42:16 +000019namespace std
20{
21
22template <class stateT>
23class fpos
24{
25private:
26 stateT st;
27public:
28 fpos(streamoff = streamoff());
29
30 operator streamoff() const;
31
32 stateT state() const;
33 void state(stateT);
34
35 fpos& operator+=(streamoff);
36 fpos operator+ (streamoff) const;
37 fpos& operator-=(streamoff);
38 fpos operator- (streamoff) const;
39};
40
41template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y);
42
43template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y);
44template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y);
45
46template <class charT>
47struct char_traits
48{
Mark de Weverb4830e62022-07-19 07:56:23 +020049 using char_type = charT;
50 using int_type = ...;
51 using off_type = streamoff;
52 using pos_type = streampos;
53 using state_type = mbstate_t;
54 using comparison_category = strong_ordering; // Since C++20 only for the specializations
55 // char, wchar_t, char8_t, char16_t, and char32_t.
Howard Hinnantc51e1022010-05-11 19:42:16 +000056
Howard Hinnantaeb17d82011-05-29 19:57:12 +000057 static void assign(char_type& c1, const char_type& c2) noexcept;
Howard Hinnant270c00e2012-07-20 19:09:12 +000058 static constexpr bool eq(char_type c1, char_type c2) noexcept;
59 static constexpr bool lt(char_type c1, char_type c2) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000060
61 static int compare(const char_type* s1, const char_type* s2, size_t n);
62 static size_t length(const char_type* s);
63 static const char_type* find(const char_type* s, size_t n, const char_type& a);
64 static char_type* move(char_type* s1, const char_type* s2, size_t n);
65 static char_type* copy(char_type* s1, const char_type* s2, size_t n);
66 static char_type* assign(char_type* s, size_t n, char_type a);
67
Howard Hinnant270c00e2012-07-20 19:09:12 +000068 static constexpr int_type not_eof(int_type c) noexcept;
69 static constexpr char_type to_char_type(int_type c) noexcept;
70 static constexpr int_type to_int_type(char_type c) noexcept;
71 static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept;
72 static constexpr int_type eof() noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000073};
74
75template <> struct char_traits<char>;
76template <> struct char_traits<wchar_t>;
Marek Kurdeje3ac4e22021-03-23 17:15:07 +010077template <> struct char_traits<char8_t>; // C++20
78template <> struct char_traits<char16_t>;
79template <> struct char_traits<char32_t>;
Howard Hinnantc51e1022010-05-11 19:42:16 +000080
Howard Hinnant3b6579a2010-08-22 00:02:43 +000081template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
Howard Hinnantc51e1022010-05-11 19:42:16 +000082class basic_string
83{
Howard Hinnant3b6579a2010-08-22 00:02:43 +000084public:
85// types:
Howard Hinnantc51e1022010-05-11 19:42:16 +000086 typedef traits traits_type;
87 typedef typename traits_type::char_type value_type;
88 typedef Allocator allocator_type;
89 typedef typename allocator_type::size_type size_type;
90 typedef typename allocator_type::difference_type difference_type;
91 typedef typename allocator_type::reference reference;
92 typedef typename allocator_type::const_reference const_reference;
93 typedef typename allocator_type::pointer pointer;
94 typedef typename allocator_type::const_pointer const_pointer;
95 typedef implementation-defined iterator;
96 typedef implementation-defined const_iterator;
97 typedef std::reverse_iterator<iterator> reverse_iterator;
98 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
99
100 static const size_type npos = -1;
101
Howard Hinnant3e276872011-06-03 18:40:47 +0000102 basic_string()
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200103 noexcept(is_nothrow_default_constructible<allocator_type>::value); // constexpr since C++20
104 explicit basic_string(const allocator_type& a); // constexpr since C++20
105 basic_string(const basic_string& str); // constexpr since C++20
Howard Hinnant3e276872011-06-03 18:40:47 +0000106 basic_string(basic_string&& str)
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200107 noexcept(is_nothrow_move_constructible<allocator_type>::value); // constexpr since C++20
Marshall Clow83445802016-04-07 18:13:41 +0000108 basic_string(const basic_string& str, size_type pos,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200109 const allocator_type& a = allocator_type()); // constexpr since C++20
Marshall Clow83445802016-04-07 18:13:41 +0000110 basic_string(const basic_string& str, size_type pos, size_type n,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200111 const Allocator& a = Allocator()); // constexpr since C++20
Marshall Clow78dbe462016-11-14 18:22:19 +0000112 template<class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200113 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 +0000114 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200115 explicit basic_string(const T& t, const Allocator& a = Allocator()); // C++17, constexpr since C++20
116 basic_string(const value_type* s, const allocator_type& a = allocator_type()); // constexpr since C++20
117 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 +0200118 basic_string(nullptr_t) = delete; // C++2b
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200119 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 +0000120 template<class InputIterator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000121 basic_string(InputIterator begin, InputIterator end,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200122 const allocator_type& a = allocator_type()); // constexpr since C++20
123 basic_string(initializer_list<value_type>, const Allocator& = Allocator()); // constexpr since C++20
124 basic_string(const basic_string&, const Allocator&); // constexpr since C++20
125 basic_string(basic_string&&, const Allocator&); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000126
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200127 ~basic_string(); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000128
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200129 operator basic_string_view<charT, traits>() const noexcept; // constexpr since C++20
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000130
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200131 basic_string& operator=(const basic_string& str); // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000132 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200133 basic_string& operator=(const T& t); // C++17, constexpr since C++20
Howard Hinnant3e276872011-06-03 18:40:47 +0000134 basic_string& operator=(basic_string&& str)
135 noexcept(
Marshall Clow2fe8a8d2015-08-18 18:57:00 +0000136 allocator_type::propagate_on_container_move_assignment::value ||
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200137 allocator_type::is_always_equal::value ); // C++17, constexpr since C++20
138 basic_string& operator=(const value_type* s); // constexpr since C++20
Marek Kurdej90d79712021-07-27 16:16:21 +0200139 basic_string& operator=(nullptr_t) = delete; // C++2b
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200140 basic_string& operator=(value_type c); // constexpr since C++20
141 basic_string& operator=(initializer_list<value_type>); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000142
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200143 iterator begin() noexcept; // constexpr since C++20
144 const_iterator begin() const noexcept; // constexpr since C++20
145 iterator end() noexcept; // constexpr since C++20
146 const_iterator end() const noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000147
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200148 reverse_iterator rbegin() noexcept; // constexpr since C++20
149 const_reverse_iterator rbegin() const noexcept; // constexpr since C++20
150 reverse_iterator rend() noexcept; // constexpr since C++20
151 const_reverse_iterator rend() const noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000152
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200153 const_iterator cbegin() const noexcept; // constexpr since C++20
154 const_iterator cend() const noexcept; // constexpr since C++20
155 const_reverse_iterator crbegin() const noexcept; // constexpr since C++20
156 const_reverse_iterator crend() const noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000157
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200158 size_type size() const noexcept; // constexpr since C++20
159 size_type length() const noexcept; // constexpr since C++20
160 size_type max_size() const noexcept; // constexpr since C++20
161 size_type capacity() const noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000162
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200163 void resize(size_type n, value_type c); // constexpr since C++20
164 void resize(size_type n); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000165
Nikolas Klauser9e6040c2022-01-06 21:43:26 +0100166 template<class Operation>
167 constexpr void resize_and_overwrite(size_type n, Operation op); // since C++23
168
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200169 void reserve(size_type res_arg); // constexpr since C++20
Marek Kurdejc9848142020-11-26 10:07:16 +0100170 void reserve(); // deprecated in C++20
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200171 void shrink_to_fit(); // constexpr since C++20
172 void clear() noexcept; // constexpr since C++20
173 bool empty() const noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000174
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200175 const_reference operator[](size_type pos) const; // constexpr since C++20
176 reference operator[](size_type pos); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000177
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200178 const_reference at(size_type n) const; // constexpr since C++20
179 reference at(size_type n); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000180
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200181 basic_string& operator+=(const basic_string& str); // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000182 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200183 basic_string& operator+=(const T& t); // C++17, constexpr since C++20
184 basic_string& operator+=(const value_type* s); // constexpr since C++20
185 basic_string& operator+=(value_type c); // constexpr since C++20
186 basic_string& operator+=(initializer_list<value_type>); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000187
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200188 basic_string& append(const basic_string& str); // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000189 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200190 basic_string& append(const T& t); // C++17, constexpr since C++20
191 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 +0000192 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200193 basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17, constexpr since C++20
194 basic_string& append(const value_type* s, size_type n); // constexpr since C++20
195 basic_string& append(const value_type* s); // constexpr since C++20
196 basic_string& append(size_type n, value_type c); // constexpr since C++20
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000197 template<class InputIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200198 basic_string& append(InputIterator first, InputIterator last); // constexpr since C++20
199 basic_string& append(initializer_list<value_type>); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000200
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200201 void push_back(value_type c); // constexpr since C++20
202 void pop_back(); // constexpr since C++20
203 reference front(); // constexpr since C++20
204 const_reference front() const; // constexpr since C++20
205 reference back(); // constexpr since C++20
206 const_reference back() const; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000207
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200208 basic_string& assign(const basic_string& str); // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000209 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200210 basic_string& assign(const T& t); // C++17, constexpr since C++20
211 basic_string& assign(basic_string&& str); // constexpr since C++20
212 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 +0000213 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200214 basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17, constexpr since C++20
215 basic_string& assign(const value_type* s, size_type n); // constexpr since C++20
216 basic_string& assign(const value_type* s); // constexpr since C++20
217 basic_string& assign(size_type n, value_type c); // constexpr since C++20
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000218 template<class InputIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200219 basic_string& assign(InputIterator first, InputIterator last); // constexpr since C++20
220 basic_string& assign(initializer_list<value_type>); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000221
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200222 basic_string& insert(size_type pos1, const basic_string& str); // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000223 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200224 basic_string& insert(size_type pos1, const T& t); // constexpr since C++20
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000225 basic_string& insert(size_type pos1, const basic_string& str,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200226 size_type pos2, size_type n); // constexpr since C++20
Marshall Clow82513342016-09-24 22:45:42 +0000227 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200228 basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17, constexpr since C++20
229 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); // C++14, constexpr since C++20
230 basic_string& insert(size_type pos, const value_type* s); // constexpr since C++20
231 basic_string& insert(size_type pos, size_type n, value_type c); // constexpr since C++20
232 iterator insert(const_iterator p, value_type c); // constexpr since C++20
233 iterator insert(const_iterator p, size_type n, value_type c); // constexpr since C++20
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000234 template<class InputIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200235 iterator insert(const_iterator p, InputIterator first, InputIterator last); // constexpr since C++20
236 iterator insert(const_iterator p, initializer_list<value_type>); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000237
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200238 basic_string& erase(size_type pos = 0, size_type n = npos); // constexpr since C++20
239 iterator erase(const_iterator position); // constexpr since C++20
240 iterator erase(const_iterator first, const_iterator last); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000241
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200242 basic_string& replace(size_type pos1, size_type n1, const basic_string& str); // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000243 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200244 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 +0000245 basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200246 size_type pos2, size_type n2=npos); // C++14, constexpr since C++20
Marshall Clow82513342016-09-24 22:45:42 +0000247 template <class T>
248 basic_string& replace(size_type pos1, size_type n1, const T& t,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200249 size_type pos2, size_type n); // C++17, constexpr since C++20
250 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2); // constexpr since C++20
251 basic_string& replace(size_type pos, size_type n1, const value_type* s); // constexpr since C++20
252 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c); // constexpr since C++20
253 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str); // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000254 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200255 basic_string& replace(const_iterator i1, const_iterator i2, const T& t); // C++17, constexpr since C++20
256 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n); // constexpr since C++20
257 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s); // constexpr since C++20
258 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 +0000259 template<class InputIterator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200260 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2); // constexpr since C++20
261 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000262
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200263 size_type copy(value_type* s, size_type n, size_type pos = 0) const; // constexpr since C++20
264 basic_string substr(size_type pos = 0, size_type n = npos) const; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000265
Howard Hinnant3e276872011-06-03 18:40:47 +0000266 void swap(basic_string& str)
Marshall Clow8982dcd2015-07-13 20:04:56 +0000267 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200268 allocator_traits<allocator_type>::is_always_equal::value); // C++17, constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000269
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200270 const value_type* c_str() const noexcept; // constexpr since C++20
271 const value_type* data() const noexcept; // constexpr since C++20
272 value_type* data() noexcept; // C++17, constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000273
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200274 allocator_type get_allocator() const noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000275
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200276 size_type find(const basic_string& str, size_type pos = 0) const noexcept; // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000277 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200278 size_type find(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension, constexpr since C++20
279 size_type find(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20
280 size_type find(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20
281 size_type find(value_type c, size_type pos = 0) const noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000282
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200283 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept; // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000284 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200285 size_type rfind(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension, constexpr since C++20
286 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20
287 size_type rfind(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20
288 size_type rfind(value_type c, size_type pos = npos) const noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200290 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 +0000291 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200292 size_type find_first_of(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension, constexpr since C++20
293 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20
294 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20
295 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 +0000296
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200297 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 +0000298 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200299 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
300 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20
301 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20
302 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 +0000303
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200304 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 +0000305 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200306 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
307 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20
308 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20
309 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 +0000310
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200311 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 +0000312 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200313 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
314 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20
315 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20
316 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 +0000317
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200318 int compare(const basic_string& str) const noexcept; // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000319 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200320 int compare(const T& t) const noexcept; // C++17, noexcept as an extension, constexpr since C++20
321 int compare(size_type pos1, size_type n1, const basic_string& str) const; // constexpr since C++20
Marshall Clowe46031a2018-07-02 18:41:15 +0000322 template <class T>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200323 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 +0000324 int compare(size_type pos1, size_type n1, const basic_string& str,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200325 size_type pos2, size_type n2=npos) const; // C++14, constexpr since C++20
Marshall Clow82513342016-09-24 22:45:42 +0000326 template <class T>
327 int compare(size_type pos1, size_type n1, const T& t,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200328 size_type pos2, size_type n2=npos) const; // C++17, constexpr since C++20
329 int compare(const value_type* s) const noexcept; // constexpr since C++20
330 int compare(size_type pos1, size_type n1, const value_type* s) const; // constexpr since C++20
331 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 +0000332
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200333 constexpr bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++20
334 constexpr bool starts_with(charT c) const noexcept; // C++20
335 constexpr bool starts_with(const charT* s) const; // C++20
336 constexpr bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++20
337 constexpr bool ends_with(charT c) const noexcept; // C++20
338 constexpr bool ends_with(const charT* s) const; // C++20
Marshall Clow18c293b2017-12-04 20:11:38 +0000339
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200340 constexpr bool contains(basic_string_view<charT, traits> sv) const noexcept; // C++2b
341 constexpr bool contains(charT c) const noexcept; // C++2b
342 constexpr bool contains(const charT* s) const; // C++2b
Howard Hinnantc51e1022010-05-11 19:42:16 +0000343};
344
Marshall Clowa0563332018-02-08 06:34:03 +0000345template<class InputIterator,
346 class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
347basic_string(InputIterator, InputIterator, Allocator = Allocator())
348 -> basic_string<typename iterator_traits<InputIterator>::value_type,
349 char_traits<typename iterator_traits<InputIterator>::value_type>,
350 Allocator>; // C++17
351
Howard Hinnantc51e1022010-05-11 19:42:16 +0000352template<class charT, class traits, class Allocator>
353basic_string<charT, traits, Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000354operator+(const basic_string<charT, traits, Allocator>& lhs,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200355 const basic_string<charT, traits, Allocator>& rhs); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000356
357template<class charT, class traits, class Allocator>
358basic_string<charT, traits, Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200359operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000360
361template<class charT, class traits, class Allocator>
362basic_string<charT, traits, Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200363operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000364
365template<class charT, class traits, class Allocator>
366basic_string<charT, traits, Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200367operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000368
369template<class charT, class traits, class Allocator>
370basic_string<charT, traits, Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200371operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000372
373template<class charT, class traits, class Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000374bool operator==(const basic_string<charT, traits, Allocator>& lhs,
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200375 const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000376
377template<class charT, class traits, class Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +0200378bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000379
380template<class charT, class traits, class Allocator>
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200381bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept; // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000382
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000383template<class charT, class traits, class Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000384bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
Mark de Weveraf1968a2022-08-14 14:14:09 +0200385 const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000386
387template<class charT, class traits, class Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +0200388bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000389
390template<class charT, class traits, class Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +0200391bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000392
393template<class charT, class traits, class Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000394bool operator< (const basic_string<charT, traits, Allocator>& lhs,
Mark de Weveraf1968a2022-08-14 14:14:09 +0200395 const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000396
397template<class charT, class traits, class Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +0200398bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000399
400template<class charT, class traits, class Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +0200401bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000402
403template<class charT, class traits, class Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000404bool operator> (const basic_string<charT, traits, Allocator>& lhs,
Mark de Weveraf1968a2022-08-14 14:14:09 +0200405 const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000406
407template<class charT, class traits, class Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +0200408bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000409
410template<class charT, class traits, class Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +0200411bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000412
413template<class charT, class traits, class Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000414bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
Mark de Weveraf1968a2022-08-14 14:14:09 +0200415 const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000416
417template<class charT, class traits, class Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +0200418bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000419
420template<class charT, class traits, class Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +0200421bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000422
423template<class charT, class traits, class Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000424bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
Mark de Weveraf1968a2022-08-14 14:14:09 +0200425 const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000426
427template<class charT, class traits, class Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +0200428bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000429
430template<class charT, class traits, class Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +0200431bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20
Mark de Weverb4830e62022-07-19 07:56:23 +0200432
433template<class charT, class traits, class Allocator> // since C++20
434constexpr see below operator<=>(const basic_string<charT, traits, Allocator>& lhs,
435 const basic_string<charT, traits, Allocator>& rhs) noexcept;
436
437template<class charT, class traits, class Allocator> // since C++20
438constexpr see below operator<=>(const basic_string<charT, traits, Allocator>& lhs,
439 const charT* rhs) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000440
441template<class charT, class traits, class Allocator>
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000442void swap(basic_string<charT, traits, Allocator>& lhs,
Howard Hinnant3e276872011-06-03 18:40:47 +0000443 basic_string<charT, traits, Allocator>& rhs)
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200444 noexcept(noexcept(lhs.swap(rhs))); // constexpr since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000445
446template<class charT, class traits, class Allocator>
447basic_istream<charT, traits>&
448operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
449
450template<class charT, class traits, class Allocator>
451basic_ostream<charT, traits>&
452operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
453
454template<class charT, class traits, class Allocator>
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000455basic_istream<charT, traits>&
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000456getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
457 charT delim);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000458
459template<class charT, class traits, class Allocator>
460basic_istream<charT, traits>&
461getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
462
Marshall Clow29b53f22018-12-14 18:49:35 +0000463template<class charT, class traits, class Allocator, class U>
Marek Kurdeja98b1412020-05-02 13:58:03 +0200464typename basic_string<charT, traits, Allocator>::size_type
465erase(basic_string<charT, traits, Allocator>& c, const U& value); // C++20
Marshall Clow29b53f22018-12-14 18:49:35 +0000466template<class charT, class traits, class Allocator, class Predicate>
Marek Kurdeja98b1412020-05-02 13:58:03 +0200467typename basic_string<charT, traits, Allocator>::size_type
468erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); // C++20
Marshall Clow29b53f22018-12-14 18:49:35 +0000469
Howard Hinnantc51e1022010-05-11 19:42:16 +0000470typedef basic_string<char> string;
471typedef basic_string<wchar_t> wstring;
Marek Kurdeje3ac4e22021-03-23 17:15:07 +0100472typedef basic_string<char8_t> u8string; // C++20
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000473typedef basic_string<char16_t> u16string;
474typedef basic_string<char32_t> u32string;
475
Bruce Mitchener170d8972020-11-24 12:53:53 -0500476int stoi (const string& str, size_t* idx = nullptr, int base = 10);
477long stol (const string& str, size_t* idx = nullptr, int base = 10);
478unsigned long stoul (const string& str, size_t* idx = nullptr, int base = 10);
479long long stoll (const string& str, size_t* idx = nullptr, int base = 10);
480unsigned long long stoull(const string& str, size_t* idx = nullptr, int base = 10);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000481
Bruce Mitchener170d8972020-11-24 12:53:53 -0500482float stof (const string& str, size_t* idx = nullptr);
483double stod (const string& str, size_t* idx = nullptr);
484long double stold(const string& str, size_t* idx = nullptr);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000485
486string to_string(int val);
487string to_string(unsigned val);
488string to_string(long val);
489string to_string(unsigned long val);
490string to_string(long long val);
491string to_string(unsigned long long val);
492string to_string(float val);
493string to_string(double val);
494string to_string(long double val);
495
Bruce Mitchener170d8972020-11-24 12:53:53 -0500496int stoi (const wstring& str, size_t* idx = nullptr, int base = 10);
497long stol (const wstring& str, size_t* idx = nullptr, int base = 10);
498unsigned long stoul (const wstring& str, size_t* idx = nullptr, int base = 10);
499long long stoll (const wstring& str, size_t* idx = nullptr, int base = 10);
500unsigned long long stoull(const wstring& str, size_t* idx = nullptr, int base = 10);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000501
Bruce Mitchener170d8972020-11-24 12:53:53 -0500502float stof (const wstring& str, size_t* idx = nullptr);
503double stod (const wstring& str, size_t* idx = nullptr);
504long double stold(const wstring& str, size_t* idx = nullptr);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +0000505
506wstring to_wstring(int val);
507wstring to_wstring(unsigned val);
508wstring to_wstring(long val);
509wstring to_wstring(unsigned long val);
510wstring to_wstring(long long val);
511wstring to_wstring(unsigned long long val);
512wstring to_wstring(float val);
513wstring to_wstring(double val);
514wstring to_wstring(long double val);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000515
516template <> struct hash<string>;
Marek Kurdeje3ac4e22021-03-23 17:15:07 +0100517template <> struct hash<u8string>; // C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000518template <> struct hash<u16string>;
519template <> struct hash<u32string>;
520template <> struct hash<wstring>;
521
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200522basic_string<char> operator "" s( const char *str, size_t len ); // C++14, constexpr since C++20
523basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14, constexpr since C++20
524constexpr basic_string<char8_t> operator "" s( const char8_t *str, size_t len ); // C++20
525basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14, constexpr since C++20
526basic_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 +0000527
Howard Hinnantc51e1022010-05-11 19:42:16 +0000528} // std
529
530*/
531
Nikolas Klauserf210d8a2022-02-15 18:18:08 +0100532#include <__algorithm/max.h>
533#include <__algorithm/min.h>
534#include <__algorithm/remove.h>
535#include <__algorithm/remove_if.h>
Louis Dionneb4fce352022-03-25 12:55:36 -0400536#include <__assert> // all public C++ headers provide the assertion handler
Howard Hinnantc51e1022010-05-11 19:42:16 +0000537#include <__config>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400538#include <__debug>
Mark de Weverdf3e0d42021-09-26 15:47:42 +0200539#include <__format/enable_insertable.h>
Nikolas Klauser11a0ff32022-06-06 23:35:24 +0200540#include <__functional/hash.h>
Nikolas Klauser24540d32022-05-21 00:45:51 +0200541#include <__functional/unary_function.h>
Nikolas Klauser80840272022-02-04 13:04:33 +0100542#include <__ios/fpos.h>
Nikolas Klauserfb1b0672022-06-10 19:53:10 +0200543#include <__iterator/distance.h>
544#include <__iterator/iterator_traits.h>
545#include <__iterator/reverse_iterator.h>
Louis Dionne77249522021-06-11 09:55:11 -0400546#include <__iterator/wrap_iter.h>
Nikolas Klauserc513eba2022-04-09 09:41:19 +0200547#include <__memory/allocate_at_least.h>
Nikolas Klauser0b5df932022-09-05 00:01:15 +0200548#include <__memory/allocator.h>
549#include <__memory/allocator_traits.h>
550#include <__memory/compressed_pair.h>
551#include <__memory/construct_at.h>
552#include <__memory/pointer_traits.h>
Nikolas Klauser35080b42022-07-26 16:13:56 +0200553#include <__memory/swap_allocator.h>
Arthur O'Dwyerebf2d342022-10-06 16:53:30 -0400554#include <__memory_resource/polymorphic_allocator.h>
Nikolas Klauser11a0ff32022-06-06 23:35:24 +0200555#include <__string/char_traits.h>
556#include <__string/extern_template_lists.h>
Nikolas Klauser0b5df932022-09-05 00:01:15 +0200557#include <__type_traits/is_allocator.h>
558#include <__type_traits/noexcept_move_assign_container.h>
Nikolas Klauser8fccd622022-03-05 19:17:07 +0100559#include <__utility/auto_cast.h>
560#include <__utility/move.h>
561#include <__utility/swap.h>
Nikolas Klauser62060be2022-04-20 10:52:04 +0200562#include <__utility/unreachable.h>
563#include <climits>
Louis Dionne44962c32022-06-13 11:21:16 -0400564#include <cstdint>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400565#include <cstdio> // EOF
Louis Dionned24191c2021-08-19 12:39:16 -0400566#include <cstdlib>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400567#include <cstring>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400568#include <iosfwd>
Nikolas Klauser62060be2022-04-20 10:52:04 +0200569#include <limits>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000570#include <stdexcept>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400571#include <string_view>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000572#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000573#include <version>
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000574
Louis Dionne89258142021-08-23 15:32:36 -0400575#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Nikolas Klauser80840272022-02-04 13:04:33 +0100576# include <cwchar>
Louis Dionne89258142021-08-23 15:32:36 -0400577#endif
578
Nikolas Klausera0e0edb2022-06-16 22:43:46 +0200579// standard-mandated includes
580
581// [iterator.range]
582#include <__iterator/access.h>
583#include <__iterator/data.h>
584#include <__iterator/empty.h>
585#include <__iterator/reverse_access.h>
586#include <__iterator/size.h>
587
588// [string.syn]
589#include <compare>
590#include <initializer_list>
591
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000592#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Arthur O'Dwyer6eeaa002022-02-01 20:16:40 -0500593# pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000594#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000595
Eric Fiselierf4433a32017-05-31 22:07:49 +0000596_LIBCPP_PUSH_MACROS
597#include <__undef_macros>
598
599
Howard Hinnantc51e1022010-05-11 19:42:16 +0000600_LIBCPP_BEGIN_NAMESPACE_STD
601
Howard Hinnantc51e1022010-05-11 19:42:16 +0000602// basic_string
603
604template<class _CharT, class _Traits, class _Allocator>
605basic_string<_CharT, _Traits, _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +0200606_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnant944510a2011-06-14 19:58:17 +0000607operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
608 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000609
610template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +0200611_LIBCPP_HIDDEN _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000612basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant944510a2011-06-14 19:58:17 +0000613operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000614
615template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +0200616_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000617basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant944510a2011-06-14 19:58:17 +0000618operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000619
620template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +0200621inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000622basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant944510a2011-06-14 19:58:17 +0000623operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000624
625template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +0200626_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000627basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant944510a2011-06-14 19:58:17 +0000628operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000629
Louis Dionnedc496ec2021-06-08 17:25:08 -0400630extern template _LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&);
Shoaib Meenaiea363712017-07-29 02:54:41 +0000631
Marshall Clow039b2f02016-01-13 21:54:34 +0000632template <class _Iter>
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -0400633struct __string_is_trivial_iterator : public false_type {};
634
635template <class _Tp>
636struct __string_is_trivial_iterator<_Tp*>
637 : public is_arithmetic<_Tp> {};
Marshall Clow039b2f02016-01-13 21:54:34 +0000638
Louis Dionne173f29e2019-05-29 16:01:36 +0000639template <class _Iter>
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -0400640struct __string_is_trivial_iterator<__wrap_iter<_Iter> >
641 : public __string_is_trivial_iterator<_Iter> {};
Marshall Clow039b2f02016-01-13 21:54:34 +0000642
Marshall Clow82513342016-09-24 22:45:42 +0000643template <class _CharT, class _Traits, class _Tp>
Eric Fiselierc522ceb2020-01-15 16:57:08 -0500644struct __can_be_converted_to_string_view : public _BoolConstant<
645 is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
646 !is_convertible<const _Tp&, const _CharT*>::value
647 > {};
Marshall Clow82513342016-09-24 22:45:42 +0000648
Arthur O'Dwyerafa5d5f2021-04-18 21:47:08 -0400649#ifndef _LIBCPP_HAS_NO_CHAR8_T
Richard Smith256954d2020-11-11 17:12:18 -0800650typedef basic_string<char8_t> u8string;
651#endif
Richard Smith256954d2020-11-11 17:12:18 -0800652typedef basic_string<char16_t> u16string;
653typedef basic_string<char32_t> u32string;
Richard Smith256954d2020-11-11 17:12:18 -0800654
Nikolas Klauser55dc8082022-04-09 16:19:45 +0200655struct __uninitialized_size_tag {};
656
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000657template<class _CharT, class _Traits, class _Allocator>
Richard Smith256954d2020-11-11 17:12:18 -0800658class
659 _LIBCPP_TEMPLATE_VIS
Arthur O'Dwyerafa5d5f2021-04-18 21:47:08 -0400660#ifndef _LIBCPP_HAS_NO_CHAR8_T
Richard Smith256954d2020-11-11 17:12:18 -0800661 _LIBCPP_PREFERRED_NAME(u8string)
662#endif
Richard Smith256954d2020-11-11 17:12:18 -0800663 _LIBCPP_PREFERRED_NAME(u16string)
664 _LIBCPP_PREFERRED_NAME(u32string)
Richard Smith256954d2020-11-11 17:12:18 -0800665 basic_string
Howard Hinnantc51e1022010-05-11 19:42:16 +0000666{
667public:
668 typedef basic_string __self;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000669 typedef basic_string_view<_CharT, _Traits> __self_view;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000670 typedef _Traits traits_type;
Marshall Clowa3a74e02017-03-15 18:41:11 +0000671 typedef _CharT value_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000672 typedef _Allocator allocator_type;
Howard Hinnantea8f7e12010-11-17 17:55:08 +0000673 typedef allocator_traits<allocator_type> __alloc_traits;
674 typedef typename __alloc_traits::size_type size_type;
675 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant3e276872011-06-03 18:40:47 +0000676 typedef value_type& reference;
677 typedef const value_type& const_reference;
Howard Hinnantea8f7e12010-11-17 17:55:08 +0000678 typedef typename __alloc_traits::pointer pointer;
679 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000680
Marshall Clow79f33542018-03-21 00:36:05 +0000681 static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array");
682 static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout");
683 static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial");
684 static_assert(( is_same<_CharT, typename traits_type::char_type>::value),
Howard Hinnant8ea98242013-08-23 17:37:05 +0000685 "traits_type::char_type must be the same type as CharT");
Marshall Clow79f33542018-03-21 00:36:05 +0000686 static_assert(( is_same<typename allocator_type::value_type, value_type>::value),
Howard Hinnant8ea98242013-08-23 17:37:05 +0000687 "Allocator::value_type must be same type as value_type");
Marshall Clowe46031a2018-07-02 18:41:15 +0000688
Nikolas Klausereb116e22022-10-08 22:17:32 +0200689 static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value,
690 "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
691 "original allocator");
692
Howard Hinnantc51e1022010-05-11 19:42:16 +0000693 typedef __wrap_iter<pointer> iterator;
694 typedef __wrap_iter<const_pointer> const_iterator;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200695 typedef std::reverse_iterator<iterator> reverse_iterator;
696 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000697
698private:
Nikolas Klauser1aa21112022-05-14 12:38:00 +0200699 static_assert(CHAR_BIT == 8, "This implementation assumes that one byte contains 8 bits");
Howard Hinnant68bf1812013-04-30 21:44:48 +0000700
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +0000701#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant68bf1812013-04-30 21:44:48 +0000702
703 struct __long
704 {
705 pointer __data_;
706 size_type __size_;
Nikolas Klauser62060be2022-04-20 10:52:04 +0200707 size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1;
708 size_type __is_long_ : 1;
Howard Hinnant68bf1812013-04-30 21:44:48 +0000709 };
710
Howard Hinnant68bf1812013-04-30 21:44:48 +0000711 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
712 (sizeof(__long) - 1)/sizeof(value_type) : 2};
713
714 struct __short
715 {
716 value_type __data_[__min_cap];
Nikolas Klauser1aa21112022-05-14 12:38:00 +0200717 unsigned char __padding_[sizeof(value_type) - 1];
Nikolas Klauser95cfe622022-06-11 23:43:00 +0200718 unsigned char __size_ : 7;
719 unsigned char __is_long_ : 1;
Howard Hinnant68bf1812013-04-30 21:44:48 +0000720 };
721
Nikolas Klauser62060be2022-04-20 10:52:04 +0200722// The __endian_factor is required because the field we use to store the size
Nikolas Klauser1aa21112022-05-14 12:38:00 +0200723// has one fewer bit than it would if it were not a bitfield.
Nikolas Klauser62060be2022-04-20 10:52:04 +0200724//
725// If the LSB is used to store the short-flag in the short string representation,
726// we have to multiply the size by two when it is stored and divide it by two when
727// it is loaded to make sure that we always store an even number. In the long string
728// representation, we can ignore this because we can assume that we always allocate
729// an even amount of value_types.
730//
731// If the MSB is used for the short-flag, the max_size() is numeric_limits<size_type>::max() / 2.
732// This does not impact the short string representation, since we never need the MSB
733// for representing the size of a short string anyway.
734
735#ifdef _LIBCPP_BIG_ENDIAN
736 static const size_type __endian_factor = 2;
Howard Hinnant68bf1812013-04-30 21:44:48 +0000737#else
Nikolas Klauser62060be2022-04-20 10:52:04 +0200738 static const size_type __endian_factor = 1;
739#endif
740
741#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
742
743#ifdef _LIBCPP_BIG_ENDIAN
744 static const size_type __endian_factor = 1;
745#else
746 static const size_type __endian_factor = 2;
747#endif
Howard Hinnant68bf1812013-04-30 21:44:48 +0000748
Xing Xue38b9fc42022-06-24 17:25:15 -0400749 // Attribute 'packed' is used to keep the layout compatible with the
750 // previous definition that did not use bit fields. This is because on
751 // some platforms bit fields have a default size rather than the actual
752 // size used, e.g., it is 4 bytes on AIX. See D128285 for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +0000753 struct __long
754 {
Xing Xue38b9fc42022-06-24 17:25:15 -0400755 struct _LIBCPP_PACKED {
756 size_type __is_long_ : 1;
757 size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1;
758 };
Howard Hinnantc51e1022010-05-11 19:42:16 +0000759 size_type __size_;
760 pointer __data_;
761 };
762
Howard Hinnantc51e1022010-05-11 19:42:16 +0000763 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
764 (sizeof(__long) - 1)/sizeof(value_type) : 2};
765
766 struct __short
767 {
Xing Xue38b9fc42022-06-24 17:25:15 -0400768 struct _LIBCPP_PACKED {
769 unsigned char __is_long_ : 1;
770 unsigned char __size_ : 7;
771 };
Nikolas Klauser1aa21112022-05-14 12:38:00 +0200772 char __padding_[sizeof(value_type) - 1];
Howard Hinnantc51e1022010-05-11 19:42:16 +0000773 value_type __data_[__min_cap];
774 };
775
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400776#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant68bf1812013-04-30 21:44:48 +0000777
Nikolas Klauser95cfe622022-06-11 23:43:00 +0200778 static_assert(sizeof(__short) == (sizeof(value_type) * (__min_cap + 1)), "__short has an unexpected size.");
779
Howard Hinnant8ea98242013-08-23 17:37:05 +0000780 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000781
Howard Hinnant8ea98242013-08-23 17:37:05 +0000782 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantc51e1022010-05-11 19:42:16 +0000783
784 struct __raw
785 {
786 size_type __words[__n_words];
787 };
788
789 struct __rep
790 {
791 union
792 {
793 __long __l;
794 __short __s;
795 __raw __r;
796 };
797 };
798
799 __compressed_pair<__rep, allocator_type> __r_;
800
Nikolas Klauser55dc8082022-04-09 16:19:45 +0200801 // Construct a string with the given allocator and enough storage to hold `__size` characters, but
802 // don't initialize the characters. The contents of the string, including the null terminator, must be
803 // initialized separately.
Nikolas Klauser8b1c5062022-08-19 13:08:01 +0200804 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200805 explicit basic_string(__uninitialized_size_tag, size_type __size, const allocator_type& __a)
Nikolas Klauser55dc8082022-04-09 16:19:45 +0200806 : __r_(__default_init_tag(), __a) {
807 if (__size > max_size())
808 __throw_length_error();
809 if (__fits_in_sso(__size)) {
Nikolas Klauser8577eec2022-08-30 17:43:14 +0200810 __r_.first() = __rep();
Nikolas Klauser55dc8082022-04-09 16:19:45 +0200811 __set_short_size(__size);
812 } else {
813 auto __capacity = __recommend(__size) + 1;
814 auto __allocation = __alloc_traits::allocate(__alloc(), __capacity);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200815 __begin_lifetime(__allocation, __capacity);
Nikolas Klauser55dc8082022-04-09 16:19:45 +0200816 __set_long_cap(__capacity);
817 __set_long_pointer(__allocation);
818 __set_long_size(__size);
819 }
820 std::__debug_db_insert_c(this);
821 }
822
Howard Hinnantc51e1022010-05-11 19:42:16 +0000823public:
Nikolas Klauserd128f2b2022-08-26 18:35:25 +0200824 _LIBCPP_TEMPLATE_DATA_VIS static const size_type npos = -1;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000825
Nikolas Klauserd128f2b2022-08-26 18:35:25 +0200826 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string()
827 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
828 : __r_(__default_init_tag(), __default_init_tag()) {
829 std::__debug_db_insert_c(this);
830 __default_init();
831 }
Marshall Clowa80abc72015-06-03 19:56:43 +0000832
Nikolas Klauserd128f2b2022-08-26 18:35:25 +0200833 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string(const allocator_type& __a)
Marshall Clowa80abc72015-06-03 19:56:43 +0000834#if _LIBCPP_STD_VER <= 14
Nikolas Klauserd128f2b2022-08-26 18:35:25 +0200835 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
Marshall Clowa80abc72015-06-03 19:56:43 +0000836#else
Nikolas Klauserd128f2b2022-08-26 18:35:25 +0200837 _NOEXCEPT
Marshall Clowa80abc72015-06-03 19:56:43 +0000838#endif
Nikolas Klauserd128f2b2022-08-26 18:35:25 +0200839 : __r_(__default_init_tag(), __a) {
840 std::__debug_db_insert_c(this);
841 __default_init();
842 }
Marshall Clowa80abc72015-06-03 19:56:43 +0000843
Nikolas Klauserd128f2b2022-08-26 18:35:25 +0200844 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const basic_string& __str);
845 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const basic_string& __str, const allocator_type& __a);
Marshall Clowa80abc72015-06-03 19:56:43 +0000846
Eric Fiselierfc92be82017-04-19 00:28:44 +0000847#ifndef _LIBCPP_CXX03_LANG
Nikolas Klauserd128f2b2022-08-26 18:35:25 +0200848 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(basic_string&& __str)
849# if _LIBCPP_STD_VER <= 14
850 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
851# else
852 _NOEXCEPT
853# endif
854 : __r_(std::move(__str.__r_)) {
855 __str.__default_init();
856 std::__debug_db_insert_c(this);
857 if (__is_long())
858 std::__debug_db_swap(this, &__str);
859 }
Marshall Clowa80abc72015-06-03 19:56:43 +0000860
Nikolas Klauserd128f2b2022-08-26 18:35:25 +0200861 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(basic_string&& __str, const allocator_type& __a)
862 : __r_(__default_init_tag(), __a) {
863 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
864 __init(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size());
865 else {
866 if (__libcpp_is_constant_evaluated())
867 __r_.first() = __rep();
868 __r_.first() = __str.__r_.first();
869 __str.__default_init();
870 }
871 std::__debug_db_insert_c(this);
872 if (__is_long())
873 std::__debug_db_swap(this, &__str);
874 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400875#endif // _LIBCPP_CXX03_LANG
Marshall Clowe46031a2018-07-02 18:41:15 +0000876
Nikolas Klauserd128f2b2022-08-26 18:35:25 +0200877 template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> >
878 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s)
879 : __r_(__default_init_tag(), __default_init_tag()) {
880 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
881 __init(__s, traits_type::length(__s));
882 std::__debug_db_insert_c(this);
883 }
Marshall Clowe46031a2018-07-02 18:41:15 +0000884
Nikolas Klauserd128f2b2022-08-26 18:35:25 +0200885 template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> >
886 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, const _Allocator& __a);
Marshall Clowe46031a2018-07-02 18:41:15 +0000887
Marek Kurdej90d79712021-07-27 16:16:21 +0200888#if _LIBCPP_STD_VER > 20
Nikolas Klauserd128f2b2022-08-26 18:35:25 +0200889 basic_string(nullptr_t) = delete;
Marek Kurdej90d79712021-07-27 16:16:21 +0200890#endif
891
Nikolas Klauserd128f2b2022-08-26 18:35:25 +0200892 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, size_type __n)
893 : __r_(__default_init_tag(), __default_init_tag()) {
894 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
895 __init(__s, __n);
896 std::__debug_db_insert_c(this);
897 }
Marshall Clowe46031a2018-07-02 18:41:15 +0000898
Nikolas Klauserd128f2b2022-08-26 18:35:25 +0200899 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
900 basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
901 : __r_(__default_init_tag(), __a) {
902 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
903 __init(__s, __n);
904 std::__debug_db_insert_c(this);
905 }
Marshall Clowe46031a2018-07-02 18:41:15 +0000906
Nikolas Klauserd128f2b2022-08-26 18:35:25 +0200907 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(size_type __n, _CharT __c)
908 : __r_(__default_init_tag(), __default_init_tag()) {
909 __init(__n, __c);
910 std::__debug_db_insert_c(this);
911 }
Marshall Clowe46031a2018-07-02 18:41:15 +0000912
Nikolas Klauserd128f2b2022-08-26 18:35:25 +0200913 template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> >
914 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(size_type __n, _CharT __c, const _Allocator& __a);
Marshall Clowe46031a2018-07-02 18:41:15 +0000915
Nikolas Klauserd128f2b2022-08-26 18:35:25 +0200916 _LIBCPP_CONSTEXPR_SINCE_CXX20
917 basic_string(const basic_string& __str, size_type __pos, size_type __n, const _Allocator& __a = _Allocator());
Marshall Clowe46031a2018-07-02 18:41:15 +0000918
Nikolas Klauserd128f2b2022-08-26 18:35:25 +0200919 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
920 basic_string(const basic_string& __str, size_type __pos, const _Allocator& __a = _Allocator())
921 : __r_(__default_init_tag(), __a) {
922 size_type __str_sz = __str.size();
923 if (__pos > __str_sz)
924 __throw_out_of_range();
925 __init(__str.data() + __pos, __str_sz - __pos);
926 std::__debug_db_insert_c(this);
927 }
Marshall Clowe46031a2018-07-02 18:41:15 +0000928
Nikolas Klauserd128f2b2022-08-26 18:35:25 +0200929 template <class _Tp,
930 class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
931 !__is_same_uncvref<_Tp, basic_string>::value> >
932 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
933 basic_string(const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a = allocator_type());
934
935 template <class _Tp,
936 class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
937 !__is_same_uncvref<_Tp, basic_string>::value> >
938 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string(
939 const _Tp& __t);
940
941 template <class _Tp,
942 class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
943 !__is_same_uncvref<_Tp, basic_string>::value> >
944 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string(
945 const _Tp& __t, const allocator_type& __a);
946
947 template <class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> >
948 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(_InputIterator __first, _InputIterator __last)
949 : __r_(__default_init_tag(), __default_init_tag()) {
950 __init(__first, __last);
951 std::__debug_db_insert_c(this);
952 }
953
954 template <class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> >
955 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
956 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a)
957 : __r_(__default_init_tag(), __a) {
958 __init(__first, __last);
959 std::__debug_db_insert_c(this);
960 }
961
Eric Fiselierfc92be82017-04-19 00:28:44 +0000962#ifndef _LIBCPP_CXX03_LANG
Nikolas Klauserd128f2b2022-08-26 18:35:25 +0200963 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(initializer_list<_CharT> __il)
964 : __r_(__default_init_tag(), __default_init_tag()) {
965 __init(__il.begin(), __il.end());
966 std::__debug_db_insert_c(this);
967 }
968
969 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(initializer_list<_CharT> __il, const _Allocator& __a)
970 : __r_(__default_init_tag(), __a) {
971 __init(__il.begin(), __il.end());
972 std::__debug_db_insert_c(this);
973 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400974#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +0000975
Nikolas Klauser8b1c5062022-08-19 13:08:01 +0200976 inline _LIBCPP_CONSTEXPR_SINCE_CXX20 ~basic_string();
Howard Hinnantc51e1022010-05-11 19:42:16 +0000977
Nikolas Klauser8b1c5062022-08-19 13:08:01 +0200978 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000979 operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
980
Nikolas Klauser8b1c5062022-08-19 13:08:01 +0200981 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(const basic_string& __str);
Eric Fiselier5ec13b12017-01-23 21:24:58 +0000982
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200983 template <class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value &&
984 !__is_same_uncvref<_Tp, basic_string>::value> >
Nikolas Klauser8b1c5062022-08-19 13:08:01 +0200985 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(const _Tp& __t) {
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200986 __self_view __sv = __t;
987 return assign(__sv);
988 }
Marshall Clowe46031a2018-07-02 18:41:15 +0000989
Eric Fiselierfc92be82017-04-19 00:28:44 +0000990#ifndef _LIBCPP_CXX03_LANG
Nikolas Klauser8b1c5062022-08-19 13:08:01 +0200991 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnant3e276872011-06-03 18:40:47 +0000992 basic_string& operator=(basic_string&& __str)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +0000993 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Nikolas Klauser8b1c5062022-08-19 13:08:01 +0200994 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Eric Fiselierfc92be82017-04-19 00:28:44 +0000995 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnantc51e1022010-05-11 19:42:16 +0000996#endif
Nikolas Klauser8b1c5062022-08-19 13:08:01 +0200997 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Nikolas Klauser80b3cf32022-04-27 10:11:44 +0200998 basic_string& operator=(const value_type* __s) {return assign(__s);}
Marek Kurdej90d79712021-07-27 16:16:21 +0200999#if _LIBCPP_STD_VER > 20
1000 basic_string& operator=(nullptr_t) = delete;
1001#endif
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001002 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(value_type __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001003
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001004 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnant8ea98242013-08-23 17:37:05 +00001005 iterator begin() _NOEXCEPT
1006 {return iterator(this, __get_pointer());}
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001007 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnant8ea98242013-08-23 17:37:05 +00001008 const_iterator begin() const _NOEXCEPT
1009 {return const_iterator(this, __get_pointer());}
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001010 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnant8ea98242013-08-23 17:37:05 +00001011 iterator end() _NOEXCEPT
1012 {return iterator(this, __get_pointer() + size());}
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001013 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnant8ea98242013-08-23 17:37:05 +00001014 const_iterator end() const _NOEXCEPT
1015 {return const_iterator(this, __get_pointer() + size());}
Louis Dionnee554e102022-06-03 15:17:03 -04001016
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001017 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001018 reverse_iterator rbegin() _NOEXCEPT
1019 {return reverse_iterator(end());}
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001020 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001021 const_reverse_iterator rbegin() const _NOEXCEPT
1022 {return const_reverse_iterator(end());}
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001023 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001024 reverse_iterator rend() _NOEXCEPT
1025 {return reverse_iterator(begin());}
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001026 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001027 const_reverse_iterator rend() const _NOEXCEPT
1028 {return const_reverse_iterator(begin());}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001029
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001030 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001031 const_iterator cbegin() const _NOEXCEPT
1032 {return begin();}
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001033 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001034 const_iterator cend() const _NOEXCEPT
1035 {return end();}
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001036 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001037 const_reverse_iterator crbegin() const _NOEXCEPT
1038 {return rbegin();}
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001039 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001040 const_reverse_iterator crend() const _NOEXCEPT
1041 {return rend();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001042
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001043 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type size() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001044 {return __is_long() ? __get_long_size() : __get_short_size();}
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001045 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type length() const _NOEXCEPT {return size();}
1046 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type max_size() const _NOEXCEPT;
1047 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type capacity() const _NOEXCEPT {
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001048 return (__is_long() ? __get_long_cap() : static_cast<size_type>(__min_cap)) - 1;
1049 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001051 _LIBCPP_CONSTEXPR_SINCE_CXX20 void resize(size_type __n, value_type __c);
1052 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void resize(size_type __n) { resize(__n, value_type()); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001053
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001054 _LIBCPP_CONSTEXPR_SINCE_CXX20 void reserve(size_type __requested_capacity);
Nikolas Klauser9e6040c2022-01-06 21:43:26 +01001055
1056#if _LIBCPP_STD_VER > 20
1057 template <class _Op>
1058 _LIBCPP_HIDE_FROM_ABI constexpr
1059 void resize_and_overwrite(size_type __n, _Op __op) {
1060 __resize_default_init(__n);
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02001061 __erase_to_end(std::move(__op)(data(), _LIBCPP_AUTO_CAST(__n)));
Nikolas Klauser9e6040c2022-01-06 21:43:26 +01001062 }
1063#endif
1064
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001065 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __resize_default_init(size_type __n);
Eric Fiselier451d5582018-11-26 20:15:38 +00001066
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02001067 _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI void reserve() _NOEXCEPT { shrink_to_fit(); }
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001068 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void shrink_to_fit() _NOEXCEPT;
1069 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void clear() _NOEXCEPT;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001070
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001071 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Marshall Clowb7db4972017-11-15 20:02:27 +00001072 bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001073
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001074 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001075 const_reference operator[](size_type __pos) const _NOEXCEPT;
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001076 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator[](size_type __pos) _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001077
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001078 _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference at(size_type __n) const;
1079 _LIBCPP_CONSTEXPR_SINCE_CXX20 reference at(size_type __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001080
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001081 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator+=(const basic_string& __str) {
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001082 return append(__str);
1083 }
Marshall Clowe46031a2018-07-02 18:41:15 +00001084
1085 template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001086 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001087 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001088 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001089 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1090 && !__is_same_uncvref<_Tp, basic_string >::value,
Marshall Clowe46031a2018-07-02 18:41:15 +00001091 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001092 >
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001093 operator+=(const _Tp& __t) {
1094 __self_view __sv = __t; return append(__sv);
1095 }
1096
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001097 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator+=(const value_type* __s) {
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001098 return append(__s);
1099 }
1100
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001101 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator+=(value_type __c) {
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001102 push_back(__c);
1103 return *this;
1104 }
1105
Eric Fiselierfc92be82017-04-19 00:28:44 +00001106#ifndef _LIBCPP_CXX03_LANG
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001107 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001108 basic_string& operator+=(initializer_list<value_type> __il) { return append(__il); }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001109#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001110
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001111 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001112 basic_string& append(const basic_string& __str);
Marshall Clowe46031a2018-07-02 18:41:15 +00001113
1114 template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001115 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001116 __enable_if_t<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001117 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1118 && !__is_same_uncvref<_Tp, basic_string>::value,
Marshall Clowe46031a2018-07-02 18:41:15 +00001119 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001120 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001121 append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); }
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001122 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clowe46031a2018-07-02 18:41:15 +00001123
Marshall Clow62953962016-10-03 23:40:48 +00001124 template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001125 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001126 __enable_if_t
Marshall Clow82513342016-09-24 22:45:42 +00001127 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001128 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1129 && !__is_same_uncvref<_Tp, basic_string>::value,
Marshall Clow82513342016-09-24 22:45:42 +00001130 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001131 >
Marshall Clow82513342016-09-24 22:45:42 +00001132 append(const _Tp& __t, size_type __pos, size_type __n=npos);
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001133 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const value_type* __s, size_type __n);
1134 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const value_type* __s);
1135 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(size_type __n, value_type __c);
Eric Fiselier451d5582018-11-26 20:15:38 +00001136
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001137 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Eric Fiselier451d5582018-11-26 20:15:38 +00001138 void __append_default_init(size_type __n);
1139
Howard Hinnantc51e1022010-05-11 19:42:16 +00001140 template<class _InputIterator>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001141 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Louis Dionne9ce598d2021-09-08 09:14:43 -04001142 __enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00001143 <
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04001144 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001145 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001146 >
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001147 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +00001148 append(_InputIterator __first, _InputIterator __last) {
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04001149 const basic_string __temp(__first, __last, __alloc());
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +00001150 append(__temp.data(), __temp.size());
1151 return *this;
1152 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001153 template<class _ForwardIterator>
Shoaib Meenai69c57412017-03-02 03:02:50 +00001154 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
Louis Dionne9ce598d2021-09-08 09:14:43 -04001155 __enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00001156 <
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04001157 __is_cpp17_forward_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001158 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001159 >
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001160 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04001161 append(_ForwardIterator __first, _ForwardIterator __last);
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +00001162
Eric Fiselierfc92be82017-04-19 00:28:44 +00001163#ifndef _LIBCPP_CXX03_LANG
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001164 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001165 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001166#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001167
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001168 _LIBCPP_CONSTEXPR_SINCE_CXX20 void push_back(value_type __c);
1169 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void pop_back();
1170 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference front() _NOEXCEPT;
1171 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference front() const _NOEXCEPT;
1172 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference back() _NOEXCEPT;
1173 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference back() const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001174
Marshall Clowe46031a2018-07-02 18:41:15 +00001175 template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001176 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001177 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001178 <
1179 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1180 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001181 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001182 assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); }
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001183 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Marshall Clow95d5e9a2016-03-09 18:08:29 +00001184 basic_string& assign(const basic_string& __str) { return *this = __str; }
Eric Fiselierfc92be82017-04-19 00:28:44 +00001185#ifndef _LIBCPP_CXX03_LANG
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001186 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001187 basic_string& assign(basic_string&& __str)
Marshall Clow5aa9e942015-10-05 16:17:34 +00001188 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02001189 {*this = std::move(__str); return *this;}
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001190#endif
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001191 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow62953962016-10-03 23:40:48 +00001192 template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001193 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001194 __enable_if_t
Marshall Clow82513342016-09-24 22:45:42 +00001195 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001196 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
1197 && !__is_same_uncvref<_Tp, basic_string>::value,
Marshall Clow82513342016-09-24 22:45:42 +00001198 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001199 >
Eric Fiselierc5ea1ae2017-06-01 02:29:37 +00001200 assign(const _Tp & __t, size_type __pos, size_type __n=npos);
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001201 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(const value_type* __s, size_type __n);
1202 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(const value_type* __s);
1203 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(size_type __n, value_type __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001204 template<class _InputIterator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001205 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001206 __enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00001207 <
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04001208 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001209 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001210 >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001211 assign(_InputIterator __first, _InputIterator __last);
1212 template<class _ForwardIterator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001213 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001214 __enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00001215 <
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04001216 __is_cpp17_forward_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001217 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001218 >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001219 assign(_ForwardIterator __first, _ForwardIterator __last);
Eric Fiselierfc92be82017-04-19 00:28:44 +00001220#ifndef _LIBCPP_CXX03_LANG
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001221 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001222 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001223#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001224
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001225 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001226 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clowe46031a2018-07-02 18:41:15 +00001227
1228 template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001229 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001230 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001231 <
1232 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1233 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001234 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001235 insert(size_type __pos1, const _Tp& __t)
1236 { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); }
1237
Marshall Clow82513342016-09-24 22:45:42 +00001238 template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001239 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001240 __enable_if_t
Marshall Clow82513342016-09-24 22:45:42 +00001241 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001242 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
Marshall Clow82513342016-09-24 22:45:42 +00001243 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001244 >
Marshall Clow82513342016-09-24 22:45:42 +00001245 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001246 _LIBCPP_CONSTEXPR_SINCE_CXX20
Marshall Clow8db7fb02014-03-04 19:17:19 +00001247 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001248 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1249 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, const value_type* __s);
1250 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1251 _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __pos, value_type __c);
1252 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001253 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1254 template<class _InputIterator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001255 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001256 __enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00001257 <
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04001258 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001259 iterator
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001260 >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001261 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1262 template<class _ForwardIterator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001263 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001264 __enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00001265 <
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04001266 __is_cpp17_forward_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001267 iterator
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001268 >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001269 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Eric Fiselierfc92be82017-04-19 00:28:44 +00001270#ifndef _LIBCPP_CXX03_LANG
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001271 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001272 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1273 {return insert(__pos, __il.begin(), __il.end());}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001274#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001275
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001276 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& erase(size_type __pos = 0, size_type __n = npos);
1277 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001278 iterator erase(const_iterator __pos);
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001279 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001280 iterator erase(const_iterator __first, const_iterator __last);
1281
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001282 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001283 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clowe46031a2018-07-02 18:41:15 +00001284
1285 template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001286 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001287 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001288 <
1289 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1290 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001291 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001292 replace(size_type __pos1, size_type __n1, const _Tp& __t) { __self_view __sv = __t; return replace(__pos1, __n1, __sv.data(), __sv.size()); }
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001293 _LIBCPP_CONSTEXPR_SINCE_CXX20
Marshall Clow8db7fb02014-03-04 19:17:19 +00001294 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 +00001295 template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001296 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001297 __enable_if_t
Marshall Clow82513342016-09-24 22:45:42 +00001298 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001299 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
Marshall Clow82513342016-09-24 22:45:42 +00001300 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001301 >
Marshall Clow82513342016-09-24 22:45:42 +00001302 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001303 _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantd17880b2013-06-28 16:59:19 +00001304 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001305 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
1306 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
1307 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnant990d6e82010-11-17 21:11:40 +00001308 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Marshall Clowe46031a2018-07-02 18:41:15 +00001309
1310 template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001311 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001312 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001313 <
1314 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1315 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001316 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001317 replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); }
1318
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001319 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantd17880b2013-06-28 16:59:19 +00001320 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001321 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantd17880b2013-06-28 16:59:19 +00001322 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001323 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnant990d6e82010-11-17 21:11:40 +00001324 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001325 template<class _InputIterator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001326 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001327 __enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00001328 <
Eric Fiseliercd5a6772019-11-18 01:46:58 -05001329 __is_cpp17_input_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001330 basic_string&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001331 >
Howard Hinnant990d6e82010-11-17 21:11:40 +00001332 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Eric Fiselierfc92be82017-04-19 00:28:44 +00001333#ifndef _LIBCPP_CXX03_LANG
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001334 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnant990d6e82010-11-17 21:11:40 +00001335 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001336 {return replace(__i1, __i2, __il.begin(), __il.end());}
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001337#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001338
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001339 _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
1340 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001341 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1342
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001343 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnant3e276872011-06-03 18:40:47 +00001344 void swap(basic_string& __str)
Marshall Clow8982dcd2015-07-13 20:04:56 +00001345#if _LIBCPP_STD_VER >= 14
Eric Fiselier873b8d32019-03-18 21:50:12 +00001346 _NOEXCEPT;
Marshall Clow8982dcd2015-07-13 20:04:56 +00001347#else
Eric Fiselier873b8d32019-03-18 21:50:12 +00001348 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow8982dcd2015-07-13 20:04:56 +00001349 __is_nothrow_swappable<allocator_type>::value);
1350#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001351
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001352 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantd17880b2013-06-28 16:59:19 +00001353 const value_type* c_str() const _NOEXCEPT {return data();}
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001354 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02001355 const value_type* data() const _NOEXCEPT {return std::__to_address(__get_pointer());}
Eric Fiselier4ee2a892017-11-20 20:23:27 +00001356#if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY)
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001357 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02001358 value_type* data() _NOEXCEPT {return std::__to_address(__get_pointer());}
Marshall Clowd3c22392016-03-08 15:44:30 +00001359#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001360
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001361 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001362 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001363
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001364 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001365 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001366
1367 template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001368 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001369 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001370 <
1371 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1372 size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001373 >
zoecarver1997e0a2021-02-05 11:54:47 -08001374 find(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT;
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001375 _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantd17880b2013-06-28 16:59:19 +00001376 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001377 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantd17880b2013-06-28 16:59:19 +00001378 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001379 _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001380
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001381 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001382 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001383
1384 template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001385 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001386 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001387 <
1388 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1389 size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001390 >
zoecarver1997e0a2021-02-05 11:54:47 -08001391 rfind(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT;
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001392 _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantd17880b2013-06-28 16:59:19 +00001393 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001394 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantd17880b2013-06-28 16:59:19 +00001395 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001396 _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001397
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001398 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001399 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001400
1401 template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001402 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001403 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001404 <
1405 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1406 size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001407 >
zoecarver1997e0a2021-02-05 11:54:47 -08001408 find_first_of(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT;
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001409 _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantd17880b2013-06-28 16:59:19 +00001410 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001411 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantd17880b2013-06-28 16:59:19 +00001412 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001413 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001414 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001415
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001416 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001417 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001418
1419 template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001420 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001421 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001422 <
1423 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1424 size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001425 >
zoecarver1997e0a2021-02-05 11:54:47 -08001426 find_last_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT;
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001427 _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantd17880b2013-06-28 16:59:19 +00001428 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001429 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantd17880b2013-06-28 16:59:19 +00001430 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001431 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001432 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001433
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001434 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001435 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001436
1437 template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001438 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001439 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001440 <
1441 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1442 size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001443 >
zoecarver1997e0a2021-02-05 11:54:47 -08001444 find_first_not_of(const _Tp &__t, size_type __pos = 0) const _NOEXCEPT;
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001445 _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantd17880b2013-06-28 16:59:19 +00001446 size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001447 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantd17880b2013-06-28 16:59:19 +00001448 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001449 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001450 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1451
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001452 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001453 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001454
1455 template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001456 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001457 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001458 <
1459 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1460 size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001461 >
zoecarver1997e0a2021-02-05 11:54:47 -08001462 find_last_not_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT;
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001463 _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantd17880b2013-06-28 16:59:19 +00001464 size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001465 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantd17880b2013-06-28 16:59:19 +00001466 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001467 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001468 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1469
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001470 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001471 int compare(const basic_string& __str) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001472
1473 template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001474 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001475 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001476 <
1477 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1478 int
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001479 >
zoecarver1997e0a2021-02-05 11:54:47 -08001480 compare(const _Tp &__t) const _NOEXCEPT;
Marshall Clowe46031a2018-07-02 18:41:15 +00001481
1482 template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001483 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001484 __enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00001485 <
1486 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1487 int
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001488 >
Marshall Clowe46031a2018-07-02 18:41:15 +00001489 compare(size_type __pos1, size_type __n1, const _Tp& __t) const;
1490
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001491 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001492 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001493 _LIBCPP_CONSTEXPR_SINCE_CXX20
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001494 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2,
1495 size_type __n2 = npos) const;
Marshall Clowe46031a2018-07-02 18:41:15 +00001496
Marshall Clow82513342016-09-24 22:45:42 +00001497 template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001498 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001499 __enable_if_t
Marshall Clow82513342016-09-24 22:45:42 +00001500 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001501 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value,
Marshall Clow82513342016-09-24 22:45:42 +00001502 int
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001503 >
Marshall Clow82513342016-09-24 22:45:42 +00001504 compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const;
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001505 _LIBCPP_CONSTEXPR_SINCE_CXX20 int compare(const value_type* __s) const _NOEXCEPT;
1506 _LIBCPP_CONSTEXPR_SINCE_CXX20 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1507 _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantd17880b2013-06-28 16:59:19 +00001508 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001509
Marshall Clow18c293b2017-12-04 20:11:38 +00001510#if _LIBCPP_STD_VER > 17
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02001511 constexpr _LIBCPP_HIDE_FROM_ABI
Arthur O'Dwyera0cb1e82021-09-28 12:19:35 -04001512 bool starts_with(__self_view __sv) const noexcept
Marshall Clow18c293b2017-12-04 20:11:38 +00001513 { return __self_view(data(), size()).starts_with(__sv); }
1514
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02001515 constexpr _LIBCPP_HIDE_FROM_ABI
Arthur O'Dwyera0cb1e82021-09-28 12:19:35 -04001516 bool starts_with(value_type __c) const noexcept
Marshall Clow18c293b2017-12-04 20:11:38 +00001517 { return !empty() && _Traits::eq(front(), __c); }
1518
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02001519 constexpr _LIBCPP_HIDE_FROM_ABI
Arthur O'Dwyera0cb1e82021-09-28 12:19:35 -04001520 bool starts_with(const value_type* __s) const noexcept
Marshall Clow18c293b2017-12-04 20:11:38 +00001521 { return starts_with(__self_view(__s)); }
1522
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02001523 constexpr _LIBCPP_HIDE_FROM_ABI
Arthur O'Dwyera0cb1e82021-09-28 12:19:35 -04001524 bool ends_with(__self_view __sv) const noexcept
Marshall Clow18c293b2017-12-04 20:11:38 +00001525 { return __self_view(data(), size()).ends_with( __sv); }
1526
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02001527 constexpr _LIBCPP_HIDE_FROM_ABI
Arthur O'Dwyera0cb1e82021-09-28 12:19:35 -04001528 bool ends_with(value_type __c) const noexcept
Marshall Clow18c293b2017-12-04 20:11:38 +00001529 { return !empty() && _Traits::eq(back(), __c); }
1530
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02001531 constexpr _LIBCPP_HIDE_FROM_ABI
Arthur O'Dwyera0cb1e82021-09-28 12:19:35 -04001532 bool ends_with(const value_type* __s) const noexcept
Marshall Clow18c293b2017-12-04 20:11:38 +00001533 { return ends_with(__self_view(__s)); }
1534#endif
1535
Wim Leflere023c3542021-01-19 14:33:30 -05001536#if _LIBCPP_STD_VER > 20
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02001537 constexpr _LIBCPP_HIDE_FROM_ABI
Wim Leflere023c3542021-01-19 14:33:30 -05001538 bool contains(__self_view __sv) const noexcept
1539 { return __self_view(data(), size()).contains(__sv); }
1540
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02001541 constexpr _LIBCPP_HIDE_FROM_ABI
Wim Leflere023c3542021-01-19 14:33:30 -05001542 bool contains(value_type __c) const noexcept
1543 { return __self_view(data(), size()).contains(__c); }
1544
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02001545 constexpr _LIBCPP_HIDE_FROM_ABI
Wim Leflere023c3542021-01-19 14:33:30 -05001546 bool contains(const value_type* __s) const
1547 { return __self_view(data(), size()).contains(__s); }
1548#endif
1549
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001550 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __invariants() const;
Howard Hinnantaaeb1132013-04-22 23:55:13 +00001551
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001552 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __clear_and_shrink() _NOEXCEPT;
Howard Hinnantaaeb1132013-04-22 23:55:13 +00001553
Louis Dionne510450b2022-04-01 16:38:30 -04001554#ifdef _LIBCPP_ENABLE_DEBUG_MODE
Howard Hinnant8ea98242013-08-23 17:37:05 +00001555
1556 bool __dereferenceable(const const_iterator* __i) const;
1557 bool __decrementable(const const_iterator* __i) const;
1558 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1559 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1560
Louis Dionne510450b2022-04-01 16:38:30 -04001561#endif // _LIBCPP_ENABLE_DEBUG_MODE
Howard Hinnant8ea98242013-08-23 17:37:05 +00001562
Howard Hinnantc51e1022010-05-11 19:42:16 +00001563private:
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001564 template<class _Alloc>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001565 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001566 bool friend operator==(const basic_string<char, char_traits<char>, _Alloc>& __lhs,
1567 const basic_string<char, char_traits<char>, _Alloc>& __rhs) _NOEXCEPT;
1568
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001569 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __shrink_or_extend(size_type __target_capacity);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001570
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001571 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001572 bool __is_long() const _NOEXCEPT {
1573 if (__libcpp_is_constant_evaluated())
1574 return true;
1575 return __r_.first().__s.__is_long_;
1576 }
1577
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001578 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __begin_lifetime(pointer __begin, size_type __n) {
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001579#if _LIBCPP_STD_VER > 17
1580 if (__libcpp_is_constant_evaluated()) {
1581 for (size_type __i = 0; __i != __n; ++__i)
1582 std::construct_at(std::addressof(__begin[__i]));
1583 }
1584#else
1585 (void)__begin;
1586 (void)__n;
1587#endif // _LIBCPP_STD_VER > 17
1588 }
1589
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001590 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __default_init() {
Nikolas Klauser8577eec2022-08-30 17:43:14 +02001591 __r_.first() = __rep();
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001592 if (__libcpp_is_constant_evaluated()) {
1593 size_type __sz = __recommend(0) + 1;
1594 pointer __ptr = __alloc_traits::allocate(__alloc(), __sz);
1595 __begin_lifetime(__ptr, __sz);
1596 __set_long_pointer(__ptr);
1597 __set_long_cap(__sz);
1598 __set_long_size(0);
1599 }
1600 }
1601
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001602 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __deallocate_constexpr() {
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001603 if (__libcpp_is_constant_evaluated() && __get_pointer() != nullptr)
1604 __alloc_traits::deallocate(__alloc(), __get_pointer(), __get_long_cap());
1605 }
1606
Nikolas Klauser93826d12022-01-04 17:24:03 +01001607 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI static bool __fits_in_sso(size_type __sz) {
1608 // SSO is disabled during constant evaluation because `__is_long` isn't constexpr friendly
1609 return !__libcpp_is_constant_evaluated() && (__sz < __min_cap);
1610 }
1611
Nikolas Klauser48d680d2022-02-26 13:28:33 +01001612 template <class _ForwardIterator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001613 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14
Nikolas Klauser48d680d2022-02-26 13:28:33 +01001614 iterator __insert_from_safe_copy(size_type __n, size_type __ip, _ForwardIterator __first, _ForwardIterator __last) {
1615 size_type __sz = size();
1616 size_type __cap = capacity();
1617 value_type* __p;
1618 if (__cap - __sz >= __n)
1619 {
1620 __p = std::__to_address(__get_pointer());
1621 size_type __n_move = __sz - __ip;
1622 if (__n_move != 0)
1623 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
1624 }
1625 else
1626 {
1627 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
1628 __p = std::__to_address(__get_long_pointer());
1629 }
1630 __sz += __n;
1631 __set_size(__sz);
1632 traits_type::assign(__p[__sz], value_type());
1633 for (__p += __ip; __first != __last; ++__p, ++__first)
1634 traits_type::assign(*__p, *__first);
1635
1636 return begin() + __ip;
1637 }
1638
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001639 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 allocator_type& __alloc() _NOEXCEPT { return __r_.second(); }
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001640 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const allocator_type& __alloc() const _NOEXCEPT { return __r_.second(); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001641
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001642 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Nikolas Klauser62060be2022-04-20 10:52:04 +02001643 void __set_short_size(size_type __s) _NOEXCEPT {
1644 _LIBCPP_ASSERT(__s < __min_cap, "__s should never be greater than or equal to the short string capacity");
1645 __r_.first().__s.__size_ = __s;
1646 __r_.first().__s.__is_long_ = false;
1647 }
Howard Hinnant68bf1812013-04-30 21:44:48 +00001648
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001649 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Nikolas Klauser62060be2022-04-20 10:52:04 +02001650 size_type __get_short_size() const _NOEXCEPT {
1651 _LIBCPP_ASSERT(!__r_.first().__s.__is_long_, "String has to be short when trying to get the short size");
1652 return __r_.first().__s.__size_;
1653 }
Howard Hinnant68bf1812013-04-30 21:44:48 +00001654
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001655 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001656 void __set_long_size(size_type __s) _NOEXCEPT
1657 {__r_.first().__l.__size_ = __s;}
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001658 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001659 size_type __get_long_size() const _NOEXCEPT
1660 {return __r_.first().__l.__size_;}
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001661 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001662 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001663 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1664
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001665 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Nikolas Klauser62060be2022-04-20 10:52:04 +02001666 void __set_long_cap(size_type __s) _NOEXCEPT {
1667 __r_.first().__l.__cap_ = __s / __endian_factor;
1668 __r_.first().__l.__is_long_ = true;
1669 }
1670
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001671 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Nikolas Klauser62060be2022-04-20 10:52:04 +02001672 size_type __get_long_cap() const _NOEXCEPT {
1673 return __r_.first().__l.__cap_ * __endian_factor;
1674 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001675
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001676 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001677 void __set_long_pointer(pointer __p) _NOEXCEPT
1678 {__r_.first().__l.__data_ = __p;}
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001679 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001680 pointer __get_long_pointer() _NOEXCEPT
1681 {return __r_.first().__l.__data_;}
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001682 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001683 const_pointer __get_long_pointer() const _NOEXCEPT
1684 {return __r_.first().__l.__data_;}
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001685 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001686 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnantd17880b2013-06-28 16:59:19 +00001687 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001688 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001689 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnantd17880b2013-06-28 16:59:19 +00001690 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001691 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001692 pointer __get_pointer() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001693 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001694 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001695 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001696 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1697
Howard Hinnantc51e1022010-05-11 19:42:16 +00001698 template <size_type __a> static
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001699 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantea382952013-08-14 18:00:20 +00001700 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiselier8599fcc2015-08-28 07:02:42 +00001701 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001702 enum {__alignment = 16};
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001703 static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantaeb17d82011-05-29 19:57:12 +00001704 size_type __recommend(size_type __s) _NOEXCEPT
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001705 {
1706 if (__s < __min_cap) {
1707 if (__libcpp_is_constant_evaluated())
1708 return static_cast<size_type>(__min_cap);
1709 else
1710 return static_cast<size_type>(__min_cap) - 1;
1711 }
Marshall Clow80584522018-02-07 21:30:17 +00001712 size_type __guess = __align_it<sizeof(value_type) < __alignment ?
1713 __alignment/sizeof(value_type) : 1 > (__s+1) - 1;
1714 if (__guess == __min_cap) ++__guess;
1715 return __guess;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001716 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001717
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001718 inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantd17880b2013-06-28 16:59:19 +00001719 void __init(const value_type* __s, size_type __sz, size_type __reserve);
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001720 inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantd17880b2013-06-28 16:59:19 +00001721 void __init(const value_type* __s, size_type __sz);
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001722 inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001723 void __init(size_type __n, value_type __c);
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001724
Martijn Vels5e7c9752020-03-04 17:52:46 -05001725 // Slow path for the (inlined) copy constructor for 'long' strings.
1726 // Always externally instantiated and not inlined.
1727 // Requires that __s is zero terminated.
1728 // The main reason for this function to exist is because for unstable, we
1729 // want to allow inlining of the copy constructor. However, we don't want
1730 // to call the __init() functions as those are marked as inline which may
1731 // result in over-aggressive inlining by the compiler, where our aim is
1732 // to only inline the fast path code directly in the ctor.
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001733 _LIBCPP_CONSTEXPR_SINCE_CXX20 void __init_copy_ctor_external(const value_type* __s, size_type __sz);
Martijn Vels5e7c9752020-03-04 17:52:46 -05001734
Howard Hinnantc51e1022010-05-11 19:42:16 +00001735 template <class _InputIterator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001736 inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001737 __enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00001738 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001739 __is_exactly_cpp17_input_iterator<_InputIterator>::value
1740 >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001741 __init(_InputIterator __first, _InputIterator __last);
1742
1743 template <class _ForwardIterator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001744 inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04001745 __enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00001746 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05001747 __is_cpp17_forward_iterator<_ForwardIterator>::value
1748 >
Howard Hinnantc51e1022010-05-11 19:42:16 +00001749 __init(_ForwardIterator __first, _ForwardIterator __last);
1750
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001751 _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001752 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001753 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001754 _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001755 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1756 size_type __n_copy, size_type __n_del,
Howard Hinnantd17880b2013-06-28 16:59:19 +00001757 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001758
Martijn Vels596e3de2020-02-26 15:55:49 -05001759 // __assign_no_alias is invoked for assignment operations where we
1760 // have proof that the input does not alias the current instance.
1761 // For example, operator=(basic_string) performs a 'self' check.
1762 template <bool __is_short>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001763 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& __assign_no_alias(const value_type* __s, size_type __n);
Martijn Vels596e3de2020-02-26 15:55:49 -05001764
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001765 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001766 void __erase_to_end(size_type __pos);
1767
Martijn Velsa81fc792020-02-26 13:25:43 -05001768 // __erase_external_with_move is invoked for erase() invocations where
1769 // `n ~= npos`, likely requiring memory moves on the string data.
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001770 _LIBCPP_CONSTEXPR_SINCE_CXX20 void __erase_external_with_move(size_type __pos, size_type __n);
Martijn Velsa81fc792020-02-26 13:25:43 -05001771
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001772 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001773 void __copy_assign_alloc(const basic_string& __str)
1774 {__copy_assign_alloc(__str, integral_constant<bool,
1775 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1776
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001777 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001778 void __copy_assign_alloc(const basic_string& __str, true_type)
1779 {
Marshall Clowf258c202017-01-31 03:40:52 +00001780 if (__alloc() == __str.__alloc())
1781 __alloc() = __str.__alloc();
1782 else
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001783 {
Marshall Clowf258c202017-01-31 03:40:52 +00001784 if (!__str.__is_long())
1785 {
Vedant Kumar55e007e2018-03-08 21:15:26 +00001786 __clear_and_shrink();
Marshall Clowf258c202017-01-31 03:40:52 +00001787 __alloc() = __str.__alloc();
1788 }
1789 else
1790 {
1791 allocator_type __a = __str.__alloc();
Nikolas Klauserc513eba2022-04-09 09:41:19 +02001792 auto __allocation = std::__allocate_at_least(__a, __str.__get_long_cap());
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001793 __begin_lifetime(__allocation.ptr, __allocation.count);
Nikolas Klauser1821ec32022-10-01 15:37:24 +02001794 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02001795 __alloc() = std::move(__a);
Nikolas Klauserc513eba2022-04-09 09:41:19 +02001796 __set_long_pointer(__allocation.ptr);
1797 __set_long_cap(__allocation.count);
Marshall Clowf258c202017-01-31 03:40:52 +00001798 __set_long_size(__str.size());
1799 }
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001800 }
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001801 }
1802
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001803 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnant28b24882011-12-01 20:21:04 +00001804 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001805 {}
1806
Eric Fiselierfc92be82017-04-19 00:28:44 +00001807#ifndef _LIBCPP_CXX03_LANG
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001808 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00001809 void __move_assign(basic_string& __str, false_type)
1810 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001811 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnant3e276872011-06-03 18:40:47 +00001812 void __move_assign(basic_string& __str, true_type)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00001813#if _LIBCPP_STD_VER > 14
1814 _NOEXCEPT;
1815#else
Howard Hinnant3e276872011-06-03 18:40:47 +00001816 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001817#endif
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00001818#endif
Howard Hinnantea8f7e12010-11-17 17:55:08 +00001819
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001820 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnant58fe91b2011-08-17 20:36:18 +00001821 void
Howard Hinnantc2734962011-09-02 20:42:31 +00001822 __move_assign_alloc(basic_string& __str)
Howard Hinnant58fe91b2011-08-17 20:36:18 +00001823 _NOEXCEPT_(
1824 !__alloc_traits::propagate_on_container_move_assignment::value ||
1825 is_nothrow_move_assignable<allocator_type>::value)
1826 {__move_assign_alloc(__str, integral_constant<bool,
1827 __alloc_traits::propagate_on_container_move_assignment::value>());}
1828
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001829 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc2734962011-09-02 20:42:31 +00001830 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant58fe91b2011-08-17 20:36:18 +00001831 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1832 {
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02001833 __alloc() = std::move(__c.__alloc());
Howard Hinnant58fe91b2011-08-17 20:36:18 +00001834 }
1835
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001836 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnant28b24882011-12-01 20:21:04 +00001837 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant58fe91b2011-08-17 20:36:18 +00001838 _NOEXCEPT
1839 {}
1840
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001841 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& __assign_external(const value_type* __s);
1842 _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& __assign_external(const value_type* __s, size_type __n);
Martijn Velsda7d94f2020-06-19 14:24:03 -04001843
1844 // Assigns the value in __s, guaranteed to be __n < __min_cap in length.
1845 inline basic_string& __assign_short(const value_type* __s, size_type __n) {
1846 pointer __p = __is_long()
1847 ? (__set_long_size(__n), __get_long_pointer())
1848 : (__set_short_size(__n), __get_short_pointer());
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02001849 traits_type::move(std::__to_address(__p), __s, __n);
Martijn Velsda7d94f2020-06-19 14:24:03 -04001850 traits_type::assign(__p[__n], value_type());
1851 return *this;
1852 }
1853
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001854 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001855 basic_string& __null_terminate_at(value_type* __p, size_type __newsz) {
Nikolas Klauser3ec7fb22021-12-14 01:20:53 +01001856 __set_size(__newsz);
1857 __invalidate_iterators_past(__newsz);
1858 traits_type::assign(__p[__newsz], value_type());
1859 return *this;
1860 }
1861
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001862 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __invalidate_iterators_past(size_type);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001863
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04001864 template<class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001865 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04001866 bool __addr_in_range(_Tp&& __t) const {
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001867 // assume that the ranges overlap, because we can't check during constant evaluation
1868 if (__libcpp_is_constant_evaluated())
1869 return true;
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02001870 const volatile void *__p = std::addressof(__t);
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04001871 return data() <= __p && __p <= data() + size();
1872 }
1873
Louis Dionned24191c2021-08-19 12:39:16 -04001874 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
1875 void __throw_length_error() const {
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02001876 std::__throw_length_error("basic_string");
Louis Dionned24191c2021-08-19 12:39:16 -04001877 }
1878
1879 _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
1880 void __throw_out_of_range() const {
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02001881 std::__throw_out_of_range("basic_string");
Louis Dionned24191c2021-08-19 12:39:16 -04001882 }
1883
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001884 friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(const basic_string&, const basic_string&);
1885 friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(const value_type*, const basic_string&);
1886 friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(value_type, const basic_string&);
1887 friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(const basic_string&, const value_type*);
1888 friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(const basic_string&, value_type);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001889};
1890
Eric Fiselier2ed640b2020-03-04 13:54:04 -05001891// These declarations must appear before any functions are implicitly used
1892// so that they have the correct visibility specifier.
Louis Dionnedc496ec2021-06-08 17:25:08 -04001893#define _LIBCPP_DECLARE(...) extern template __VA_ARGS__;
Eric Fiselier2ed640b2020-03-04 13:54:04 -05001894#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
Louis Dionnedc496ec2021-06-08 17:25:08 -04001895 _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, char)
Louis Dionne89258142021-08-23 15:32:36 -04001896# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Louis Dionnedc496ec2021-06-08 17:25:08 -04001897 _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, wchar_t)
Louis Dionne89258142021-08-23 15:32:36 -04001898# endif
Eric Fiselier2ed640b2020-03-04 13:54:04 -05001899#else
Louis Dionnedc496ec2021-06-08 17:25:08 -04001900 _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, char)
Louis Dionne89258142021-08-23 15:32:36 -04001901# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Louis Dionnedc496ec2021-06-08 17:25:08 -04001902 _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, wchar_t)
Louis Dionne89258142021-08-23 15:32:36 -04001903# endif
Eric Fiselier2ed640b2020-03-04 13:54:04 -05001904#endif
Louis Dionnedc496ec2021-06-08 17:25:08 -04001905#undef _LIBCPP_DECLARE
Eric Fiselier2ed640b2020-03-04 13:54:04 -05001906
1907
Louis Dionned59f8a52021-08-17 11:59:07 -04001908#if _LIBCPP_STD_VER >= 17
Marshall Clowa0563332018-02-08 06:34:03 +00001909template<class _InputIterator,
Arthur O'Dwyer56226762021-03-03 23:02:20 -05001910 class _CharT = __iter_value_type<_InputIterator>,
Marshall Clowa0563332018-02-08 06:34:03 +00001911 class _Allocator = allocator<_CharT>,
Louis Dionne25547162021-08-17 12:26:09 -04001912 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
1913 class = enable_if_t<__is_allocator<_Allocator>::value>
Marshall Clowa0563332018-02-08 06:34:03 +00001914 >
1915basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
1916 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
Marshall Clowe46031a2018-07-02 18:41:15 +00001917
1918template<class _CharT,
1919 class _Traits,
1920 class _Allocator = allocator<_CharT>,
Louis Dionne25547162021-08-17 12:26:09 -04001921 class = enable_if_t<__is_allocator<_Allocator>::value>
Marshall Clowe46031a2018-07-02 18:41:15 +00001922 >
1923explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
1924 -> basic_string<_CharT, _Traits, _Allocator>;
1925
1926template<class _CharT,
1927 class _Traits,
1928 class _Allocator = allocator<_CharT>,
Louis Dionne25547162021-08-17 12:26:09 -04001929 class = enable_if_t<__is_allocator<_Allocator>::value>,
Marshall Clowe46031a2018-07-02 18:41:15 +00001930 class _Sz = typename allocator_traits<_Allocator>::size_type
1931 >
1932basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator())
1933 -> basic_string<_CharT, _Traits, _Allocator>;
Marshall Clowa0563332018-02-08 06:34:03 +00001934#endif
1935
Howard Hinnantc51e1022010-05-11 19:42:16 +00001936template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001937inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001938void
Arthur O'Dwyerb3db4542021-04-27 09:10:04 -04001939basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001940{
Louis Dionne510450b2022-04-01 16:38:30 -04001941#ifdef _LIBCPP_ENABLE_DEBUG_MODE
Nikolas Klauser1a7d9f02021-12-16 14:55:03 +01001942 if (!__libcpp_is_constant_evaluated()) {
1943 __c_node* __c = __get_db()->__find_c_and_lock(this);
1944 if (__c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001945 {
Nikolas Klauser1a7d9f02021-12-16 14:55:03 +01001946 const_pointer __new_last = __get_pointer() + __pos;
1947 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantc51e1022010-05-11 19:42:16 +00001948 {
Nikolas Klauser1a7d9f02021-12-16 14:55:03 +01001949 --__p;
1950 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1951 if (__i->base() > __new_last)
1952 {
1953 (*__p)->__c_ = nullptr;
1954 if (--__c->end_ != __p)
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02001955 std::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Nikolas Klauser1a7d9f02021-12-16 14:55:03 +01001956 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001957 }
Nikolas Klauser1a7d9f02021-12-16 14:55:03 +01001958 __get_db()->unlock();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001959 }
1960 }
Arthur O'Dwyerb3db4542021-04-27 09:10:04 -04001961#else
1962 (void)__pos;
Louis Dionne510450b2022-04-01 16:38:30 -04001963#endif // _LIBCPP_ENABLE_DEBUG_MODE
Howard Hinnantc51e1022010-05-11 19:42:16 +00001964}
1965
1966template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001967_LIBCPP_CONSTEXPR_SINCE_CXX20
Eric Fiselier815ed732016-09-16 00:00:48 +00001968void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1969 size_type __sz,
1970 size_type __reserve)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001971{
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001972 if (__libcpp_is_constant_evaluated())
Nikolas Klauser8577eec2022-08-30 17:43:14 +02001973 __r_.first() = __rep();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001974 if (__reserve > max_size())
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01001975 __throw_length_error();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001976 pointer __p;
Nikolas Klauser93826d12022-01-04 17:24:03 +01001977 if (__fits_in_sso(__reserve))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001978 {
1979 __set_short_size(__sz);
1980 __p = __get_short_pointer();
1981 }
1982 else
1983 {
Nikolas Klauserc513eba2022-04-09 09:41:19 +02001984 auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__reserve) + 1);
1985 __p = __allocation.ptr;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02001986 __begin_lifetime(__p, __allocation.count);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001987 __set_long_pointer(__p);
Nikolas Klauserc513eba2022-04-09 09:41:19 +02001988 __set_long_cap(__allocation.count);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001989 __set_long_size(__sz);
1990 }
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02001991 traits_type::copy(std::__to_address(__p), __s, __sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001992 traits_type::assign(__p[__sz], value_type());
1993}
1994
1995template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02001996_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00001997void
Howard Hinnantd17880b2013-06-28 16:59:19 +00001998basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001999{
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002000 if (__libcpp_is_constant_evaluated())
Nikolas Klauser8577eec2022-08-30 17:43:14 +02002001 __r_.first() = __rep();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002002 if (__sz > max_size())
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002003 __throw_length_error();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002004 pointer __p;
Nikolas Klauser93826d12022-01-04 17:24:03 +01002005 if (__fits_in_sso(__sz))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002006 {
2007 __set_short_size(__sz);
2008 __p = __get_short_pointer();
2009 }
2010 else
2011 {
Nikolas Klauserc513eba2022-04-09 09:41:19 +02002012 auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1);
2013 __p = __allocation.ptr;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002014 __begin_lifetime(__p, __allocation.count);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002015 __set_long_pointer(__p);
Nikolas Klauserc513eba2022-04-09 09:41:19 +02002016 __set_long_cap(__allocation.count);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002017 __set_long_size(__sz);
2018 }
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002019 traits_type::copy(std::__to_address(__p), __s, __sz);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002020 traits_type::assign(__p[__sz], value_type());
2021}
2022
2023template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00002024template <class>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002025_LIBCPP_CONSTEXPR_SINCE_CXX20
Eric Fiselier812882b2017-02-17 01:17:10 +00002026basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002027 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002028{
Howard Hinnant8ea98242013-08-23 17:37:05 +00002029 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002030 __init(__s, traits_type::length(__s));
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002031 std::__debug_db_insert_c(this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002032}
2033
2034template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002035_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002036basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002037 : __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002038{
2039 if (!__str.__is_long())
Nikolas Klauser8577eec2022-08-30 17:43:14 +02002040 __r_.first() = __str.__r_.first();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002041 else
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002042 __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()),
Martijn Vels5e7c9752020-03-04 17:52:46 -05002043 __str.__get_long_size());
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002044 std::__debug_db_insert_c(this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002045}
2046
2047template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002048_LIBCPP_CONSTEXPR_SINCE_CXX20
Eric Fiselier812882b2017-02-17 01:17:10 +00002049basic_string<_CharT, _Traits, _Allocator>::basic_string(
2050 const basic_string& __str, const allocator_type& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002051 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002052{
2053 if (!__str.__is_long())
Nikolas Klauser8577eec2022-08-30 17:43:14 +02002054 __r_.first() = __str.__r_.first();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002055 else
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002056 __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()),
Martijn Vels5e7c9752020-03-04 17:52:46 -05002057 __str.__get_long_size());
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002058 std::__debug_db_insert_c(this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002059}
2060
Martijn Vels5e7c9752020-03-04 17:52:46 -05002061template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002062_LIBCPP_CONSTEXPR_SINCE_CXX20
Martijn Vels5e7c9752020-03-04 17:52:46 -05002063void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(
2064 const value_type* __s, size_type __sz) {
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002065 if (__libcpp_is_constant_evaluated())
Nikolas Klauser8577eec2022-08-30 17:43:14 +02002066 __r_.first() = __rep();
2067
Martijn Vels5e7c9752020-03-04 17:52:46 -05002068 pointer __p;
Nikolas Klauser93826d12022-01-04 17:24:03 +01002069 if (__fits_in_sso(__sz)) {
Martijn Vels5e7c9752020-03-04 17:52:46 -05002070 __p = __get_short_pointer();
2071 __set_short_size(__sz);
2072 } else {
2073 if (__sz > max_size())
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002074 __throw_length_error();
Nikolas Klauserc513eba2022-04-09 09:41:19 +02002075 auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1);
2076 __p = __allocation.ptr;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002077 __begin_lifetime(__p, __allocation.count);
Martijn Vels5e7c9752020-03-04 17:52:46 -05002078 __set_long_pointer(__p);
Nikolas Klauserc513eba2022-04-09 09:41:19 +02002079 __set_long_cap(__allocation.count);
Martijn Vels5e7c9752020-03-04 17:52:46 -05002080 __set_long_size(__sz);
2081 }
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002082 traits_type::copy(std::__to_address(__p), __s, __sz + 1);
Martijn Vels5e7c9752020-03-04 17:52:46 -05002083}
2084
Howard Hinnantc51e1022010-05-11 19:42:16 +00002085template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002086_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002087void
2088basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
2089{
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002090 if (__libcpp_is_constant_evaluated())
Nikolas Klauser8577eec2022-08-30 17:43:14 +02002091 __r_.first() = __rep();
2092
Howard Hinnantc51e1022010-05-11 19:42:16 +00002093 if (__n > max_size())
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002094 __throw_length_error();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002095 pointer __p;
Nikolas Klauser93826d12022-01-04 17:24:03 +01002096 if (__fits_in_sso(__n))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002097 {
2098 __set_short_size(__n);
2099 __p = __get_short_pointer();
2100 }
2101 else
2102 {
Nikolas Klauserc513eba2022-04-09 09:41:19 +02002103 auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__n) + 1);
2104 __p = __allocation.ptr;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002105 __begin_lifetime(__p, __allocation.count);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002106 __set_long_pointer(__p);
Nikolas Klauserc513eba2022-04-09 09:41:19 +02002107 __set_long_cap(__allocation.count);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002108 __set_long_size(__n);
2109 }
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002110 traits_type::assign(std::__to_address(__p), __n, __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002111 traits_type::assign(__p[__n], value_type());
2112}
2113
2114template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00002115template <class>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002116_LIBCPP_CONSTEXPR_SINCE_CXX20
Eric Fiselier812882b2017-02-17 01:17:10 +00002117basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002118 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002119{
2120 __init(__n, __c);
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002121 std::__debug_db_insert_c(this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002122}
2123
Howard Hinnantc51e1022010-05-11 19:42:16 +00002124template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002125_LIBCPP_CONSTEXPR_SINCE_CXX20
Eric Fiselier812882b2017-02-17 01:17:10 +00002126basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
2127 size_type __pos, size_type __n,
2128 const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002129 : __r_(__default_init_tag(), __a)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002130{
2131 size_type __str_sz = __str.size();
2132 if (__pos > __str_sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002133 __throw_out_of_range();
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002134 __init(__str.data() + __pos, std::min(__n, __str_sz - __pos));
2135 std::__debug_db_insert_c(this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002136}
2137
2138template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00002139template <class _Tp, class>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002140_LIBCPP_CONSTEXPR_SINCE_CXX20
Marshall Clow78dbe462016-11-14 18:22:19 +00002141basic_string<_CharT, _Traits, _Allocator>::basic_string(
Marshall Clowe46031a2018-07-02 18:41:15 +00002142 const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002143 : __r_(__default_init_tag(), __a)
Marshall Clow78dbe462016-11-14 18:22:19 +00002144{
Marshall Clowe46031a2018-07-02 18:41:15 +00002145 __self_view __sv0 = __t;
2146 __self_view __sv = __sv0.substr(__pos, __n);
Marshall Clow78dbe462016-11-14 18:22:19 +00002147 __init(__sv.data(), __sv.size());
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002148 std::__debug_db_insert_c(this);
Marshall Clow78dbe462016-11-14 18:22:19 +00002149}
2150
2151template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00002152template <class _Tp, class>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002153_LIBCPP_CONSTEXPR_SINCE_CXX20
Marshall Clowe46031a2018-07-02 18:41:15 +00002154basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002155 : __r_(__default_init_tag(), __default_init_tag())
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002156{
Marshall Clowe46031a2018-07-02 18:41:15 +00002157 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002158 __init(__sv.data(), __sv.size());
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002159 std::__debug_db_insert_c(this);
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002160}
2161
2162template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00002163template <class _Tp, class>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002164_LIBCPP_CONSTEXPR_SINCE_CXX20
Marshall Clowe46031a2018-07-02 18:41:15 +00002165basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a)
Eric Fiselier5169d1c2019-12-16 19:03:23 -05002166 : __r_(__default_init_tag(), __a)
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002167{
Marshall Clowe46031a2018-07-02 18:41:15 +00002168 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002169 __init(__sv.data(), __sv.size());
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002170 std::__debug_db_insert_c(this);
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002171}
2172
2173template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002174template <class _InputIterator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002175_LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04002176__enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00002177<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002178 __is_exactly_cpp17_input_iterator<_InputIterator>::value
2179>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002180basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2181{
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002182 __default_init();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002183#ifndef _LIBCPP_NO_EXCEPTIONS
2184 try
2185 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002186#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002187 for (; __first != __last; ++__first)
2188 push_back(*__first);
2189#ifndef _LIBCPP_NO_EXCEPTIONS
2190 }
2191 catch (...)
2192 {
2193 if (__is_long())
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002194 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002195 throw;
2196 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002197#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002198}
2199
2200template <class _CharT, class _Traits, class _Allocator>
2201template <class _ForwardIterator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002202_LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04002203__enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00002204<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002205 __is_cpp17_forward_iterator<_ForwardIterator>::value
2206>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002207basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2208{
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002209 if (__libcpp_is_constant_evaluated())
Nikolas Klauser8577eec2022-08-30 17:43:14 +02002210 __r_.first() = __rep();
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002211 size_type __sz = static_cast<size_type>(std::distance(__first, __last));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002212 if (__sz > max_size())
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002213 __throw_length_error();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002214 pointer __p;
Nikolas Klauser93826d12022-01-04 17:24:03 +01002215 if (__fits_in_sso(__sz))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002216 {
2217 __set_short_size(__sz);
2218 __p = __get_short_pointer();
2219 }
2220 else
2221 {
Nikolas Klauserc513eba2022-04-09 09:41:19 +02002222 auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1);
2223 __p = __allocation.ptr;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002224 __begin_lifetime(__p, __allocation.count);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002225 __set_long_pointer(__p);
Nikolas Klauserc513eba2022-04-09 09:41:19 +02002226 __set_long_cap(__allocation.count);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002227 __set_long_size(__sz);
2228 }
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002229
2230#ifndef _LIBCPP_NO_EXCEPTIONS
2231 try
2232 {
2233#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiseliera09a3b42014-10-27 19:28:20 +00002234 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002235 traits_type::assign(*__p, *__first);
2236 traits_type::assign(*__p, value_type());
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002237#ifndef _LIBCPP_NO_EXCEPTIONS
2238 }
2239 catch (...)
2240 {
2241 if (__is_long())
2242 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
2243 throw;
2244 }
2245#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002246}
2247
2248template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002249_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002250basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2251{
Nikolas Klauser98833542022-05-07 22:20:23 +02002252 std::__debug_db_erase_c(this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002253 if (__is_long())
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002254 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002255}
2256
2257template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002258_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002259void
2260basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2261 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnantd17880b2013-06-28 16:59:19 +00002262 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 +00002263{
2264 size_type __ms = max_size();
2265 if (__delta_cap > __ms - __old_cap - 1)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002266 __throw_length_error();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002267 pointer __old_p = __get_pointer();
2268 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002269 __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantc51e1022010-05-11 19:42:16 +00002270 __ms - 1;
Nikolas Klauserc513eba2022-04-09 09:41:19 +02002271 auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1);
2272 pointer __p = __allocation.ptr;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002273 __begin_lifetime(__p, __allocation.count);
Nikolas Klauserf1d286b2022-05-08 16:40:04 +02002274 std::__debug_db_invalidate_all(this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002275 if (__n_copy != 0)
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002276 traits_type::copy(std::__to_address(__p),
2277 std::__to_address(__old_p), __n_copy);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002278 if (__n_add != 0)
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002279 traits_type::copy(std::__to_address(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002280 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2281 if (__sec_cp_sz != 0)
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002282 traits_type::copy(std::__to_address(__p) + __n_copy + __n_add,
2283 std::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002284 if (__old_cap+1 != __min_cap || __libcpp_is_constant_evaluated())
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002285 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002286 __set_long_pointer(__p);
Nikolas Klauserc513eba2022-04-09 09:41:19 +02002287 __set_long_cap(__allocation.count);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002288 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2289 __set_long_size(__old_sz);
2290 traits_type::assign(__p[__old_sz], value_type());
2291}
2292
2293template <class _CharT, class _Traits, class _Allocator>
2294void
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002295_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002296basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2297 size_type __n_copy, size_type __n_del, size_type __n_add)
2298{
2299 size_type __ms = max_size();
Marshall Clow2267c5d2013-11-06 14:24:38 +00002300 if (__delta_cap > __ms - __old_cap)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002301 __throw_length_error();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002302 pointer __old_p = __get_pointer();
2303 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002304 __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantc51e1022010-05-11 19:42:16 +00002305 __ms - 1;
Nikolas Klauserc513eba2022-04-09 09:41:19 +02002306 auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1);
2307 pointer __p = __allocation.ptr;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002308 __begin_lifetime(__p, __allocation.count);
Nikolas Klauserf1d286b2022-05-08 16:40:04 +02002309 std::__debug_db_invalidate_all(this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002310 if (__n_copy != 0)
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002311 traits_type::copy(std::__to_address(__p),
2312 std::__to_address(__old_p), __n_copy);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002313 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2314 if (__sec_cp_sz != 0)
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002315 traits_type::copy(std::__to_address(__p) + __n_copy + __n_add,
2316 std::__to_address(__old_p) + __n_copy + __n_del,
Howard Hinnantd17880b2013-06-28 16:59:19 +00002317 __sec_cp_sz);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002318 if (__libcpp_is_constant_evaluated() || __old_cap + 1 != __min_cap)
2319 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap + 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002320 __set_long_pointer(__p);
Nikolas Klauserc513eba2022-04-09 09:41:19 +02002321 __set_long_cap(__allocation.count);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002322}
2323
2324// assign
2325
2326template <class _CharT, class _Traits, class _Allocator>
Martijn Vels596e3de2020-02-26 15:55:49 -05002327template <bool __is_short>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002328_LIBCPP_CONSTEXPR_SINCE_CXX20
Martijn Velsb6a08b62020-04-10 18:36:31 -04002329basic_string<_CharT, _Traits, _Allocator>&
2330basic_string<_CharT, _Traits, _Allocator>::__assign_no_alias(
Martijn Vels596e3de2020-02-26 15:55:49 -05002331 const value_type* __s, size_type __n) {
Louis Dionne6209e9f2022-03-03 13:39:12 -05002332 size_type __cap = __is_short ? static_cast<size_type>(__min_cap) : __get_long_cap();
Martijn Vels596e3de2020-02-26 15:55:49 -05002333 if (__n < __cap) {
2334 pointer __p = __is_short ? __get_short_pointer() : __get_long_pointer();
2335 __is_short ? __set_short_size(__n) : __set_long_size(__n);
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002336 traits_type::copy(std::__to_address(__p), __s, __n);
Martijn Vels596e3de2020-02-26 15:55:49 -05002337 traits_type::assign(__p[__n], value_type());
2338 __invalidate_iterators_past(__n);
2339 } else {
2340 size_type __sz = __is_short ? __get_short_size() : __get_long_size();
2341 __grow_by_and_replace(__cap - 1, __n - __cap + 1, __sz, 0, __sz, __n, __s);
2342 }
Martijn Velsb6a08b62020-04-10 18:36:31 -04002343 return *this;
Martijn Vels596e3de2020-02-26 15:55:49 -05002344}
2345
2346template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002347_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002348basic_string<_CharT, _Traits, _Allocator>&
Martijn Velsda7d94f2020-06-19 14:24:03 -04002349basic_string<_CharT, _Traits, _Allocator>::__assign_external(
2350 const value_type* __s, size_type __n) {
2351 size_type __cap = capacity();
2352 if (__cap >= __n) {
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002353 value_type* __p = std::__to_address(__get_pointer());
Martijn Velsda7d94f2020-06-19 14:24:03 -04002354 traits_type::move(__p, __s, __n);
Nikolas Klauser3ec7fb22021-12-14 01:20:53 +01002355 return __null_terminate_at(__p, __n);
Martijn Velsda7d94f2020-06-19 14:24:03 -04002356 } else {
2357 size_type __sz = size();
2358 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
Nikolas Klauser3ec7fb22021-12-14 01:20:53 +01002359 return *this;
Martijn Velsda7d94f2020-06-19 14:24:03 -04002360 }
Martijn Velsda7d94f2020-06-19 14:24:03 -04002361}
2362
2363template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002364_LIBCPP_CONSTEXPR_SINCE_CXX20
Martijn Velsda7d94f2020-06-19 14:24:03 -04002365basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002366basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002367{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002368 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Nikolas Klauser93826d12022-01-04 17:24:03 +01002369 return (__builtin_constant_p(__n) && __fits_in_sso(__n))
Martijn Velsda7d94f2020-06-19 14:24:03 -04002370 ? __assign_short(__s, __n)
2371 : __assign_external(__s, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002372}
2373
2374template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002375_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002376basic_string<_CharT, _Traits, _Allocator>&
2377basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2378{
2379 size_type __cap = capacity();
2380 if (__cap < __n)
2381 {
2382 size_type __sz = size();
2383 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2384 }
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002385 value_type* __p = std::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002386 traits_type::assign(__p, __n, __c);
Nikolas Klauser3ec7fb22021-12-14 01:20:53 +01002387 return __null_terminate_at(__p, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002388}
2389
2390template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002391_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002392basic_string<_CharT, _Traits, _Allocator>&
2393basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2394{
2395 pointer __p;
2396 if (__is_long())
2397 {
2398 __p = __get_long_pointer();
2399 __set_long_size(1);
2400 }
2401 else
2402 {
2403 __p = __get_short_pointer();
2404 __set_short_size(1);
2405 }
2406 traits_type::assign(*__p, __c);
2407 traits_type::assign(*++__p, value_type());
2408 __invalidate_iterators_past(1);
2409 return *this;
2410}
2411
2412template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002413_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002414basic_string<_CharT, _Traits, _Allocator>&
2415basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2416{
Martijn Vels596e3de2020-02-26 15:55:49 -05002417 if (this != &__str) {
2418 __copy_assign_alloc(__str);
2419 if (!__is_long()) {
2420 if (!__str.__is_long()) {
Nikolas Klauser8577eec2022-08-30 17:43:14 +02002421 __r_.first() = __str.__r_.first();
Martijn Vels596e3de2020-02-26 15:55:49 -05002422 } else {
Martijn Velsb6a08b62020-04-10 18:36:31 -04002423 return __assign_no_alias<true>(__str.data(), __str.size());
Martijn Vels596e3de2020-02-26 15:55:49 -05002424 }
2425 } else {
Martijn Velsb6a08b62020-04-10 18:36:31 -04002426 return __assign_no_alias<false>(__str.data(), __str.size());
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002427 }
Martijn Vels596e3de2020-02-26 15:55:49 -05002428 }
2429 return *this;
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002430}
2431
Eric Fiselierfc92be82017-04-19 00:28:44 +00002432#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002433
2434template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002435inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002436void
2437basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002438 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002439{
2440 if (__alloc() != __str.__alloc())
2441 assign(__str);
2442 else
2443 __move_assign(__str, true_type());
2444}
2445
2446template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002447inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002448void
2449basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002450#if _LIBCPP_STD_VER > 14
2451 _NOEXCEPT
2452#else
Howard Hinnant3e276872011-06-03 18:40:47 +00002453 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002454#endif
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002455{
marshall2ed41622019-11-27 07:13:00 -08002456 if (__is_long()) {
2457 __alloc_traits::deallocate(__alloc(), __get_long_pointer(),
2458 __get_long_cap());
2459#if _LIBCPP_STD_VER <= 14
2460 if (!is_nothrow_move_assignable<allocator_type>::value) {
2461 __set_short_size(0);
2462 traits_type::assign(__get_short_pointer()[0], value_type());
2463 }
2464#endif
2465 }
2466 __move_assign_alloc(__str);
2467 __r_.first() = __str.__r_.first();
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002468 if (__libcpp_is_constant_evaluated()) {
2469 __str.__default_init();
2470 } else {
2471 __str.__set_short_size(0);
2472 traits_type::assign(__str.__get_short_pointer()[0], value_type());
2473 }
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002474}
2475
2476template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002477inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002478basic_string<_CharT, _Traits, _Allocator>&
2479basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clow2fe8a8d2015-08-18 18:57:00 +00002480 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnantea8f7e12010-11-17 17:55:08 +00002481{
2482 __move_assign(__str, integral_constant<bool,
2483 __alloc_traits::propagate_on_container_move_assignment::value>());
2484 return *this;
2485}
2486
2487#endif
2488
2489template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002490template<class _InputIterator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002491_LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04002492__enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00002493<
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002494 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002495 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002496>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002497basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2498{
Marshall Clow958362f2016-09-05 01:54:30 +00002499 const basic_string __temp(__first, __last, __alloc());
Marshall Clow039b2f02016-01-13 21:54:34 +00002500 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00002501 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002502}
2503
2504template <class _CharT, class _Traits, class _Allocator>
2505template<class _ForwardIterator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002506_LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04002507__enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00002508<
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002509 __is_cpp17_forward_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002510 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002511>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002512basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2513{
Howard Hinnantc51e1022010-05-11 19:42:16 +00002514 size_type __cap = capacity();
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002515 size_type __n = __string_is_trivial_iterator<_ForwardIterator>::value ?
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002516 static_cast<size_type>(std::distance(__first, __last)) : 0;
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002517
2518 if (__string_is_trivial_iterator<_ForwardIterator>::value &&
2519 (__cap >= __n || !__addr_in_range(*__first)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002520 {
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002521 if (__cap < __n)
2522 {
2523 size_type __sz = size();
2524 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2525 }
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002526 pointer __p = __get_pointer();
Arthur O'Dwyer80dbcbe2021-09-07 21:35:37 -04002527 for (; __first != __last; ++__p, (void) ++__first)
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002528 traits_type::assign(*__p, *__first);
2529 traits_type::assign(*__p, value_type());
2530 __set_size(__n);
Arthur O'Dwyerb3db4542021-04-27 09:10:04 -04002531 __invalidate_iterators_past(__n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002532 }
2533 else
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002534 {
2535 const basic_string __temp(__first, __last, __alloc());
2536 assign(__temp.data(), __temp.size());
2537 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002538 return *this;
2539}
2540
2541template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002542_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002543basic_string<_CharT, _Traits, _Allocator>&
2544basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2545{
2546 size_type __sz = __str.size();
2547 if (__pos > __sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002548 __throw_out_of_range();
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002549 return assign(__str.data() + __pos, std::min(__n, __sz - __pos));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002550}
2551
2552template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00002553template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002554_LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04002555__enable_if_t
Marshall Clow82513342016-09-24 22:45:42 +00002556<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002557 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
2558 && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
Marshall Clowb7db4972017-11-15 20:02:27 +00002559 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002560>
Marshall Clow82513342016-09-24 22:45:42 +00002561basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002562{
Marshall Clow82513342016-09-24 22:45:42 +00002563 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002564 size_type __sz = __sv.size();
2565 if (__pos > __sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002566 __throw_out_of_range();
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002567 return assign(__sv.data() + __pos, std::min(__n, __sz - __pos));
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002568}
2569
2570
2571template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002572_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002573basic_string<_CharT, _Traits, _Allocator>&
Martijn Velsda7d94f2020-06-19 14:24:03 -04002574basic_string<_CharT, _Traits, _Allocator>::__assign_external(const value_type* __s) {
2575 return __assign_external(__s, traits_type::length(__s));
2576}
2577
2578template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002579_LIBCPP_CONSTEXPR_SINCE_CXX20
Martijn Velsda7d94f2020-06-19 14:24:03 -04002580basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002581basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002582{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002583 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Louis Dionne3e0c4332021-08-31 10:49:06 -04002584 return __builtin_constant_p(*__s)
Nikolas Klauser93826d12022-01-04 17:24:03 +01002585 ? (__fits_in_sso(traits_type::length(__s))
Martijn Velsda7d94f2020-06-19 14:24:03 -04002586 ? __assign_short(__s, traits_type::length(__s))
2587 : __assign_external(__s, traits_type::length(__s)))
2588 : __assign_external(__s);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002589}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002590// append
2591
2592template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002593_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002594basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002595basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002596{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002597 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002598 size_type __cap = capacity();
2599 size_type __sz = size();
2600 if (__cap - __sz >= __n)
2601 {
2602 if (__n)
2603 {
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002604 value_type* __p = std::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002605 traits_type::copy(__p + __sz, __s, __n);
2606 __sz += __n;
2607 __set_size(__sz);
2608 traits_type::assign(__p[__sz], value_type());
2609 }
2610 }
2611 else
2612 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2613 return *this;
2614}
2615
2616template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002617_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002618basic_string<_CharT, _Traits, _Allocator>&
2619basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2620{
2621 if (__n)
2622 {
2623 size_type __cap = capacity();
2624 size_type __sz = size();
2625 if (__cap - __sz < __n)
2626 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2627 pointer __p = __get_pointer();
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002628 traits_type::assign(std::__to_address(__p) + __sz, __n, __c);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002629 __sz += __n;
2630 __set_size(__sz);
2631 traits_type::assign(__p[__sz], value_type());
2632 }
2633 return *this;
2634}
2635
2636template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002637_LIBCPP_CONSTEXPR_SINCE_CXX20 inline void
Eric Fiselier451d5582018-11-26 20:15:38 +00002638basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n)
2639{
2640 if (__n)
2641 {
2642 size_type __cap = capacity();
2643 size_type __sz = size();
2644 if (__cap - __sz < __n)
2645 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2646 pointer __p = __get_pointer();
2647 __sz += __n;
2648 __set_size(__sz);
2649 traits_type::assign(__p[__sz], value_type());
2650 }
2651}
2652
2653template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002654_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002655void
2656basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2657{
Howard Hinnant68bf1812013-04-30 21:44:48 +00002658 bool __is_short = !__is_long();
2659 size_type __cap;
2660 size_type __sz;
2661 if (__is_short)
2662 {
2663 __cap = __min_cap - 1;
2664 __sz = __get_short_size();
2665 }
2666 else
2667 {
2668 __cap = __get_long_cap() - 1;
2669 __sz = __get_long_size();
2670 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002671 if (__sz == __cap)
Howard Hinnant68bf1812013-04-30 21:44:48 +00002672 {
Howard Hinnantc51e1022010-05-11 19:42:16 +00002673 __grow_by(__cap, 1, __sz, __sz, 0);
Louis Dionne82d2b2c2021-11-16 11:26:56 -05002674 __is_short = false; // the string is always long after __grow_by
Howard Hinnant68bf1812013-04-30 21:44:48 +00002675 }
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002676 pointer __p = __get_pointer();
Howard Hinnant68bf1812013-04-30 21:44:48 +00002677 if (__is_short)
2678 {
2679 __p = __get_short_pointer() + __sz;
2680 __set_short_size(__sz+1);
2681 }
2682 else
2683 {
2684 __p = __get_long_pointer() + __sz;
2685 __set_long_size(__sz+1);
2686 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002687 traits_type::assign(*__p, __c);
2688 traits_type::assign(*++__p, value_type());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002689}
2690
Howard Hinnantc51e1022010-05-11 19:42:16 +00002691template <class _CharT, class _Traits, class _Allocator>
2692template<class _ForwardIterator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002693_LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04002694__enable_if_t
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002695<
2696 __is_cpp17_forward_iterator<_ForwardIterator>::value,
2697 basic_string<_CharT, _Traits, _Allocator>&
2698>
2699basic_string<_CharT, _Traits, _Allocator>::append(
Eric Fiselierdb7ee8f2016-10-31 02:46:25 +00002700 _ForwardIterator __first, _ForwardIterator __last)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002701{
2702 size_type __sz = size();
2703 size_type __cap = capacity();
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002704 size_type __n = static_cast<size_type>(std::distance(__first, __last));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002705 if (__n)
2706 {
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002707 if (__string_is_trivial_iterator<_ForwardIterator>::value &&
2708 !__addr_in_range(*__first))
Marshall Clow958362f2016-09-05 01:54:30 +00002709 {
2710 if (__cap - __sz < __n)
2711 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2712 pointer __p = __get_pointer() + __sz;
Arthur O'Dwyer80dbcbe2021-09-07 21:35:37 -04002713 for (; __first != __last; ++__p, (void) ++__first)
Marshall Clow958362f2016-09-05 01:54:30 +00002714 traits_type::assign(*__p, *__first);
2715 traits_type::assign(*__p, value_type());
2716 __set_size(__sz + __n);
2717 }
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002718 else
2719 {
2720 const basic_string __temp(__first, __last, __alloc());
2721 append(__temp.data(), __temp.size());
2722 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002723 }
2724 return *this;
2725}
2726
2727template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002728inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002729basic_string<_CharT, _Traits, _Allocator>&
2730basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2731{
2732 return append(__str.data(), __str.size());
2733}
2734
2735template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002736_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002737basic_string<_CharT, _Traits, _Allocator>&
2738basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2739{
2740 size_type __sz = __str.size();
2741 if (__pos > __sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002742 __throw_out_of_range();
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002743 return append(__str.data() + __pos, std::min(__n, __sz - __pos));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002744}
2745
2746template <class _CharT, class _Traits, class _Allocator>
Marshall Clow62953962016-10-03 23:40:48 +00002747template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002748_LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04002749 __enable_if_t
Marshall Clow82513342016-09-24 22:45:42 +00002750 <
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002751 __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 +00002752 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002753 >
Marshall Clow82513342016-09-24 22:45:42 +00002754basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002755{
Marshall Clow82513342016-09-24 22:45:42 +00002756 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002757 size_type __sz = __sv.size();
2758 if (__pos > __sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002759 __throw_out_of_range();
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002760 return append(__sv.data() + __pos, std::min(__n, __sz - __pos));
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002761}
2762
2763template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002764_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002765basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002766basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002767{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002768 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002769 return append(__s, traits_type::length(__s));
2770}
2771
2772// insert
2773
2774template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002775_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002776basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002777basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002778{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002779 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002780 size_type __sz = size();
2781 if (__pos > __sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002782 __throw_out_of_range();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002783 size_type __cap = capacity();
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002784 if (__libcpp_is_constant_evaluated()) {
2785 if (__cap - __sz >= __n)
2786 __grow_by_and_replace(__cap, 0, __sz, __pos, 0, __n, __s);
2787 else
2788 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2789 return *this;
2790 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002791 if (__cap - __sz >= __n)
2792 {
2793 if (__n)
2794 {
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002795 value_type* __p = std::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002796 size_type __n_move = __sz - __pos;
2797 if (__n_move != 0)
2798 {
2799 if (__p + __pos <= __s && __s < __p + __sz)
2800 __s += __n;
2801 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2802 }
2803 traits_type::move(__p + __pos, __s, __n);
2804 __sz += __n;
2805 __set_size(__sz);
2806 traits_type::assign(__p[__sz], value_type());
2807 }
2808 }
2809 else
2810 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2811 return *this;
2812}
2813
2814template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002815_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002816basic_string<_CharT, _Traits, _Allocator>&
2817basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2818{
2819 size_type __sz = size();
2820 if (__pos > __sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002821 __throw_out_of_range();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002822 if (__n)
2823 {
2824 size_type __cap = capacity();
Howard Hinnantd17880b2013-06-28 16:59:19 +00002825 value_type* __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002826 if (__cap - __sz >= __n)
2827 {
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002828 __p = std::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002829 size_type __n_move = __sz - __pos;
2830 if (__n_move != 0)
2831 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2832 }
2833 else
2834 {
2835 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002836 __p = std::__to_address(__get_long_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002837 }
2838 traits_type::assign(__p + __pos, __n, __c);
2839 __sz += __n;
2840 __set_size(__sz);
2841 traits_type::assign(__p[__sz], value_type());
2842 }
2843 return *this;
2844}
2845
2846template <class _CharT, class _Traits, class _Allocator>
2847template<class _InputIterator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002848_LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04002849__enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00002850<
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002851 __is_exactly_cpp17_input_iterator<_InputIterator>::value,
Marshall Clow039b2f02016-01-13 21:54:34 +00002852 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002853>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002854basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2855{
Nikolas Klausereed25832021-12-15 01:32:30 +01002856 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2857 "string::insert(iterator, range) called with an iterator not"
2858 " referring to this string");
2859 const basic_string __temp(__first, __last, __alloc());
2860 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002861}
2862
2863template <class _CharT, class _Traits, class _Allocator>
2864template<class _ForwardIterator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002865_LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04002866__enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00002867<
Arthur O'Dwyer98ff31f2021-04-16 17:49:57 -04002868 __is_cpp17_forward_iterator<_ForwardIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002869 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002870>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002871basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2872{
Nikolas Klauser48d680d2022-02-26 13:28:33 +01002873 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2874 "string::insert(iterator, range) called with an iterator not referring to this string");
Nikolas Klausereed25832021-12-15 01:32:30 +01002875
Howard Hinnantc51e1022010-05-11 19:42:16 +00002876 size_type __ip = static_cast<size_type>(__pos - begin());
Nikolas Klauser48d680d2022-02-26 13:28:33 +01002877 size_type __n = static_cast<size_type>(std::distance(__first, __last));
2878 if (__n == 0)
2879 return begin() + __ip;
2880
2881 if (__string_is_trivial_iterator<_ForwardIterator>::value && !__addr_in_range(*__first))
Howard Hinnantc51e1022010-05-11 19:42:16 +00002882 {
Nikolas Klauser48d680d2022-02-26 13:28:33 +01002883 return __insert_from_safe_copy(__n, __ip, __first, __last);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002884 }
Nikolas Klauser48d680d2022-02-26 13:28:33 +01002885 else
2886 {
2887 const basic_string __temp(__first, __last, __alloc());
2888 return __insert_from_safe_copy(__n, __ip, __temp.begin(), __temp.end());
2889 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002890}
2891
2892template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002893inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002894basic_string<_CharT, _Traits, _Allocator>&
2895basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2896{
2897 return insert(__pos1, __str.data(), __str.size());
2898}
2899
2900template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002901_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002902basic_string<_CharT, _Traits, _Allocator>&
2903basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2904 size_type __pos2, size_type __n)
2905{
2906 size_type __str_sz = __str.size();
2907 if (__pos2 > __str_sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002908 __throw_out_of_range();
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002909 return insert(__pos1, __str.data() + __pos2, std::min(__n, __str_sz - __pos2));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002910}
2911
2912template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00002913template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002914_LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04002915__enable_if_t
Marshall Clow82513342016-09-24 22:45:42 +00002916<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002917 __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 +00002918 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05002919>
Marshall Clow82513342016-09-24 22:45:42 +00002920basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002921 size_type __pos2, size_type __n)
2922{
Marshall Clow82513342016-09-24 22:45:42 +00002923 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002924 size_type __str_sz = __sv.size();
2925 if (__pos2 > __str_sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002926 __throw_out_of_range();
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002927 return insert(__pos1, __sv.data() + __pos2, std::min(__n, __str_sz - __pos2));
Marshall Clowdf63a6d2016-07-21 05:31:24 +00002928}
2929
2930template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002931_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002932basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002933basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002934{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002935 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002936 return insert(__pos, __s, traits_type::length(__s));
2937}
2938
2939template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002940_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002941typename basic_string<_CharT, _Traits, _Allocator>::iterator
2942basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2943{
Louis Dionnef4cc6fb2022-02-15 15:47:45 -05002944 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2945 "string::insert(iterator, character) called with an iterator not"
2946 " referring to this string");
2947
Howard Hinnantc51e1022010-05-11 19:42:16 +00002948 size_type __ip = static_cast<size_type>(__pos - begin());
2949 size_type __sz = size();
2950 size_type __cap = capacity();
Howard Hinnantd17880b2013-06-28 16:59:19 +00002951 value_type* __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002952 if (__cap == __sz)
2953 {
2954 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002955 __p = std::__to_address(__get_long_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002956 }
2957 else
2958 {
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002959 __p = std::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002960 size_type __n_move = __sz - __ip;
2961 if (__n_move != 0)
2962 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2963 }
2964 traits_type::assign(__p[__ip], __c);
2965 traits_type::assign(__p[++__sz], value_type());
2966 __set_size(__sz);
2967 return begin() + static_cast<difference_type>(__ip);
2968}
2969
2970template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002971inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002972typename basic_string<_CharT, _Traits, _Allocator>::iterator
2973basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2974{
Nikolas Klausereed25832021-12-15 01:32:30 +01002975 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2976 "string::insert(iterator, n, value) called with an iterator not"
2977 " referring to this string");
2978 difference_type __p = __pos - begin();
2979 insert(static_cast<size_type>(__p), __n, __c);
2980 return begin() + __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002981}
2982
2983// replace
2984
2985template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02002986_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00002987basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00002988basic_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 +00002989 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
Howard Hinnantc51e1022010-05-11 19:42:16 +00002990{
Alp Tokerb8a95f52014-05-15 11:27:39 +00002991 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00002992 size_type __sz = size();
2993 if (__pos > __sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01002994 __throw_out_of_range();
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02002995 __n1 = std::min(__n1, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002996 size_type __cap = capacity();
2997 if (__cap - __sz + __n1 >= __n2)
2998 {
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02002999 if (__libcpp_is_constant_evaluated()) {
3000 __grow_by_and_replace(__cap, 0, __sz, __pos, __n1, __n2, __s);
3001 return *this;
3002 }
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02003003 value_type* __p = std::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003004 if (__n1 != __n2)
3005 {
3006 size_type __n_move = __sz - __pos - __n1;
3007 if (__n_move != 0)
3008 {
3009 if (__n1 > __n2)
3010 {
3011 traits_type::move(__p + __pos, __s, __n2);
3012 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
Nikolas Klauser3ec7fb22021-12-14 01:20:53 +01003013 return __null_terminate_at(__p, __sz + (__n2 - __n1));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003014 }
3015 if (__p + __pos < __s && __s < __p + __sz)
3016 {
3017 if (__p + __pos + __n1 <= __s)
3018 __s += __n2 - __n1;
3019 else // __p + __pos < __s < __p + __pos + __n1
3020 {
3021 traits_type::move(__p + __pos, __s, __n1);
3022 __pos += __n1;
3023 __s += __n2;
3024 __n2 -= __n1;
3025 __n1 = 0;
3026 }
3027 }
3028 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
3029 }
3030 }
3031 traits_type::move(__p + __pos, __s, __n2);
Nikolas Klauser3ec7fb22021-12-14 01:20:53 +01003032 return __null_terminate_at(__p, __sz + (__n2 - __n1));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003033 }
3034 else
3035 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
3036 return *this;
3037}
3038
3039template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003040_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003041basic_string<_CharT, _Traits, _Allocator>&
3042basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
3043{
3044 size_type __sz = size();
3045 if (__pos > __sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01003046 __throw_out_of_range();
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02003047 __n1 = std::min(__n1, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003048 size_type __cap = capacity();
Howard Hinnantd17880b2013-06-28 16:59:19 +00003049 value_type* __p;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003050 if (__cap - __sz + __n1 >= __n2)
3051 {
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02003052 __p = std::__to_address(__get_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003053 if (__n1 != __n2)
3054 {
3055 size_type __n_move = __sz - __pos - __n1;
3056 if (__n_move != 0)
3057 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
3058 }
3059 }
3060 else
3061 {
3062 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02003063 __p = std::__to_address(__get_long_pointer());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003064 }
3065 traits_type::assign(__p + __pos, __n2, __c);
Nikolas Klauser3ec7fb22021-12-14 01:20:53 +01003066 return __null_terminate_at(__p, __sz - (__n1 - __n2));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003067}
3068
3069template <class _CharT, class _Traits, class _Allocator>
3070template<class _InputIterator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003071_LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04003072__enable_if_t
Howard Hinnantc51e1022010-05-11 19:42:16 +00003073<
Eric Fiseliercd5a6772019-11-18 01:46:58 -05003074 __is_cpp17_input_iterator<_InputIterator>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00003075 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003076>
Howard Hinnant990d6e82010-11-17 21:11:40 +00003077basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantc51e1022010-05-11 19:42:16 +00003078 _InputIterator __j1, _InputIterator __j2)
3079{
Marshall Clow958362f2016-09-05 01:54:30 +00003080 const basic_string __temp(__j1, __j2, __alloc());
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01003081 return replace(__i1, __i2, __temp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003082}
3083
3084template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003085inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003086basic_string<_CharT, _Traits, _Allocator>&
3087basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
3088{
3089 return replace(__pos1, __n1, __str.data(), __str.size());
3090}
3091
3092template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003093_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003094basic_string<_CharT, _Traits, _Allocator>&
3095basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
3096 size_type __pos2, size_type __n2)
3097{
3098 size_type __str_sz = __str.size();
3099 if (__pos2 > __str_sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01003100 __throw_out_of_range();
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02003101 return replace(__pos1, __n1, __str.data() + __pos2, std::min(__n2, __str_sz - __pos2));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003102}
3103
3104template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00003105template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003106_LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04003107__enable_if_t
Marshall Clow82513342016-09-24 22:45:42 +00003108<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003109 __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 +00003110 basic_string<_CharT, _Traits, _Allocator>&
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003111>
Marshall Clow82513342016-09-24 22:45:42 +00003112basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003113 size_type __pos2, size_type __n2)
3114{
Marshall Clow82513342016-09-24 22:45:42 +00003115 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003116 size_type __str_sz = __sv.size();
3117 if (__pos2 > __str_sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01003118 __throw_out_of_range();
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02003119 return replace(__pos1, __n1, __sv.data() + __pos2, std::min(__n2, __str_sz - __pos2));
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003120}
3121
3122template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003123_LIBCPP_CONSTEXPR_SINCE_CXX20
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003124basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00003125basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003126{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003127 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003128 return replace(__pos, __n1, __s, traits_type::length(__s));
3129}
3130
3131template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003132inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003133basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant990d6e82010-11-17 21:11:40 +00003134basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003135{
3136 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
3137 __str.data(), __str.size());
3138}
3139
3140template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003141inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003142basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00003143basic_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 +00003144{
3145 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
3146}
3147
3148template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003149inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003150basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnantd17880b2013-06-28 16:59:19 +00003151basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003152{
3153 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
3154}
3155
3156template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003157inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003158basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant990d6e82010-11-17 21:11:40 +00003159basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003160{
3161 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
3162}
3163
3164// erase
3165
Martijn Velsa81fc792020-02-26 13:25:43 -05003166// 'externally instantiated' erase() implementation, called when __n != npos.
3167// Does not check __pos against size()
Howard Hinnantc51e1022010-05-11 19:42:16 +00003168template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003169_LIBCPP_CONSTEXPR_SINCE_CXX20
Martijn Velsa81fc792020-02-26 13:25:43 -05003170void
3171basic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move(
3172 size_type __pos, size_type __n)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003173{
Howard Hinnantc51e1022010-05-11 19:42:16 +00003174 if (__n)
3175 {
Martijn Velsa81fc792020-02-26 13:25:43 -05003176 size_type __sz = size();
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02003177 value_type* __p = std::__to_address(__get_pointer());
3178 __n = std::min(__n, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003179 size_type __n_move = __sz - __pos - __n;
3180 if (__n_move != 0)
3181 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
Nikolas Klauser3ec7fb22021-12-14 01:20:53 +01003182 __null_terminate_at(__p, __sz - __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003183 }
Martijn Velsa81fc792020-02-26 13:25:43 -05003184}
3185
3186template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003187_LIBCPP_CONSTEXPR_SINCE_CXX20
Martijn Velsa81fc792020-02-26 13:25:43 -05003188basic_string<_CharT, _Traits, _Allocator>&
3189basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos,
3190 size_type __n) {
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01003191 if (__pos > size())
3192 __throw_out_of_range();
Martijn Velsa81fc792020-02-26 13:25:43 -05003193 if (__n == npos) {
3194 __erase_to_end(__pos);
3195 } else {
3196 __erase_external_with_move(__pos, __n);
3197 }
3198 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003199}
3200
3201template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003202inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003203typename basic_string<_CharT, _Traits, _Allocator>::iterator
3204basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
3205{
Nikolas Klausereed25832021-12-15 01:32:30 +01003206 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
3207 "string::erase(iterator) called with an iterator not"
3208 " referring to this string");
3209
3210 _LIBCPP_ASSERT(__pos != end(), "string::erase(iterator) called with a non-dereferenceable iterator");
3211 iterator __b = begin();
3212 size_type __r = static_cast<size_type>(__pos - __b);
3213 erase(__r, 1);
3214 return __b + static_cast<difference_type>(__r);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003215}
3216
3217template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003218inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003219typename basic_string<_CharT, _Traits, _Allocator>::iterator
3220basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
3221{
Nikolas Klausereed25832021-12-15 01:32:30 +01003222 _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
3223 "string::erase(iterator, iterator) called with an iterator not"
3224 " referring to this string");
3225
3226 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
3227 iterator __b = begin();
3228 size_type __r = static_cast<size_type>(__first - __b);
3229 erase(__r, static_cast<size_type>(__last - __first));
3230 return __b + static_cast<difference_type>(__r);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003231}
3232
3233template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003234inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003235void
3236basic_string<_CharT, _Traits, _Allocator>::pop_back()
3237{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003238 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Nikolas Klauser3ec7fb22021-12-14 01:20:53 +01003239 __erase_to_end(size() - 1);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003240}
3241
3242template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003243inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003244void
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003245basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003246{
Nikolas Klauserf1d286b2022-05-08 16:40:04 +02003247 std::__debug_db_invalidate_all(this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003248 if (__is_long())
3249 {
3250 traits_type::assign(*__get_long_pointer(), value_type());
3251 __set_long_size(0);
3252 }
3253 else
3254 {
3255 traits_type::assign(*__get_short_pointer(), value_type());
3256 __set_short_size(0);
3257 }
3258}
3259
3260template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003261inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003262void
3263basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3264{
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02003265 __null_terminate_at(std::__to_address(__get_pointer()), __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003266}
3267
3268template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003269_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003270void
3271basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3272{
3273 size_type __sz = size();
3274 if (__n > __sz)
3275 append(__n - __sz, __c);
3276 else
3277 __erase_to_end(__n);
3278}
3279
3280template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003281_LIBCPP_CONSTEXPR_SINCE_CXX20 inline void
Eric Fiselier451d5582018-11-26 20:15:38 +00003282basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n)
3283{
3284 size_type __sz = size();
3285 if (__n > __sz) {
3286 __append_default_init(__n - __sz);
3287 } else
3288 __erase_to_end(__n);
3289}
3290
3291template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003292inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003293typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003294basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003295{
Howard Hinnantea8f7e12010-11-17 17:55:08 +00003296 size_type __m = __alloc_traits::max_size(__alloc());
Nikolas Klauser62060be2022-04-20 10:52:04 +02003297 if (__m <= std::numeric_limits<size_type>::max() / 2) {
3298 return __m - __alignment;
3299 } else {
3300 bool __uses_lsb = __endian_factor == 2;
3301 return __uses_lsb ? __m - __alignment : (__m / 2) - __alignment;
3302 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00003303}
3304
3305template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003306_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003307void
Marek Kurdejc9848142020-11-26 10:07:16 +01003308basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacity)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003309{
Marek Kurdejc9848142020-11-26 10:07:16 +01003310 if (__requested_capacity > max_size())
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01003311 __throw_length_error();
Marek Kurdejc9848142020-11-26 10:07:16 +01003312
Louis Dionne05b6d3e2022-01-14 12:30:22 -05003313 // Make sure reserve(n) never shrinks. This is technically only required in C++20
3314 // and later (since P0966R1), however we provide consistent behavior in all Standard
3315 // modes because this function is instantiated in the shared library.
3316 if (__requested_capacity <= capacity())
3317 return;
Marek Kurdejc9848142020-11-26 10:07:16 +01003318
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02003319 size_type __target_capacity = std::max(__requested_capacity, size());
Marek Kurdejc9848142020-11-26 10:07:16 +01003320 __target_capacity = __recommend(__target_capacity);
3321 if (__target_capacity == capacity()) return;
3322
3323 __shrink_or_extend(__target_capacity);
3324}
3325
3326template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003327inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Marek Kurdejc9848142020-11-26 10:07:16 +01003328void
3329basic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT
3330{
3331 size_type __target_capacity = __recommend(size());
3332 if (__target_capacity == capacity()) return;
3333
3334 __shrink_or_extend(__target_capacity);
3335}
3336
3337template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003338inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Marek Kurdejc9848142020-11-26 10:07:16 +01003339void
3340basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target_capacity)
3341{
Howard Hinnantc51e1022010-05-11 19:42:16 +00003342 size_type __cap = capacity();
3343 size_type __sz = size();
Marek Kurdejc9848142020-11-26 10:07:16 +01003344
3345 pointer __new_data, __p;
3346 bool __was_long, __now_long;
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003347 if (__fits_in_sso(__target_capacity))
Howard Hinnantc51e1022010-05-11 19:42:16 +00003348 {
Marek Kurdejc9848142020-11-26 10:07:16 +01003349 __was_long = true;
3350 __now_long = false;
3351 __new_data = __get_short_pointer();
3352 __p = __get_long_pointer();
Howard Hinnantc51e1022010-05-11 19:42:16 +00003353 }
Marek Kurdejc9848142020-11-26 10:07:16 +01003354 else
3355 {
Nikolas Klauserc513eba2022-04-09 09:41:19 +02003356 if (__target_capacity > __cap) {
3357 auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1);
3358 __new_data = __allocation.ptr;
3359 __target_capacity = __allocation.count - 1;
3360 }
Marek Kurdejc9848142020-11-26 10:07:16 +01003361 else
3362 {
3363 #ifndef _LIBCPP_NO_EXCEPTIONS
3364 try
3365 {
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04003366 #endif // _LIBCPP_NO_EXCEPTIONS
Nikolas Klauserc513eba2022-04-09 09:41:19 +02003367 auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1);
3368 __new_data = __allocation.ptr;
3369 __target_capacity = __allocation.count - 1;
Marek Kurdejc9848142020-11-26 10:07:16 +01003370 #ifndef _LIBCPP_NO_EXCEPTIONS
3371 }
3372 catch (...)
3373 {
3374 return;
3375 }
3376 #else // _LIBCPP_NO_EXCEPTIONS
3377 if (__new_data == nullptr)
3378 return;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04003379 #endif // _LIBCPP_NO_EXCEPTIONS
Marek Kurdejc9848142020-11-26 10:07:16 +01003380 }
Nikolas Klauser80b3cf32022-04-27 10:11:44 +02003381 __begin_lifetime(__new_data, __target_capacity + 1);
Marek Kurdejc9848142020-11-26 10:07:16 +01003382 __now_long = true;
3383 __was_long = __is_long();
3384 __p = __get_pointer();
3385 }
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02003386 traits_type::copy(std::__to_address(__new_data),
3387 std::__to_address(__p), size()+1);
Marek Kurdejc9848142020-11-26 10:07:16 +01003388 if (__was_long)
3389 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
3390 if (__now_long)
3391 {
3392 __set_long_cap(__target_capacity+1);
3393 __set_long_size(__sz);
3394 __set_long_pointer(__new_data);
3395 }
3396 else
3397 __set_short_size(__sz);
Nikolas Klauserf1d286b2022-05-08 16:40:04 +02003398 std::__debug_db_invalidate_all(this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003399}
3400
3401template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003402inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003403typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003404basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003405{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003406 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003407 return *(data() + __pos);
3408}
3409
3410template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003411inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003412typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003413basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003414{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003415 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003416 return *(__get_pointer() + __pos);
3417}
3418
3419template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003420_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003421typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3422basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3423{
3424 if (__n >= size())
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01003425 __throw_out_of_range();
Howard Hinnantc51e1022010-05-11 19:42:16 +00003426 return (*this)[__n];
3427}
3428
3429template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003430_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003431typename basic_string<_CharT, _Traits, _Allocator>::reference
3432basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3433{
3434 if (__n >= size())
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01003435 __throw_out_of_range();
Howard Hinnantc51e1022010-05-11 19:42:16 +00003436 return (*this)[__n];
3437}
3438
3439template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003440inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003441typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003442basic_string<_CharT, _Traits, _Allocator>::front() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003443{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003444 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003445 return *__get_pointer();
3446}
3447
3448template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003449inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003450typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003451basic_string<_CharT, _Traits, _Allocator>::front() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003452{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003453 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003454 return *data();
3455}
3456
3457template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003458inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003459typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003460basic_string<_CharT, _Traits, _Allocator>::back() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003461{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003462 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003463 return *(__get_pointer() + size() - 1);
3464}
3465
3466template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003467inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003468typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow05cf6692019-03-19 03:30:07 +00003469basic_string<_CharT, _Traits, _Allocator>::back() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003470{
Howard Hinnant8ea98242013-08-23 17:37:05 +00003471 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003472 return *(data() + size() - 1);
3473}
3474
3475template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003476_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003477typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003478basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00003479{
3480 size_type __sz = size();
3481 if (__pos > __sz)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01003482 __throw_out_of_range();
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02003483 size_type __rlen = std::min(__n, __sz - __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003484 traits_type::copy(__s, data() + __pos, __rlen);
3485 return __rlen;
3486}
3487
3488template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003489inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003490basic_string<_CharT, _Traits, _Allocator>
3491basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3492{
3493 return basic_string(*this, __pos, __n, __alloc());
3494}
3495
3496template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003497inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003498void
3499basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow8982dcd2015-07-13 20:04:56 +00003500#if _LIBCPP_STD_VER >= 14
Eric Fiselier873b8d32019-03-18 21:50:12 +00003501 _NOEXCEPT
Marshall Clow8982dcd2015-07-13 20:04:56 +00003502#else
Eric Fiselier873b8d32019-03-18 21:50:12 +00003503 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow8982dcd2015-07-13 20:04:56 +00003504 __is_nothrow_swappable<allocator_type>::value)
3505#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003506{
Nikolas Klauser98833542022-05-07 22:20:23 +02003507 if (!__is_long())
3508 std::__debug_db_invalidate_all(this);
3509 if (!__str.__is_long())
3510 std::__debug_db_invalidate_all(&__str);
3511 std::__debug_db_swap(this, &__str);
3512
Eric Fiselier9bf691f2016-12-28 05:53:01 +00003513 _LIBCPP_ASSERT(
3514 __alloc_traits::propagate_on_container_swap::value ||
3515 __alloc_traits::is_always_equal::value ||
3516 __alloc() == __str.__alloc(), "swapping non-equal allocators");
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02003517 std::swap(__r_.first(), __str.__r_.first());
3518 std::__swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003519}
3520
3521// find
3522
3523template <class _Traits>
3524struct _LIBCPP_HIDDEN __traits_eq
3525{
3526 typedef typename _Traits::char_type char_type;
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02003527 _LIBCPP_HIDE_FROM_ABI
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003528 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3529 {return _Traits::eq(__x, __y);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003530};
3531
3532template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003533_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003534typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003535basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003536 size_type __pos,
3537 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003538{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003539 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003540 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003541 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003542}
3543
3544template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003545inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003546typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003547basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3548 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003549{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003550 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003551 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003552}
3553
3554template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003555template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003556_LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04003557__enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00003558<
3559 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3560 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003561>
Marshall Clowe46031a2018-07-02 18:41:15 +00003562basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t,
zoecarver1997e0a2021-02-05 11:54:47 -08003563 size_type __pos) const _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003564{
Marshall Clowe46031a2018-07-02 18:41:15 +00003565 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003566 return __str_find<value_type, size_type, traits_type, npos>
3567 (data(), size(), __sv.data(), __pos, __sv.size());
3568}
3569
3570template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003571inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003572typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003573basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003574 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003575{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003576 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003577 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003578 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003579}
3580
3581template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003582_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003583typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003584basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3585 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003586{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003587 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003588 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003589}
3590
3591// rfind
3592
3593template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003594_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003595typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003596basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003597 size_type __pos,
3598 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003599{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003600 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003601 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003602 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003603}
3604
3605template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003606inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003607typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003608basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3609 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003610{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003611 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003612 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003613}
3614
3615template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003616template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003617_LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04003618__enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00003619<
3620 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3621 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003622>
Marshall Clowe46031a2018-07-02 18:41:15 +00003623basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t,
zoecarver1997e0a2021-02-05 11:54:47 -08003624 size_type __pos) const _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003625{
Marshall Clowe46031a2018-07-02 18:41:15 +00003626 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003627 return __str_rfind<value_type, size_type, traits_type, npos>
3628 (data(), size(), __sv.data(), __pos, __sv.size());
3629}
3630
3631template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003632inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003633typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003634basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003635 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003636{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003637 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003638 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003639 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003640}
3641
3642template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003643_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003644typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003645basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3646 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003647{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003648 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clowc527b6e2014-06-02 02:22:49 +00003649 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003650}
3651
3652// find_first_of
3653
3654template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003655_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003656typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003657basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003658 size_type __pos,
3659 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003660{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003661 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003662 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003663 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003664}
3665
3666template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003667inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003668typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003669basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3670 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003671{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003672 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003673 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003674}
3675
3676template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003677template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003678_LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04003679__enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00003680<
3681 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3682 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003683>
Marshall Clowe46031a2018-07-02 18:41:15 +00003684basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t,
zoecarver1997e0a2021-02-05 11:54:47 -08003685 size_type __pos) const _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003686{
Marshall Clowe46031a2018-07-02 18:41:15 +00003687 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003688 return __str_find_first_of<value_type, size_type, traits_type, npos>
3689 (data(), size(), __sv.data(), __pos, __sv.size());
3690}
3691
3692template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003693inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003694typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003695basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003696 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003697{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003698 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003699 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003700 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003701}
3702
3703template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003704inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003705typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003706basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3707 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003708{
3709 return find(__c, __pos);
3710}
3711
3712// find_last_of
3713
3714template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003715inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003716typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003717basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003718 size_type __pos,
3719 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003720{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003721 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003722 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003723 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003724}
3725
3726template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003727inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003728typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003729basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3730 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003731{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003732 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003733 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003734}
3735
3736template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003737template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003738_LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04003739__enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00003740<
3741 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3742 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003743>
Marshall Clowe46031a2018-07-02 18:41:15 +00003744basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t,
zoecarver1997e0a2021-02-05 11:54:47 -08003745 size_type __pos) const _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003746{
Marshall Clowe46031a2018-07-02 18:41:15 +00003747 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003748 return __str_find_last_of<value_type, size_type, traits_type, npos>
3749 (data(), size(), __sv.data(), __pos, __sv.size());
3750}
3751
3752template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003753inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003754typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003755basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003756 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003757{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003758 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003759 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003760 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003761}
3762
3763template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003764inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003765typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003766basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3767 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003768{
3769 return rfind(__c, __pos);
3770}
3771
3772// find_first_not_of
3773
3774template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003775_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003776typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003777basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003778 size_type __pos,
3779 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003780{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003781 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003782 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003783 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003784}
3785
3786template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003787inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003788typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003789basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3790 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003791{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003792 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003793 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003794}
3795
3796template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003797template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003798_LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04003799__enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00003800<
3801 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3802 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003803>
Marshall Clowe46031a2018-07-02 18:41:15 +00003804basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t,
zoecarver1997e0a2021-02-05 11:54:47 -08003805 size_type __pos) const _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003806{
Marshall Clowe46031a2018-07-02 18:41:15 +00003807 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003808 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3809 (data(), size(), __sv.data(), __pos, __sv.size());
3810}
3811
3812template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003813inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003814typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003815basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003816 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003817{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003818 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003819 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003820 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003821}
3822
3823template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003824inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003825typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003826basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3827 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003828{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003829 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003830 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003831}
3832
3833// find_last_not_of
3834
3835template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003836_LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003837typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003838basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003839 size_type __pos,
3840 size_type __n) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003841{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003842 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003843 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003844 (data(), size(), __s, __pos, __n);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003845}
3846
3847template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003848inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003849typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003850basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3851 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003852{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003853 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003854 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantc51e1022010-05-11 19:42:16 +00003855}
3856
3857template<class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003858template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003859_LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04003860__enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00003861<
3862 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3863 typename basic_string<_CharT, _Traits, _Allocator>::size_type
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003864>
Marshall Clowe46031a2018-07-02 18:41:15 +00003865basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t,
zoecarver1997e0a2021-02-05 11:54:47 -08003866 size_type __pos) const _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003867{
Marshall Clowe46031a2018-07-02 18:41:15 +00003868 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003869 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3870 (data(), size(), __sv.data(), __pos, __sv.size());
3871}
3872
3873template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003874inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003875typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantd17880b2013-06-28 16:59:19 +00003876basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003877 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003878{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003879 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003880 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003881 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003882}
3883
3884template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003885inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003886typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003887basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3888 size_type __pos) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003889{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003890 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow4bc2be22014-02-16 01:57:26 +00003891 (data(), size(), __c, __pos);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003892}
3893
3894// compare
3895
3896template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003897template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003898_LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04003899__enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00003900<
3901 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3902 int
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003903>
zoecarver1997e0a2021-02-05 11:54:47 -08003904basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003905{
Marshall Clowe46031a2018-07-02 18:41:15 +00003906 __self_view __sv = __t;
Howard Hinnantb0485532011-07-24 21:45:06 +00003907 size_t __lhs_sz = size();
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003908 size_t __rhs_sz = __sv.size();
3909 int __result = traits_type::compare(data(), __sv.data(),
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02003910 std::min(__lhs_sz, __rhs_sz));
Howard Hinnantb0485532011-07-24 21:45:06 +00003911 if (__result != 0)
3912 return __result;
3913 if (__lhs_sz < __rhs_sz)
3914 return -1;
3915 if (__lhs_sz > __rhs_sz)
3916 return 1;
3917 return 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003918}
3919
3920template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003921inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003922int
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003923basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00003924{
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003925 return compare(__self_view(__str));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003926}
3927
3928template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003929inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00003930int
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003931basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3932 size_type __n1,
Howard Hinnantd17880b2013-06-28 16:59:19 +00003933 const value_type* __s,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00003934 size_type __n2) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00003935{
Alp Tokerb8a95f52014-05-15 11:27:39 +00003936 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantc51e1022010-05-11 19:42:16 +00003937 size_type __sz = size();
3938 if (__pos1 > __sz || __n2 == npos)
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01003939 __throw_out_of_range();
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02003940 size_type __rlen = std::min(__n1, __sz - __pos1);
3941 int __r = traits_type::compare(data() + __pos1, __s, std::min(__rlen, __n2));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003942 if (__r == 0)
3943 {
3944 if (__rlen < __n2)
3945 __r = -1;
3946 else if (__rlen > __n2)
3947 __r = 1;
3948 }
3949 return __r;
3950}
3951
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003952template <class _CharT, class _Traits, class _Allocator>
Marshall Clowe46031a2018-07-02 18:41:15 +00003953template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003954_LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04003955__enable_if_t
Marshall Clowe46031a2018-07-02 18:41:15 +00003956<
3957 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3958 int
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003959>
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003960basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3961 size_type __n1,
Marshall Clowe46031a2018-07-02 18:41:15 +00003962 const _Tp& __t) const
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003963{
Marshall Clowe46031a2018-07-02 18:41:15 +00003964 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003965 return compare(__pos1, __n1, __sv.data(), __sv.size());
3966}
3967
3968template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003969inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003970int
3971basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3972 size_type __n1,
3973 const basic_string& __str) const
3974{
3975 return compare(__pos1, __n1, __str.data(), __str.size());
3976}
3977
3978template <class _CharT, class _Traits, class _Allocator>
Marshall Clow82513342016-09-24 22:45:42 +00003979template <class _Tp>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003980_LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne9ce598d2021-09-08 09:14:43 -04003981__enable_if_t
Marshall Clow82513342016-09-24 22:45:42 +00003982<
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003983 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value
3984 && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value,
Marshall Clowb7db4972017-11-15 20:02:27 +00003985 int
Eric Fiselierc522ceb2020-01-15 16:57:08 -05003986>
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003987basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3988 size_type __n1,
Marshall Clow82513342016-09-24 22:45:42 +00003989 const _Tp& __t,
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003990 size_type __pos2,
3991 size_type __n2) const
3992{
Marshall Clow82513342016-09-24 22:45:42 +00003993 __self_view __sv = __t;
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003994 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3995}
3996
3997template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02003998_LIBCPP_CONSTEXPR_SINCE_CXX20
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003999int
4000basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
4001 size_type __n1,
4002 const basic_string& __str,
4003 size_type __pos2,
4004 size_type __n2) const
4005{
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01004006 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
Marshall Clowdf63a6d2016-07-21 05:31:24 +00004007}
4008
4009template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004010_LIBCPP_CONSTEXPR_SINCE_CXX20
Marshall Clowdf63a6d2016-07-21 05:31:24 +00004011int
4012basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
4013{
4014 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
4015 return compare(0, npos, __s, traits_type::length(__s));
4016}
4017
4018template <class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004019_LIBCPP_CONSTEXPR_SINCE_CXX20
Marshall Clowdf63a6d2016-07-21 05:31:24 +00004020int
4021basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
4022 size_type __n1,
4023 const value_type* __s) const
4024{
4025 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
4026 return compare(__pos1, __n1, __s, traits_type::length(__s));
4027}
4028
Howard Hinnantc51e1022010-05-11 19:42:16 +00004029// __invariants
4030
4031template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004032inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00004033bool
4034basic_string<_CharT, _Traits, _Allocator>::__invariants() const
4035{
4036 if (size() > capacity())
4037 return false;
4038 if (capacity() < __min_cap - 1)
4039 return false;
Bruce Mitchener170d8972020-11-24 12:53:53 -05004040 if (data() == nullptr)
Howard Hinnantc51e1022010-05-11 19:42:16 +00004041 return false;
Louis Dionne663415f2020-10-05 16:16:13 -04004042 if (data()[size()] != value_type())
Howard Hinnantc51e1022010-05-11 19:42:16 +00004043 return false;
4044 return true;
4045}
4046
Vedant Kumar55e007e2018-03-08 21:15:26 +00004047// __clear_and_shrink
4048
4049template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004050inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Louis Dionne173f29e2019-05-29 16:01:36 +00004051void
Marshall Clowe60a7182018-05-29 17:04:37 +00004052basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT
Vedant Kumar55e007e2018-03-08 21:15:26 +00004053{
4054 clear();
4055 if(__is_long())
4056 {
4057 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
Nikolas Klauser1821ec32022-10-01 15:37:24 +02004058 __default_init();
Vedant Kumar55e007e2018-03-08 21:15:26 +00004059 }
Louis Dionne173f29e2019-05-29 16:01:36 +00004060}
Vedant Kumar55e007e2018-03-08 21:15:26 +00004061
Howard Hinnantc51e1022010-05-11 19:42:16 +00004062// operator==
4063
4064template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004065inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
Howard Hinnantc51e1022010-05-11 19:42:16 +00004066bool
4067operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004068 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004069{
Mark de Weverb4830e62022-07-19 07:56:23 +02004070#if _LIBCPP_STD_VER > 17
4071 return basic_string_view<_CharT, _Traits>(__lhs) == basic_string_view<_CharT, _Traits>(__rhs);
4072#else
Howard Hinnantaaeb1132013-04-22 23:55:13 +00004073 size_t __lhs_sz = __lhs.size();
4074 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
4075 __rhs.data(),
4076 __lhs_sz) == 0;
Mark de Weverb4830e62022-07-19 07:56:23 +02004077#endif
Howard Hinnantaaeb1132013-04-22 23:55:13 +00004078}
4079
4080template<class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004081inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
Howard Hinnantaaeb1132013-04-22 23:55:13 +00004082bool
4083operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
4084 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
4085{
4086 size_t __lhs_sz = __lhs.size();
4087 if (__lhs_sz != __rhs.size())
4088 return false;
4089 const char* __lp = __lhs.data();
4090 const char* __rp = __rhs.data();
4091 if (__lhs.__is_long())
4092 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
4093 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
4094 if (*__lp != *__rp)
4095 return false;
4096 return true;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004097}
4098
Mark de Weverb4830e62022-07-19 07:56:23 +02004099#if _LIBCPP_STD_VER <= 17
Howard Hinnantc51e1022010-05-11 19:42:16 +00004100template<class _CharT, class _Traits, class _Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +02004101inline _LIBCPP_HIDE_FROM_ABI
Howard Hinnantc51e1022010-05-11 19:42:16 +00004102bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004103operator==(const _CharT* __lhs,
4104 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004105{
Eric Fiselier0cafa3f2015-08-28 03:02:37 +00004106 typedef basic_string<_CharT, _Traits, _Allocator> _String;
4107 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
4108 size_t __lhs_len = _Traits::length(__lhs);
4109 if (__lhs_len != __rhs.size()) return false;
4110 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004111}
Mark de Weverb4830e62022-07-19 07:56:23 +02004112#endif // _LIBCPP_STD_VER <= 17
Howard Hinnantc51e1022010-05-11 19:42:16 +00004113
Howard Hinnantc51e1022010-05-11 19:42:16 +00004114template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004115inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
Howard Hinnantc51e1022010-05-11 19:42:16 +00004116bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004117operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
4118 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004119{
Mark de Weverb4830e62022-07-19 07:56:23 +02004120#if _LIBCPP_STD_VER > 17
4121 return basic_string_view<_CharT, _Traits>(__lhs) == basic_string_view<_CharT, _Traits>(__rhs);
4122#else
Eric Fiselier0cafa3f2015-08-28 03:02:37 +00004123 typedef basic_string<_CharT, _Traits, _Allocator> _String;
4124 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
4125 size_t __rhs_len = _Traits::length(__rhs);
4126 if (__rhs_len != __lhs.size()) return false;
4127 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Mark de Weverb4830e62022-07-19 07:56:23 +02004128#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00004129}
4130
Mark de Weverb4830e62022-07-19 07:56:23 +02004131#if _LIBCPP_STD_VER > 17
4132
4133template <class _CharT, class _Traits, class _Allocator>
4134_LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>(
4135 const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4136 const basic_string<_CharT, _Traits, _Allocator>& __rhs) noexcept {
4137 return basic_string_view<_CharT, _Traits>(__lhs) <=> basic_string_view<_CharT, _Traits>(__rhs);
4138}
4139
4140template <class _CharT, class _Traits, class _Allocator>
4141_LIBCPP_HIDE_FROM_ABI constexpr auto
4142operator<=>(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) {
4143 return basic_string_view<_CharT, _Traits>(__lhs) <=> basic_string_view<_CharT, _Traits>(__rhs);
4144}
4145
4146#else // _LIBCPP_STD_VER > 17
4147
Howard Hinnant3b6579a2010-08-22 00:02:43 +00004148template<class _CharT, class _Traits, class _Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +02004149inline _LIBCPP_HIDE_FROM_ABI
Howard Hinnantc51e1022010-05-11 19:42:16 +00004150bool
4151operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004152 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004153{
4154 return !(__lhs == __rhs);
4155}
4156
4157template<class _CharT, class _Traits, class _Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +02004158inline _LIBCPP_HIDE_FROM_ABI
Howard Hinnantc51e1022010-05-11 19:42:16 +00004159bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004160operator!=(const _CharT* __lhs,
4161 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004162{
4163 return !(__lhs == __rhs);
4164}
4165
4166template<class _CharT, class _Traits, class _Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +02004167inline _LIBCPP_HIDE_FROM_ABI
Howard Hinnantc51e1022010-05-11 19:42:16 +00004168bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004169operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4170 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004171{
4172 return !(__lhs == __rhs);
4173}
4174
4175// operator<
4176
4177template<class _CharT, class _Traits, class _Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +02004178inline _LIBCPP_HIDE_FROM_ABI
Howard Hinnantc51e1022010-05-11 19:42:16 +00004179bool
4180operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004181 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004182{
Howard Hinnanta2660c12011-07-24 15:07:21 +00004183 return __lhs.compare(__rhs) < 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004184}
4185
4186template<class _CharT, class _Traits, class _Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +02004187inline _LIBCPP_HIDE_FROM_ABI
Howard Hinnantc51e1022010-05-11 19:42:16 +00004188bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004189operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4190 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004191{
Howard Hinnanta2660c12011-07-24 15:07:21 +00004192 return __lhs.compare(__rhs) < 0;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004193}
4194
4195template<class _CharT, class _Traits, class _Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +02004196inline _LIBCPP_HIDE_FROM_ABI
Howard Hinnantc51e1022010-05-11 19:42:16 +00004197bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004198operator< (const _CharT* __lhs,
4199 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004200{
4201 return __rhs.compare(__lhs) > 0;
4202}
4203
Howard Hinnantc51e1022010-05-11 19:42:16 +00004204// operator>
4205
4206template<class _CharT, class _Traits, class _Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +02004207inline _LIBCPP_HIDE_FROM_ABI
Howard Hinnantc51e1022010-05-11 19:42:16 +00004208bool
4209operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004210 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004211{
4212 return __rhs < __lhs;
4213}
4214
4215template<class _CharT, class _Traits, class _Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +02004216inline _LIBCPP_HIDE_FROM_ABI
Howard Hinnantc51e1022010-05-11 19:42:16 +00004217bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004218operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4219 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004220{
4221 return __rhs < __lhs;
4222}
4223
4224template<class _CharT, class _Traits, class _Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +02004225inline _LIBCPP_HIDE_FROM_ABI
Howard Hinnantc51e1022010-05-11 19:42:16 +00004226bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004227operator> (const _CharT* __lhs,
4228 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004229{
4230 return __rhs < __lhs;
4231}
4232
4233// operator<=
4234
4235template<class _CharT, class _Traits, class _Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +02004236inline _LIBCPP_HIDE_FROM_ABI
Howard Hinnantc51e1022010-05-11 19:42:16 +00004237bool
4238operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004239 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004240{
4241 return !(__rhs < __lhs);
4242}
4243
4244template<class _CharT, class _Traits, class _Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +02004245inline _LIBCPP_HIDE_FROM_ABI
Howard Hinnantc51e1022010-05-11 19:42:16 +00004246bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004247operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4248 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004249{
4250 return !(__rhs < __lhs);
4251}
4252
4253template<class _CharT, class _Traits, class _Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +02004254inline _LIBCPP_HIDE_FROM_ABI
Howard Hinnantc51e1022010-05-11 19:42:16 +00004255bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004256operator<=(const _CharT* __lhs,
4257 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004258{
4259 return !(__rhs < __lhs);
4260}
4261
4262// operator>=
4263
4264template<class _CharT, class _Traits, class _Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +02004265inline _LIBCPP_HIDE_FROM_ABI
Howard Hinnantc51e1022010-05-11 19:42:16 +00004266bool
4267operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004268 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004269{
4270 return !(__lhs < __rhs);
4271}
4272
4273template<class _CharT, class _Traits, class _Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +02004274inline _LIBCPP_HIDE_FROM_ABI
Howard Hinnantc51e1022010-05-11 19:42:16 +00004275bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004276operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4277 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004278{
4279 return !(__lhs < __rhs);
4280}
4281
4282template<class _CharT, class _Traits, class _Allocator>
Mark de Weveraf1968a2022-08-14 14:14:09 +02004283inline _LIBCPP_HIDE_FROM_ABI
Howard Hinnantc51e1022010-05-11 19:42:16 +00004284bool
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004285operator>=(const _CharT* __lhs,
4286 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00004287{
4288 return !(__lhs < __rhs);
4289}
Mark de Weverb4830e62022-07-19 07:56:23 +02004290#endif // _LIBCPP_STD_VER > 17
Howard Hinnantc51e1022010-05-11 19:42:16 +00004291
4292// operator +
4293
4294template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004295_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00004296basic_string<_CharT, _Traits, _Allocator>
4297operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
4298 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4299{
Nikolas Klauser38631bf2022-02-11 19:24:31 +01004300 using _String = basic_string<_CharT, _Traits, _Allocator>;
Nikolas Klauser55dc8082022-04-09 16:19:45 +02004301 auto __lhs_sz = __lhs.size();
4302 auto __rhs_sz = __rhs.size();
4303 _String __r(__uninitialized_size_tag(),
4304 __lhs_sz + __rhs_sz,
4305 _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
4306 auto __ptr = std::__to_address(__r.__get_pointer());
4307 _Traits::copy(__ptr, __lhs.data(), __lhs_sz);
4308 _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz);
4309 _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004310 return __r;
4311}
4312
4313template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004314_LIBCPP_HIDDEN _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00004315basic_string<_CharT, _Traits, _Allocator>
4316operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4317{
Nikolas Klauser38631bf2022-02-11 19:24:31 +01004318 using _String = basic_string<_CharT, _Traits, _Allocator>;
Nikolas Klauser55dc8082022-04-09 16:19:45 +02004319 auto __lhs_sz = _Traits::length(__lhs);
4320 auto __rhs_sz = __rhs.size();
4321 _String __r(__uninitialized_size_tag(),
4322 __lhs_sz + __rhs_sz,
4323 _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator()));
4324 auto __ptr = std::__to_address(__r.__get_pointer());
4325 _Traits::copy(__ptr, __lhs, __lhs_sz);
4326 _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz);
4327 _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004328 return __r;
4329}
4330
4331template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004332_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00004333basic_string<_CharT, _Traits, _Allocator>
4334operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
4335{
Nikolas Klauser38631bf2022-02-11 19:24:31 +01004336 using _String = basic_string<_CharT, _Traits, _Allocator>;
Nikolas Klauser38631bf2022-02-11 19:24:31 +01004337 typename _String::size_type __rhs_sz = __rhs.size();
Nikolas Klauser55dc8082022-04-09 16:19:45 +02004338 _String __r(__uninitialized_size_tag(),
4339 __rhs_sz + 1,
4340 _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator()));
4341 auto __ptr = std::__to_address(__r.__get_pointer());
4342 _Traits::assign(__ptr, 1, __lhs);
4343 _Traits::copy(__ptr + 1, __rhs.data(), __rhs_sz);
4344 _Traits::assign(__ptr + 1 + __rhs_sz, 1, _CharT());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004345 return __r;
4346}
4347
4348template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004349inline _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00004350basic_string<_CharT, _Traits, _Allocator>
4351operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
4352{
Nikolas Klauser38631bf2022-02-11 19:24:31 +01004353 using _String = basic_string<_CharT, _Traits, _Allocator>;
Nikolas Klauser38631bf2022-02-11 19:24:31 +01004354 typename _String::size_type __lhs_sz = __lhs.size();
4355 typename _String::size_type __rhs_sz = _Traits::length(__rhs);
Nikolas Klauser55dc8082022-04-09 16:19:45 +02004356 _String __r(__uninitialized_size_tag(),
4357 __lhs_sz + __rhs_sz,
4358 _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
4359 auto __ptr = std::__to_address(__r.__get_pointer());
4360 _Traits::copy(__ptr, __lhs.data(), __lhs_sz);
4361 _Traits::copy(__ptr + __lhs_sz, __rhs, __rhs_sz);
4362 _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004363 return __r;
4364}
4365
4366template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004367_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00004368basic_string<_CharT, _Traits, _Allocator>
4369operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
4370{
Nikolas Klauser38631bf2022-02-11 19:24:31 +01004371 using _String = basic_string<_CharT, _Traits, _Allocator>;
Nikolas Klauser38631bf2022-02-11 19:24:31 +01004372 typename _String::size_type __lhs_sz = __lhs.size();
Nikolas Klauser55dc8082022-04-09 16:19:45 +02004373 _String __r(__uninitialized_size_tag(),
4374 __lhs_sz + 1,
4375 _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator()));
4376 auto __ptr = std::__to_address(__r.__get_pointer());
4377 _Traits::copy(__ptr, __lhs.data(), __lhs_sz);
4378 _Traits::assign(__ptr + __lhs_sz, 1, __rhs);
4379 _Traits::assign(__ptr + 1 + __lhs_sz, 1, _CharT());
Howard Hinnantc51e1022010-05-11 19:42:16 +00004380 return __r;
4381}
4382
Eric Fiselierfc92be82017-04-19 00:28:44 +00004383#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00004384
4385template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004386inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00004387basic_string<_CharT, _Traits, _Allocator>
4388operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4389{
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02004390 return std::move(__lhs.append(__rhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004391}
4392
4393template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004394inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00004395basic_string<_CharT, _Traits, _Allocator>
4396operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4397{
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02004398 return std::move(__rhs.insert(0, __lhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004399}
4400
4401template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004402inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00004403basic_string<_CharT, _Traits, _Allocator>
4404operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4405{
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02004406 return std::move(__lhs.append(__rhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004407}
4408
4409template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004410inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00004411basic_string<_CharT, _Traits, _Allocator>
4412operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4413{
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02004414 return std::move(__rhs.insert(0, __lhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004415}
4416
4417template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004418inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00004419basic_string<_CharT, _Traits, _Allocator>
4420operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4421{
4422 __rhs.insert(__rhs.begin(), __lhs);
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02004423 return std::move(__rhs);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004424}
4425
4426template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004427inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00004428basic_string<_CharT, _Traits, _Allocator>
4429operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
4430{
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02004431 return std::move(__lhs.append(__rhs));
Howard Hinnantc51e1022010-05-11 19:42:16 +00004432}
4433
4434template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004435inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00004436basic_string<_CharT, _Traits, _Allocator>
4437operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
4438{
4439 __lhs.push_back(__rhs);
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02004440 return std::move(__lhs);
Howard Hinnantc51e1022010-05-11 19:42:16 +00004441}
4442
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04004443#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00004444
4445// swap
4446
4447template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004448inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnantc51e1022010-05-11 19:42:16 +00004449void
Howard Hinnantaeb17d82011-05-29 19:57:12 +00004450swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant3e276872011-06-03 18:40:47 +00004451 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4452 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantc51e1022010-05-11 19:42:16 +00004453{
4454 __lhs.swap(__rhs);
4455}
4456
Bruce Mitchener170d8972020-11-24 12:53:53 -05004457_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = nullptr, int __base = 10);
4458_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = nullptr, int __base = 10);
4459_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = nullptr, int __base = 10);
4460_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = nullptr, int __base = 10);
4461_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = nullptr, int __base = 10);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004462
Bruce Mitchener170d8972020-11-24 12:53:53 -05004463_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = nullptr);
4464_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = nullptr);
4465_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = nullptr);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004466
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004467_LIBCPP_FUNC_VIS string to_string(int __val);
4468_LIBCPP_FUNC_VIS string to_string(unsigned __val);
4469_LIBCPP_FUNC_VIS string to_string(long __val);
4470_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4471_LIBCPP_FUNC_VIS string to_string(long long __val);
4472_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4473_LIBCPP_FUNC_VIS string to_string(float __val);
4474_LIBCPP_FUNC_VIS string to_string(double __val);
4475_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004476
Louis Dionne89258142021-08-23 15:32:36 -04004477#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Bruce Mitchener170d8972020-11-24 12:53:53 -05004478_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
4479_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
4480_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
4481_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = nullptr, int __base = 10);
4482_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = nullptr, int __base = 10);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004483
Bruce Mitchener170d8972020-11-24 12:53:53 -05004484_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = nullptr);
4485_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = nullptr);
4486_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = nullptr);
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004487
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00004488_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4489_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4490_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4491_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4492_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4493_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4494_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4495_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4496_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Louis Dionne89258142021-08-23 15:32:36 -04004497#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
Howard Hinnanta5f4f8e2010-06-02 18:20:39 +00004498
Howard Hinnantc51e1022010-05-11 19:42:16 +00004499template<class _CharT, class _Traits, class _Allocator>
Martin Storsjö88890c22021-02-22 01:13:13 +02004500_LIBCPP_TEMPLATE_DATA_VIS
Eric Fiselierc9fdaf12020-01-15 17:02:17 -05004501const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4502 basic_string<_CharT, _Traits, _Allocator>::npos;
Howard Hinnantc51e1022010-05-11 19:42:16 +00004503
Marshall Clow851b9ec2019-05-20 21:56:51 +00004504template <class _CharT, class _Allocator>
Nikolas Klauser3ab26e32022-08-22 02:59:09 +02004505struct __string_hash : public __unary_function<basic_string<_CharT, char_traits<_CharT>, _Allocator>, size_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00004506{
4507 size_t
Marshall Clow851b9ec2019-05-20 21:56:51 +00004508 operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT
4509 { return __do_string_hash(__val.data(), __val.data() + __val.size()); }
Howard Hinnantc51e1022010-05-11 19:42:16 +00004510};
4511
Nikolas Klauser3ab26e32022-08-22 02:59:09 +02004512template <class _Allocator>
4513struct hash<basic_string<char, char_traits<char>, _Allocator> > : __string_hash<char, _Allocator> {};
4514
4515#ifndef _LIBCPP_HAS_NO_CHAR8_T
4516template <class _Allocator>
4517struct hash<basic_string<char8_t, char_traits<char8_t>, _Allocator> > : __string_hash<char8_t, _Allocator> {};
4518#endif
4519
4520template <class _Allocator>
4521struct hash<basic_string<char16_t, char_traits<char16_t>, _Allocator> > : __string_hash<char16_t, _Allocator> {};
4522
4523template <class _Allocator>
4524struct hash<basic_string<char32_t, char_traits<char32_t>, _Allocator> > : __string_hash<char32_t, _Allocator> {};
4525
4526#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4527template <class _Allocator>
4528struct hash<basic_string<wchar_t, char_traits<wchar_t>, _Allocator> > : __string_hash<wchar_t, _Allocator> {};
4529#endif
4530
Howard Hinnantdc095972011-07-18 15:51:59 +00004531template<class _CharT, class _Traits, class _Allocator>
Nikolas Klausera9ad6702022-08-13 13:23:16 +02004532_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
Howard Hinnantdc095972011-07-18 15:51:59 +00004533operator<<(basic_ostream<_CharT, _Traits>& __os,
4534 const basic_string<_CharT, _Traits, _Allocator>& __str);
4535
4536template<class _CharT, class _Traits, class _Allocator>
Nikolas Klausera9ad6702022-08-13 13:23:16 +02004537_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
Howard Hinnantdc095972011-07-18 15:51:59 +00004538operator>>(basic_istream<_CharT, _Traits>& __is,
4539 basic_string<_CharT, _Traits, _Allocator>& __str);
4540
4541template<class _CharT, class _Traits, class _Allocator>
Nikolas Klausera9ad6702022-08-13 13:23:16 +02004542_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>&
Howard Hinnantdc095972011-07-18 15:51:59 +00004543getline(basic_istream<_CharT, _Traits>& __is,
4544 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4545
4546template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02004547inline _LIBCPP_HIDE_FROM_ABI
Howard Hinnantdc095972011-07-18 15:51:59 +00004548basic_istream<_CharT, _Traits>&
4549getline(basic_istream<_CharT, _Traits>& __is,
4550 basic_string<_CharT, _Traits, _Allocator>& __str);
4551
Howard Hinnantdc095972011-07-18 15:51:59 +00004552template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02004553inline _LIBCPP_HIDE_FROM_ABI
Howard Hinnantdc095972011-07-18 15:51:59 +00004554basic_istream<_CharT, _Traits>&
4555getline(basic_istream<_CharT, _Traits>&& __is,
4556 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4557
4558template<class _CharT, class _Traits, class _Allocator>
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02004559inline _LIBCPP_HIDE_FROM_ABI
Howard Hinnantdc095972011-07-18 15:51:59 +00004560basic_istream<_CharT, _Traits>&
4561getline(basic_istream<_CharT, _Traits>&& __is,
4562 basic_string<_CharT, _Traits, _Allocator>& __str);
4563
Marshall Clow29b53f22018-12-14 18:49:35 +00004564#if _LIBCPP_STD_VER > 17
Marek Kurdeja98b1412020-05-02 13:58:03 +02004565template <class _CharT, class _Traits, class _Allocator, class _Up>
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02004566inline _LIBCPP_HIDE_FROM_ABI
Marek Kurdeja98b1412020-05-02 13:58:03 +02004567 typename basic_string<_CharT, _Traits, _Allocator>::size_type
4568 erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v) {
4569 auto __old_size = __str.size();
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02004570 __str.erase(std::remove(__str.begin(), __str.end(), __v), __str.end());
Marek Kurdeja98b1412020-05-02 13:58:03 +02004571 return __old_size - __str.size();
4572}
Marshall Clow29b53f22018-12-14 18:49:35 +00004573
Marek Kurdeja98b1412020-05-02 13:58:03 +02004574template <class _CharT, class _Traits, class _Allocator, class _Predicate>
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02004575inline _LIBCPP_HIDE_FROM_ABI
Marek Kurdeja98b1412020-05-02 13:58:03 +02004576 typename basic_string<_CharT, _Traits, _Allocator>::size_type
4577 erase_if(basic_string<_CharT, _Traits, _Allocator>& __str,
4578 _Predicate __pred) {
4579 auto __old_size = __str.size();
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02004580 __str.erase(std::remove_if(__str.begin(), __str.end(), __pred),
Marek Kurdeja98b1412020-05-02 13:58:03 +02004581 __str.end());
4582 return __old_size - __str.size();
4583}
Marshall Clow29b53f22018-12-14 18:49:35 +00004584#endif
4585
Louis Dionne510450b2022-04-01 16:38:30 -04004586#ifdef _LIBCPP_ENABLE_DEBUG_MODE
Howard Hinnant8ea98242013-08-23 17:37:05 +00004587
4588template<class _CharT, class _Traits, class _Allocator>
4589bool
4590basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4591{
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02004592 return data() <= std::__to_address(__i->base()) &&
4593 std::__to_address(__i->base()) < data() + size();
Howard Hinnant8ea98242013-08-23 17:37:05 +00004594}
4595
4596template<class _CharT, class _Traits, class _Allocator>
4597bool
4598basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4599{
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02004600 return data() < std::__to_address(__i->base()) &&
4601 std::__to_address(__i->base()) <= data() + size();
Howard Hinnant8ea98242013-08-23 17:37:05 +00004602}
4603
4604template<class _CharT, class _Traits, class _Allocator>
4605bool
4606basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4607{
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02004608 const value_type* __p = std::__to_address(__i->base()) + __n;
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01004609 return data() <= __p && __p <= data() + size();
Howard Hinnant8ea98242013-08-23 17:37:05 +00004610}
4611
4612template<class _CharT, class _Traits, class _Allocator>
4613bool
4614basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4615{
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02004616 const value_type* __p = std::__to_address(__i->base()) + __n;
Nikolas Klauser00ba7f82021-12-28 13:09:40 +01004617 return data() <= __p && __p < data() + size();
Howard Hinnant8ea98242013-08-23 17:37:05 +00004618}
4619
Louis Dionne510450b2022-04-01 16:38:30 -04004620#endif // _LIBCPP_ENABLE_DEBUG_MODE
Howard Hinnant8ea98242013-08-23 17:37:05 +00004621
Louis Dionne173f29e2019-05-29 16:01:36 +00004622#if _LIBCPP_STD_VER > 11
Marshall Clowcba751f2013-07-23 17:05:24 +00004623// Literal suffixes for basic_string [basic.string.literals]
Marshall Clowac868372013-10-05 21:18:32 +00004624inline namespace literals
Marshall Clowcba751f2013-07-23 17:05:24 +00004625{
4626 inline namespace string_literals
4627 {
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004628 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnant5c167562013-08-07 19:39:48 +00004629 basic_string<char> operator "" s( const char *__str, size_t __len )
4630 {
4631 return basic_string<char> (__str, __len);
4632 }
Marshall Clowcba751f2013-07-23 17:05:24 +00004633
Louis Dionne89258142021-08-23 15:32:36 -04004634#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004635 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnant5c167562013-08-07 19:39:48 +00004636 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4637 {
4638 return basic_string<wchar_t> (__str, __len);
4639 }
Louis Dionne89258142021-08-23 15:32:36 -04004640#endif
Marshall Clowcba751f2013-07-23 17:05:24 +00004641
Arthur O'Dwyerafa5d5f2021-04-18 21:47:08 -04004642#ifndef _LIBCPP_HAS_NO_CHAR8_T
Nikolas Klauser1d5108d2022-04-29 11:17:58 +02004643 inline _LIBCPP_HIDE_FROM_ABI constexpr
Nikolas Klauser5da956d2022-09-02 16:20:28 +02004644 basic_string<char8_t> operator "" s(const char8_t *__str, size_t __len)
Marshall Clow8732fed2018-12-11 04:35:44 +00004645 {
4646 return basic_string<char8_t> (__str, __len);
4647 }
4648#endif
4649
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004650 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnant5c167562013-08-07 19:39:48 +00004651 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4652 {
4653 return basic_string<char16_t> (__str, __len);
4654 }
Marshall Clowcba751f2013-07-23 17:05:24 +00004655
Nikolas Klauser8b1c5062022-08-19 13:08:01 +02004656 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
Howard Hinnant5c167562013-08-07 19:39:48 +00004657 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4658 {
4659 return basic_string<char32_t> (__str, __len);
4660 }
Nikolas Klauserd26407a2021-12-02 14:12:51 +01004661 } // namespace string_literals
4662} // namespace literals
Mark de Weverdf3e0d42021-09-26 15:47:42 +02004663
4664#if _LIBCPP_STD_VER > 17
4665template <>
4666inline constexpr bool __format::__enable_insertable<std::basic_string<char>> = true;
4667#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4668template <>
4669inline constexpr bool __format::__enable_insertable<std::basic_string<wchar_t>> = true;
4670#endif
4671#endif
4672
Marshall Clowcba751f2013-07-23 17:05:24 +00004673#endif
4674
Howard Hinnantc51e1022010-05-11 19:42:16 +00004675_LIBCPP_END_NAMESPACE_STD
4676
Arthur O'Dwyerebf2d342022-10-06 16:53:30 -04004677#if _LIBCPP_STD_VER > 14
4678_LIBCPP_BEGIN_NAMESPACE_STD
4679namespace pmr {
4680template <class _CharT, class _TraitsT = std::char_traits<_CharT>>
4681using basic_string = std::basic_string<_CharT, _TraitsT, polymorphic_allocator<_CharT>>;
4682
4683using string = basic_string<char>;
4684using u16string = basic_string<char16_t>;
4685using u32string = basic_string<char32_t>;
4686using wstring = basic_string<wchar_t>;
4687} // namespace pmr
4688_LIBCPP_END_NAMESPACE_STD
4689#endif
4690
Eric Fiselierf4433a32017-05-31 22:07:49 +00004691_LIBCPP_POP_MACROS
4692
Mark de Weveree5fe272022-09-02 17:53:28 +02004693#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
4694# include <algorithm>
4695# include <functional>
4696# include <iterator>
4697# include <new>
4698# include <typeinfo>
4699# include <utility>
4700# include <vector>
4701#endif
4702
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04004703#endif // _LIBCPP_STRING