blob: 39bda49280f10bfbbfbec073e511a983a4ff0673 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- string -----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_STRING
12#define _LIBCPP_STRING
13
14/*
15 string synopsis
16
17namespace std
18{
19
20template <class stateT>
21class fpos
22{
23private:
24 stateT st;
25public:
26 fpos(streamoff = streamoff());
27
28 operator streamoff() const;
29
30 stateT state() const;
31 void state(stateT);
32
33 fpos& operator+=(streamoff);
34 fpos operator+ (streamoff) const;
35 fpos& operator-=(streamoff);
36 fpos operator- (streamoff) const;
37};
38
39template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y);
40
41template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y);
42template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y);
43
44template <class charT>
45struct char_traits
46{
47 typedef charT char_type;
48 typedef ... int_type;
49 typedef streamoff off_type;
50 typedef streampos pos_type;
51 typedef mbstate_t state_type;
52
Howard Hinnanta6119a82011-05-29 19:57:12 +000053 static void assign(char_type& c1, const char_type& c2) noexcept;
Howard Hinnant03d71812012-07-20 19:09:12 +000054 static constexpr bool eq(char_type c1, char_type c2) noexcept;
55 static constexpr bool lt(char_type c1, char_type c2) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056
57 static int compare(const char_type* s1, const char_type* s2, size_t n);
58 static size_t length(const char_type* s);
59 static const char_type* find(const char_type* s, size_t n, const char_type& a);
60 static char_type* move(char_type* s1, const char_type* s2, size_t n);
61 static char_type* copy(char_type* s1, const char_type* s2, size_t n);
62 static char_type* assign(char_type* s, size_t n, char_type a);
63
Howard Hinnant03d71812012-07-20 19:09:12 +000064 static constexpr int_type not_eof(int_type c) noexcept;
65 static constexpr char_type to_char_type(int_type c) noexcept;
66 static constexpr int_type to_int_type(char_type c) noexcept;
67 static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept;
68 static constexpr int_type eof() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000069};
70
71template <> struct char_traits<char>;
72template <> struct char_traits<wchar_t>;
73
Howard Hinnant324bb032010-08-22 00:02:43 +000074template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000075class basic_string
76{
Howard Hinnant324bb032010-08-22 00:02:43 +000077public:
78// types:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000079 typedef traits traits_type;
80 typedef typename traits_type::char_type value_type;
81 typedef Allocator allocator_type;
82 typedef typename allocator_type::size_type size_type;
83 typedef typename allocator_type::difference_type difference_type;
84 typedef typename allocator_type::reference reference;
85 typedef typename allocator_type::const_reference const_reference;
86 typedef typename allocator_type::pointer pointer;
87 typedef typename allocator_type::const_pointer const_pointer;
88 typedef implementation-defined iterator;
89 typedef implementation-defined const_iterator;
90 typedef std::reverse_iterator<iterator> reverse_iterator;
91 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
92
93 static const size_type npos = -1;
94
Howard Hinnant53f7d4c2011-06-03 18:40:47 +000095 basic_string()
96 noexcept(is_nothrow_default_constructible<allocator_type>::value);
97 explicit basic_string(const allocator_type& a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000098 basic_string(const basic_string& str);
Howard Hinnant53f7d4c2011-06-03 18:40:47 +000099 basic_string(basic_string&& str)
100 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000101 basic_string(const basic_string& str, size_type pos,
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000102 const allocator_type& a = allocator_type());
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000103 basic_string(const basic_string& str, size_type pos, size_type n,
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000104 const Allocator& a = Allocator());
105 explicit basic_string(const basic_string_view<charT, traits> sv, const Allocator& a = Allocator());
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000106 basic_string(const value_type* s, const allocator_type& a = allocator_type());
107 basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000108 basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
109 template<class InputIterator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000110 basic_string(InputIterator begin, InputIterator end,
111 const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000112 basic_string(initializer_list<value_type>, const Allocator& = Allocator());
113 basic_string(const basic_string&, const Allocator&);
114 basic_string(basic_string&&, const Allocator&);
115
116 ~basic_string();
117
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000118 operator basic_string_view<charT, traits>() const noexcept;
119
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000120 basic_string& operator=(const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000121 basic_string& operator=(basic_string_view<charT, traits> sv);
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000122 basic_string& operator=(basic_string&& str)
123 noexcept(
Marshall Clowaf961ed2015-08-18 18:57:00 +0000124 allocator_type::propagate_on_container_move_assignment::value ||
125 allocator_type::is_always_equal::value ); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000126 basic_string& operator=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000127 basic_string& operator=(value_type c);
128 basic_string& operator=(initializer_list<value_type>);
129
Howard Hinnanta6119a82011-05-29 19:57:12 +0000130 iterator begin() noexcept;
131 const_iterator begin() const noexcept;
132 iterator end() noexcept;
133 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000134
Howard Hinnanta6119a82011-05-29 19:57:12 +0000135 reverse_iterator rbegin() noexcept;
136 const_reverse_iterator rbegin() const noexcept;
137 reverse_iterator rend() noexcept;
138 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000139
Howard Hinnanta6119a82011-05-29 19:57:12 +0000140 const_iterator cbegin() const noexcept;
141 const_iterator cend() const noexcept;
142 const_reverse_iterator crbegin() const noexcept;
143 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000144
Howard Hinnanta6119a82011-05-29 19:57:12 +0000145 size_type size() const noexcept;
146 size_type length() const noexcept;
147 size_type max_size() const noexcept;
148 size_type capacity() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000149
150 void resize(size_type n, value_type c);
151 void resize(size_type n);
152
153 void reserve(size_type res_arg = 0);
154 void shrink_to_fit();
Howard Hinnanta6119a82011-05-29 19:57:12 +0000155 void clear() noexcept;
156 bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000157
158 const_reference operator[](size_type pos) const;
159 reference operator[](size_type pos);
160
161 const_reference at(size_type n) const;
162 reference at(size_type n);
163
164 basic_string& operator+=(const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000165 basic_string& operator+=(basic_string_view<charT, traits> sv);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000166 basic_string& operator+=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000167 basic_string& operator+=(value_type c);
168 basic_string& operator+=(initializer_list<value_type>);
169
170 basic_string& append(const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000171 basic_string& append(basic_string_view<charT, traits> sv);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000172 basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000173 basic_string& append(basic_string_view<charT, traits> sv, size_type pos, size_type n=npos); //C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000174 basic_string& append(const value_type* s, size_type n);
175 basic_string& append(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000176 basic_string& append(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000177 template<class InputIterator>
178 basic_string& append(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000179 basic_string& append(initializer_list<value_type>);
180
181 void push_back(value_type c);
182 void pop_back();
183 reference front();
184 const_reference front() const;
185 reference back();
186 const_reference back() const;
187
188 basic_string& assign(const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000189 basic_string& assign(basic_string_view<charT, traits> sv);
Howard Hinnanta6119a82011-05-29 19:57:12 +0000190 basic_string& assign(basic_string&& str);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000191 basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000192 basic_string& assign(basic_string_view<charT, traits> sv, size_type pos, size_type n=npos); // C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000193 basic_string& assign(const value_type* s, size_type n);
194 basic_string& assign(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000195 basic_string& assign(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000196 template<class InputIterator>
197 basic_string& assign(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000198 basic_string& assign(initializer_list<value_type>);
199
200 basic_string& insert(size_type pos1, const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000201 basic_string& insert(size_type pos1, basic_string_view<charT, traits> sv);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000202 basic_string& insert(size_type pos1, const basic_string& str,
203 size_type pos2, size_type n);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000204 basic_string& insert(size_type pos1, basic_string_view<charT, traits> sv,
205 size_type pos2, size_type n);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000206 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000207 basic_string& insert(size_type pos, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000208 basic_string& insert(size_type pos, size_type n, value_type c);
209 iterator insert(const_iterator p, value_type c);
210 iterator insert(const_iterator p, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000211 template<class InputIterator>
212 iterator insert(const_iterator p, InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000213 iterator insert(const_iterator p, initializer_list<value_type>);
214
215 basic_string& erase(size_type pos = 0, size_type n = npos);
216 iterator erase(const_iterator position);
217 iterator erase(const_iterator first, const_iterator last);
218
219 basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000220 basic_string& replace(size_type pos1, size_type n1, basic_string_view<charT, traits> sv);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000221 basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000222 size_type pos2, size_type n2=npos); // C++14
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000223 basic_string& replace(size_type pos1, size_type n1, basic_string_view<charT, traits> sv,
224 size_type pos2, size_type n2=npos); // C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000225 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
226 basic_string& replace(size_type pos, size_type n1, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000227 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000228 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000229 basic_string& replace(const_iterator i1, const_iterator i2, basic_string_view<charT, traits> sv);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000230 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
231 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000232 basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000233 template<class InputIterator>
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000234 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
235 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000236
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000237 size_type copy(value_type* s, size_type n, size_type pos = 0) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000238 basic_string substr(size_type pos = 0, size_type n = npos) const;
239
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000240 void swap(basic_string& str)
Marshall Clow7d914d12015-07-13 20:04:56 +0000241 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
242 allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000243
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000244 const value_type* c_str() const noexcept;
245 const value_type* data() const noexcept;
Marshall Clowf532a702016-03-08 15:44:30 +0000246 value_type* data() noexcept; // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000247
Howard Hinnanta6119a82011-05-29 19:57:12 +0000248 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000249
Howard Hinnanta6119a82011-05-29 19:57:12 +0000250 size_type find(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000251 size_type find(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000252 size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
253 size_type find(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000254 size_type find(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000255
Howard Hinnanta6119a82011-05-29 19:57:12 +0000256 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000257 size_type ffind(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000258 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
259 size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000260 size_type rfind(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000261
Howard Hinnanta6119a82011-05-29 19:57:12 +0000262 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000263 size_type find_first_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000264 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
265 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000266 size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000267
Howard Hinnanta6119a82011-05-29 19:57:12 +0000268 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000269 size_type find_last_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000270 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
271 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000272 size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000273
Howard Hinnanta6119a82011-05-29 19:57:12 +0000274 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000275 size_type find_first_not_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000276 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
277 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000278 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000279
Howard Hinnanta6119a82011-05-29 19:57:12 +0000280 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000281 size_type find_last_not_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000282 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
283 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000284 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000285
Howard Hinnanta6119a82011-05-29 19:57:12 +0000286 int compare(const basic_string& str) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000287 int compare(basic_string_view<charT, traits> sv) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000288 int compare(size_type pos1, size_type n1, const basic_string& str) const;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000289 int compare(size_type pos1, size_type n1, basic_string_view<charT, traits> sv) const;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000290 int compare(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000291 size_type pos2, size_type n2=npos) const; // C++14
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000292 int compare(size_type pos1, size_type n1, basic_string_view<charT, traits> sv,
293 size_type pos2, size_type n2=npos) const; // C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000294 int compare(const value_type* s) const noexcept;
295 int compare(size_type pos1, size_type n1, const value_type* s) const;
296 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000297
298 bool __invariants() const;
299};
300
301template<class charT, class traits, class Allocator>
302basic_string<charT, traits, Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000303operator+(const basic_string<charT, traits, Allocator>& lhs,
304 const basic_string<charT, traits, Allocator>& rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000305
306template<class charT, class traits, class Allocator>
307basic_string<charT, traits, Allocator>
308operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
309
310template<class charT, class traits, class Allocator>
311basic_string<charT, traits, Allocator>
312operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
313
314template<class charT, class traits, class Allocator>
315basic_string<charT, traits, Allocator>
316operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
317
318template<class charT, class traits, class Allocator>
319basic_string<charT, traits, Allocator>
320operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
321
322template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000323bool operator==(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000324 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000325
326template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000327bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000328
329template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000330bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000331
Howard Hinnant324bb032010-08-22 00:02:43 +0000332template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000333bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000334 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000335
336template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000337bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000338
339template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000340bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000341
342template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000343bool operator< (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000344 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000345
346template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000347bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000348
349template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000350bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000351
352template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000353bool operator> (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000354 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000355
356template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000357bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000358
359template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000360bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000361
362template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000363bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000364 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000365
366template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000367bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000368
369template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000370bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000371
372template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000373bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000374 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000375
376template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000377bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000378
379template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000380bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000381
382template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000383void swap(basic_string<charT, traits, Allocator>& lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000384 basic_string<charT, traits, Allocator>& rhs)
385 noexcept(noexcept(lhs.swap(rhs)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000386
387template<class charT, class traits, class Allocator>
388basic_istream<charT, traits>&
389operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
390
391template<class charT, class traits, class Allocator>
392basic_ostream<charT, traits>&
393operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
394
395template<class charT, class traits, class Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +0000396basic_istream<charT, traits>&
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000397getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
398 charT delim);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000399
400template<class charT, class traits, class Allocator>
401basic_istream<charT, traits>&
402getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
403
404typedef basic_string<char> string;
405typedef basic_string<wchar_t> wstring;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000406typedef basic_string<char16_t> u16string;
407typedef basic_string<char32_t> u32string;
408
409int stoi (const string& str, size_t* idx = 0, int base = 10);
410long stol (const string& str, size_t* idx = 0, int base = 10);
411unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
412long long stoll (const string& str, size_t* idx = 0, int base = 10);
413unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
414
415float stof (const string& str, size_t* idx = 0);
416double stod (const string& str, size_t* idx = 0);
417long double stold(const string& str, size_t* idx = 0);
418
419string to_string(int val);
420string to_string(unsigned val);
421string to_string(long val);
422string to_string(unsigned long val);
423string to_string(long long val);
424string to_string(unsigned long long val);
425string to_string(float val);
426string to_string(double val);
427string to_string(long double val);
428
429int stoi (const wstring& str, size_t* idx = 0, int base = 10);
430long stol (const wstring& str, size_t* idx = 0, int base = 10);
431unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
432long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
433unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
434
435float stof (const wstring& str, size_t* idx = 0);
436double stod (const wstring& str, size_t* idx = 0);
437long double stold(const wstring& str, size_t* idx = 0);
438
439wstring to_wstring(int val);
440wstring to_wstring(unsigned val);
441wstring to_wstring(long val);
442wstring to_wstring(unsigned long val);
443wstring to_wstring(long long val);
444wstring to_wstring(unsigned long long val);
445wstring to_wstring(float val);
446wstring to_wstring(double val);
447wstring to_wstring(long double val);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000448
449template <> struct hash<string>;
450template <> struct hash<u16string>;
451template <> struct hash<u32string>;
452template <> struct hash<wstring>;
453
Marshall Clow15234322013-07-23 17:05:24 +0000454basic_string<char> operator "" s( const char *str, size_t len ); // C++14
455basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
456basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
457basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
458
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000459} // std
460
461*/
462
463#include <__config>
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000464#include <string_view>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000465#include <iosfwd>
466#include <cstring>
Howard Hinnantadff4892010-05-24 17:49:41 +0000467#include <cstdio> // For EOF.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000468#include <cwchar>
469#include <algorithm>
470#include <iterator>
471#include <utility>
472#include <memory>
473#include <stdexcept>
474#include <type_traits>
475#include <initializer_list>
476#include <__functional_base>
477#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
478#include <cstdint>
479#endif
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000480
Howard Hinnant66c6f972011-11-29 16:45:27 +0000481#include <__undef_min_max>
482
Eric Fiselierb9536102014-08-10 23:53:08 +0000483#include <__debug>
484
Howard Hinnant08e17472011-10-17 20:05:10 +0000485#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000486#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000487#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000488
489_LIBCPP_BEGIN_NAMESPACE_STD
490
491// fpos
492
493template <class _StateT>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000494class _LIBCPP_TYPE_VIS_ONLY fpos
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000495{
496private:
497 _StateT __st_;
498 streamoff __off_;
499public:
500 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
501
502 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
503
504 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
505 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
506
507 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
508 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
509 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
510 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
511};
512
513template <class _StateT>
514inline _LIBCPP_INLINE_VISIBILITY
515streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
516 {return streamoff(__x) - streamoff(__y);}
517
518template <class _StateT>
519inline _LIBCPP_INLINE_VISIBILITY
520bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
521 {return streamoff(__x) == streamoff(__y);}
522
523template <class _StateT>
524inline _LIBCPP_INLINE_VISIBILITY
525bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
526 {return streamoff(__x) != streamoff(__y);}
527
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000528// basic_string
529
530template<class _CharT, class _Traits, class _Allocator>
531basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000532operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
533 const basic_string<_CharT, _Traits, _Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000534
535template<class _CharT, class _Traits, class _Allocator>
536basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000537operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000538
539template<class _CharT, class _Traits, class _Allocator>
540basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000541operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000542
543template<class _CharT, class _Traits, class _Allocator>
544basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000545operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000546
547template<class _CharT, class _Traits, class _Allocator>
548basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000549operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000550
551template <bool>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000552class _LIBCPP_TYPE_VIS_ONLY __basic_string_common
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000553{
554protected:
Marshall Clow14c09a22016-08-25 15:09:01 +0000555 _LIBCPP_NORETURN void __throw_length_error() const;
556 _LIBCPP_NORETURN void __throw_out_of_range() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000557};
558
559template <bool __b>
560void
561__basic_string_common<__b>::__throw_length_error() const
562{
Marshall Clow14c09a22016-08-25 15:09:01 +0000563 _VSTD::__throw_length_error("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000564}
565
566template <bool __b>
567void
568__basic_string_common<__b>::__throw_out_of_range() const
569{
Marshall Clow14c09a22016-08-25 15:09:01 +0000570 _VSTD::__throw_out_of_range("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000571}
572
Howard Hinnante9df0a52013-08-01 18:17:34 +0000573#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +0000574#pragma warning( push )
575#pragma warning( disable: 4231 )
Howard Hinnante9df0a52013-08-01 18:17:34 +0000576#endif // _LIBCPP_MSVC
Eric Fiselier833d6442016-09-15 22:27:07 +0000577_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>)
Howard Hinnante9df0a52013-08-01 18:17:34 +0000578#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +0000579#pragma warning( pop )
Howard Hinnante9df0a52013-08-01 18:17:34 +0000580#endif // _LIBCPP_MSVC
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000581
Marshall Clowdf9db312016-01-13 21:54:34 +0000582#ifdef _LIBCPP_NO_EXCEPTIONS
583template <class _Iter>
584struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
585#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
586template <class _Iter>
587struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
588#else
589template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
590struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
591 noexcept(++(declval<_Iter&>())) &&
592 is_nothrow_assignable<_Iter&, _Iter>::value &&
593 noexcept(declval<_Iter>() == declval<_Iter>()) &&
594 noexcept(*declval<_Iter>())
595)) {};
596
597template <class _Iter>
598struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
599#endif
600
601
602template <class _Iter>
603struct __libcpp_string_gets_noexcept_iterator
604 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
605
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000606#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000607
608template <class _CharT, size_t = sizeof(_CharT)>
609struct __padding
610{
611 unsigned char __xx[sizeof(_CharT)-1];
612};
613
614template <class _CharT>
615struct __padding<_CharT, 1>
616{
617};
618
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000619#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000620
Howard Hinnant324bb032010-08-22 00:02:43 +0000621template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000622class _LIBCPP_TYPE_VIS_ONLY basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000623 : private __basic_string_common<true>
624{
625public:
626 typedef basic_string __self;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000627 typedef basic_string_view<_CharT, _Traits> __self_view;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000628 typedef _Traits traits_type;
629 typedef typename traits_type::char_type value_type;
630 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000631 typedef allocator_traits<allocator_type> __alloc_traits;
632 typedef typename __alloc_traits::size_type size_type;
633 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000634 typedef value_type& reference;
635 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000636 typedef typename __alloc_traits::pointer pointer;
637 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000638
Howard Hinnant499cea12013-08-23 17:37:05 +0000639 static_assert(is_pod<value_type>::value, "Character type of basic_string must be a POD");
640 static_assert((is_same<_CharT, value_type>::value),
641 "traits_type::char_type must be the same type as CharT");
642 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
643 "Allocator::value_type must be same type as value_type");
644#if defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000645 typedef pointer iterator;
646 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000647#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000648 typedef __wrap_iter<pointer> iterator;
649 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000650#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000651 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
652 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000653
654private:
Howard Hinnant15467182013-04-30 21:44:48 +0000655
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000656#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000657
658 struct __long
659 {
660 pointer __data_;
661 size_type __size_;
662 size_type __cap_;
663 };
664
665#if _LIBCPP_BIG_ENDIAN
666 enum {__short_mask = 0x01};
667 enum {__long_mask = 0x1ul};
668#else // _LIBCPP_BIG_ENDIAN
669 enum {__short_mask = 0x80};
670 enum {__long_mask = ~(size_type(~0) >> 1)};
671#endif // _LIBCPP_BIG_ENDIAN
672
673 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
674 (sizeof(__long) - 1)/sizeof(value_type) : 2};
675
676 struct __short
677 {
678 value_type __data_[__min_cap];
679 struct
680 : __padding<value_type>
681 {
682 unsigned char __size_;
683 };
684 };
685
686#else
687
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000688 struct __long
689 {
690 size_type __cap_;
691 size_type __size_;
692 pointer __data_;
693 };
694
695#if _LIBCPP_BIG_ENDIAN
696 enum {__short_mask = 0x80};
697 enum {__long_mask = ~(size_type(~0) >> 1)};
Howard Hinnant324bb032010-08-22 00:02:43 +0000698#else // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000699 enum {__short_mask = 0x01};
Howard Hinnantec3773c2011-12-01 20:21:04 +0000700 enum {__long_mask = 0x1ul};
Howard Hinnant324bb032010-08-22 00:02:43 +0000701#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000702
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000703 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
704 (sizeof(__long) - 1)/sizeof(value_type) : 2};
705
706 struct __short
707 {
708 union
709 {
710 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59 +0000711 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000712 };
713 value_type __data_[__min_cap];
714 };
715
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000716#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000717
Howard Hinnant499cea12013-08-23 17:37:05 +0000718 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000719
Howard Hinnant499cea12013-08-23 17:37:05 +0000720 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000721
722 struct __raw
723 {
724 size_type __words[__n_words];
725 };
726
727 struct __rep
728 {
729 union
730 {
731 __long __l;
732 __short __s;
733 __raw __r;
734 };
735 };
736
737 __compressed_pair<__rep, allocator_type> __r_;
738
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000739public:
740 static const size_type npos = -1;
741
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000742 _LIBCPP_INLINE_VISIBILITY basic_string()
743 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000744
745 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
746#if _LIBCPP_STD_VER <= 14
747 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
748#else
749 _NOEXCEPT;
750#endif
751
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000752 basic_string(const basic_string& __str);
753 basic_string(const basic_string& __str, const allocator_type& __a);
Marshall Clow7b193f72015-06-03 19:56:43 +0000754
Howard Hinnant73d21a42010-09-04 23:28:19 +0000755#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9f193f22011-01-26 00:06:59 +0000756 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000757 basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +0000758#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000759 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000760#else
761 _NOEXCEPT;
762#endif
763
Howard Hinnant9f193f22011-01-26 00:06:59 +0000764 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000765 basic_string(basic_string&& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000766#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000767 _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000768 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000769 basic_string(const value_type* __s, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000770 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000771 basic_string(const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000772 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000773 basic_string(const value_type* __s, size_type __n, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000774 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000775 basic_string(size_type __n, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000776 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000777 basic_string(size_type __n, value_type __c, const allocator_type& __a);
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000778 basic_string(const basic_string& __str, size_type __pos, size_type __n,
779 const allocator_type& __a = allocator_type());
780 _LIBCPP_INLINE_VISIBILITY
781 basic_string(const basic_string& __str, size_type __pos,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000782 const allocator_type& __a = allocator_type());
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000783 _LIBCPP_INLINE_VISIBILITY explicit
784 basic_string(__self_view __sv);
785 _LIBCPP_INLINE_VISIBILITY
786 basic_string(__self_view __sv, const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000787 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000788 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000789 basic_string(_InputIterator __first, _InputIterator __last);
790 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000791 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000792 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000793#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000794 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000795 basic_string(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000796 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000797 basic_string(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000798#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000799
800 ~basic_string();
801
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000802 _LIBCPP_INLINE_VISIBILITY
803 operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
804
Howard Hinnante32b5e22010-11-17 17:55:08 +0000805 basic_string& operator=(const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000806 _LIBCPP_INLINE_VISIBILITY
807 basic_string& operator=(__self_view __sv) {return assign(__sv);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000808#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000809 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000810 basic_string& operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +0000811 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000812#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000813 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000814 basic_string& operator=(value_type __c);
Howard Hinnante3e32912011-08-12 21:56:02 +0000815#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000816 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000817 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000818#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000819
Howard Hinnant499cea12013-08-23 17:37:05 +0000820#if _LIBCPP_DEBUG_LEVEL >= 2
821 _LIBCPP_INLINE_VISIBILITY
822 iterator begin() _NOEXCEPT
823 {return iterator(this, __get_pointer());}
824 _LIBCPP_INLINE_VISIBILITY
825 const_iterator begin() const _NOEXCEPT
826 {return const_iterator(this, __get_pointer());}
827 _LIBCPP_INLINE_VISIBILITY
828 iterator end() _NOEXCEPT
829 {return iterator(this, __get_pointer() + size());}
830 _LIBCPP_INLINE_VISIBILITY
831 const_iterator end() const _NOEXCEPT
832 {return const_iterator(this, __get_pointer() + size());}
833#else
Howard Hinnanta6119a82011-05-29 19:57:12 +0000834 _LIBCPP_INLINE_VISIBILITY
835 iterator begin() _NOEXCEPT
836 {return iterator(__get_pointer());}
837 _LIBCPP_INLINE_VISIBILITY
838 const_iterator begin() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000839 {return const_iterator(__get_pointer());}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000840 _LIBCPP_INLINE_VISIBILITY
841 iterator end() _NOEXCEPT
842 {return iterator(__get_pointer() + size());}
843 _LIBCPP_INLINE_VISIBILITY
844 const_iterator end() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000845 {return const_iterator(__get_pointer() + size());}
Howard Hinnant499cea12013-08-23 17:37:05 +0000846#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnanta6119a82011-05-29 19:57:12 +0000847 _LIBCPP_INLINE_VISIBILITY
848 reverse_iterator rbegin() _NOEXCEPT
849 {return reverse_iterator(end());}
850 _LIBCPP_INLINE_VISIBILITY
851 const_reverse_iterator rbegin() const _NOEXCEPT
852 {return const_reverse_iterator(end());}
853 _LIBCPP_INLINE_VISIBILITY
854 reverse_iterator rend() _NOEXCEPT
855 {return reverse_iterator(begin());}
856 _LIBCPP_INLINE_VISIBILITY
857 const_reverse_iterator rend() const _NOEXCEPT
858 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000859
Howard Hinnanta6119a82011-05-29 19:57:12 +0000860 _LIBCPP_INLINE_VISIBILITY
861 const_iterator cbegin() const _NOEXCEPT
862 {return begin();}
863 _LIBCPP_INLINE_VISIBILITY
864 const_iterator cend() const _NOEXCEPT
865 {return end();}
866 _LIBCPP_INLINE_VISIBILITY
867 const_reverse_iterator crbegin() const _NOEXCEPT
868 {return rbegin();}
869 _LIBCPP_INLINE_VISIBILITY
870 const_reverse_iterator crend() const _NOEXCEPT
871 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000872
Howard Hinnanta6119a82011-05-29 19:57:12 +0000873 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000874 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000875 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
876 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
877 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +0000878 {return (__is_long() ? __get_long_cap()
879 : static_cast<size_type>(__min_cap)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000880
881 void resize(size_type __n, value_type __c);
882 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
883
884 void reserve(size_type res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000886 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +0000888 void clear() _NOEXCEPT;
889 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000890
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000891 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
892 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000893
894 const_reference at(size_type __n) const;
895 reference at(size_type __n);
896
897 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000898 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(__self_view __sv) {return append(__sv);}
899 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000900 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +0000901#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000902 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Howard Hinnante3e32912011-08-12 21:56:02 +0000903#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000904
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000906 basic_string& append(const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000907 _LIBCPP_INLINE_VISIBILITY
908 basic_string& append(__self_view __sv) { return append(__sv.data(), __sv.size()); }
Marshall Clowa93b5e22014-03-04 19:17:19 +0000909 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000910 _LIBCPP_INLINE_VISIBILITY
911 basic_string& append(__self_view __sv, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000912 basic_string& append(const value_type* __s, size_type __n);
913 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000914 basic_string& append(size_type __n, value_type __c);
915 template<class _InputIterator>
916 typename enable_if
917 <
Marshall Clowdf9db312016-01-13 21:54:34 +0000918 __is_exactly_input_iterator<_InputIterator>::value
919 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000920 basic_string&
921 >::type
922 append(_InputIterator __first, _InputIterator __last);
923 template<class _ForwardIterator>
924 typename enable_if
925 <
Marshall Clowdf9db312016-01-13 21:54:34 +0000926 __is_forward_iterator<_ForwardIterator>::value
927 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000928 basic_string&
929 >::type
930 append(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000931#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000932 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000933 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000934#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000935
936 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000937 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000938 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000939 _LIBCPP_INLINE_VISIBILITY reference front();
940 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
941 _LIBCPP_INLINE_VISIBILITY reference back();
942 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000943
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000944 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000945 basic_string& assign(__self_view __sv) { return assign(__sv.data(), __sv.size()); }
946 _LIBCPP_INLINE_VISIBILITY
Marshall Clowf40ec902016-03-09 18:08:29 +0000947 basic_string& assign(const basic_string& __str) { return *this = __str; }
Howard Hinnanta6119a82011-05-29 19:57:12 +0000948#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
949 _LIBCPP_INLINE_VISIBILITY
950 basic_string& assign(basic_string&& str)
Marshall Clow7ed093b2015-10-05 16:17:34 +0000951 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000952 {*this = _VSTD::move(str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000953#endif
Marshall Clowa93b5e22014-03-04 19:17:19 +0000954 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000955 _LIBCPP_INLINE_VISIBILITY
956 basic_string& assign(__self_view __sv, size_type pos, size_type n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000957 basic_string& assign(const value_type* __s, size_type __n);
958 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000959 basic_string& assign(size_type __n, value_type __c);
960 template<class _InputIterator>
961 typename enable_if
962 <
Marshall Clowdf9db312016-01-13 21:54:34 +0000963 __is_exactly_input_iterator<_InputIterator>::value
964 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000965 basic_string&
966 >::type
967 assign(_InputIterator __first, _InputIterator __last);
968 template<class _ForwardIterator>
969 typename enable_if
970 <
Marshall Clowdf9db312016-01-13 21:54:34 +0000971 __is_forward_iterator<_ForwardIterator>::value
972 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000973 basic_string&
974 >::type
975 assign(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000976#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000977 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000978 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000979#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000980
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000981 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000982 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000983 _LIBCPP_INLINE_VISIBILITY
984 basic_string& insert(size_type __pos1, __self_view __sv) { return insert(__pos1, __sv.data(), __sv.size()); }
985 _LIBCPP_INLINE_VISIBILITY
986 basic_string& insert(size_type __pos1, __self_view __sv, size_type __pos2, size_type __n=npos);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000987 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000988 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
989 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000990 basic_string& insert(size_type __pos, size_type __n, value_type __c);
991 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000992 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000993 iterator insert(const_iterator __pos, size_type __n, value_type __c);
994 template<class _InputIterator>
995 typename enable_if
996 <
Marshall Clowdf9db312016-01-13 21:54:34 +0000997 __is_exactly_input_iterator<_InputIterator>::value
998 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000999 iterator
1000 >::type
1001 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1002 template<class _ForwardIterator>
1003 typename enable_if
1004 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001005 __is_forward_iterator<_ForwardIterator>::value
1006 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001007 iterator
1008 >::type
1009 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001010#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001011 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001012 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1013 {return insert(__pos, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001014#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001015
1016 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001017 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001018 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001019 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001020 iterator erase(const_iterator __first, const_iterator __last);
1021
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001022 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001023 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001024 _LIBCPP_INLINE_VISIBILITY
1025 basic_string& replace(size_type __pos1, size_type __n1, __self_view __sv) { return replace(__pos1, __n1, __sv.data(), __sv.size()); }
Marshall Clowa93b5e22014-03-04 19:17:19 +00001026 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
Eric Fiselier833d6442016-09-15 22:27:07 +00001027 inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001028 basic_string& replace(size_type __pos1, size_type __n1, __self_view __sv, size_type __pos2, size_type __n2=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001029 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1030 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001031 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001032 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001033 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001034 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001035 basic_string& replace(const_iterator __i1, const_iterator __i2, __self_view __sv) { return replace(__i1 - begin(), __i2 - __i1, __sv); }
1036 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001037 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001038 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001039 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001040 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001041 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001042 template<class _InputIterator>
1043 typename enable_if
1044 <
1045 __is_input_iterator<_InputIterator>::value,
1046 basic_string&
1047 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001048 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Howard Hinnante3e32912011-08-12 21:56:02 +00001049#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001050 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001051 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001052 {return replace(__i1, __i2, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001053#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001054
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001055 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001056 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001057 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1058
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001059 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001060 void swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00001061#if _LIBCPP_STD_VER >= 14
1062 _NOEXCEPT;
1063#else
1064 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1065 __is_nothrow_swappable<allocator_type>::value);
1066#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001067
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001068 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001069 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001070 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001071 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Marshall Clowf532a702016-03-08 15:44:30 +00001072#if _LIBCPP_STD_VER > 14
1073 _LIBCPP_INLINE_VISIBILITY
1074 value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1075#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001076
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001077 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001078 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001079
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001080 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001081 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001082 _LIBCPP_INLINE_VISIBILITY
1083 size_type find(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001084 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001085 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001086 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001087 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001088
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001089 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001090 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001091 _LIBCPP_INLINE_VISIBILITY
1092 size_type rfind(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001093 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001094 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001095 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001096 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001097
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001098 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001099 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001100 _LIBCPP_INLINE_VISIBILITY
1101 size_type find_first_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001102 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001103 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001104 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001105 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001106 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001107
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001108 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001109 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001110 _LIBCPP_INLINE_VISIBILITY
1111 size_type find_last_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001112 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001113 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001114 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001115 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001116 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001117
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001118 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001119 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001120 _LIBCPP_INLINE_VISIBILITY
1121 size_type find_first_not_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001122 size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001123 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001124 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001125 _LIBCPP_INLINE_VISIBILITY
1126 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1127
1128 _LIBCPP_INLINE_VISIBILITY
1129 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001130 _LIBCPP_INLINE_VISIBILITY
1131 size_type find_last_not_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001132 size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001133 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001134 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001135 _LIBCPP_INLINE_VISIBILITY
1136 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1137
1138 _LIBCPP_INLINE_VISIBILITY
1139 int compare(const basic_string& __str) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001140 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001141 int compare(__self_view __sv) const _NOEXCEPT;
1142 _LIBCPP_INLINE_VISIBILITY
1143 int compare(size_type __pos1, size_type __n1, __self_view __sv) const;
1144 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001145 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clowa93b5e22014-03-04 19:17:19 +00001146 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001147 _LIBCPP_INLINE_VISIBILITY
1148 int compare(size_type __pos1, size_type __n1, __self_view __sv, size_type __pos2, size_type __n2=npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001149 int compare(const value_type* __s) const _NOEXCEPT;
1150 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1151 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001152
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001153 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:13 +00001154
1155 _LIBCPP_INLINE_VISIBILITY
1156 bool __is_long() const _NOEXCEPT
1157 {return bool(__r_.first().__s.__size_ & __short_mask);}
1158
Howard Hinnant499cea12013-08-23 17:37:05 +00001159#if _LIBCPP_DEBUG_LEVEL >= 2
1160
1161 bool __dereferenceable(const const_iterator* __i) const;
1162 bool __decrementable(const const_iterator* __i) const;
1163 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1164 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1165
1166#endif // _LIBCPP_DEBUG_LEVEL >= 2
1167
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001168private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001169 _LIBCPP_INLINE_VISIBILITY
1170 allocator_type& __alloc() _NOEXCEPT
1171 {return __r_.second();}
1172 _LIBCPP_INLINE_VISIBILITY
1173 const allocator_type& __alloc() const _NOEXCEPT
1174 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001175
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001176#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001177
Howard Hinnanta6119a82011-05-29 19:57:12 +00001178 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001179 void __set_short_size(size_type __s) _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001180# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001181 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:48 +00001182# else
1183 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1184# endif
1185
Howard Hinnanta6119a82011-05-29 19:57:12 +00001186 _LIBCPP_INLINE_VISIBILITY
1187 size_type __get_short_size() const _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001188# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001189 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:48 +00001190# else
1191 {return __r_.first().__s.__size_;}
1192# endif
1193
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001194#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001195
1196 _LIBCPP_INLINE_VISIBILITY
1197 void __set_short_size(size_type __s) _NOEXCEPT
1198# if _LIBCPP_BIG_ENDIAN
1199 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1200# else
1201 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1202# endif
1203
1204 _LIBCPP_INLINE_VISIBILITY
1205 size_type __get_short_size() const _NOEXCEPT
1206# if _LIBCPP_BIG_ENDIAN
1207 {return __r_.first().__s.__size_;}
1208# else
1209 {return __r_.first().__s.__size_ >> 1;}
1210# endif
1211
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001212#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001213
Howard Hinnanta6119a82011-05-29 19:57:12 +00001214 _LIBCPP_INLINE_VISIBILITY
1215 void __set_long_size(size_type __s) _NOEXCEPT
1216 {__r_.first().__l.__size_ = __s;}
1217 _LIBCPP_INLINE_VISIBILITY
1218 size_type __get_long_size() const _NOEXCEPT
1219 {return __r_.first().__l.__size_;}
1220 _LIBCPP_INLINE_VISIBILITY
1221 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001222 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1223
Howard Hinnanta6119a82011-05-29 19:57:12 +00001224 _LIBCPP_INLINE_VISIBILITY
1225 void __set_long_cap(size_type __s) _NOEXCEPT
1226 {__r_.first().__l.__cap_ = __long_mask | __s;}
1227 _LIBCPP_INLINE_VISIBILITY
1228 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001229 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001230
Howard Hinnanta6119a82011-05-29 19:57:12 +00001231 _LIBCPP_INLINE_VISIBILITY
1232 void __set_long_pointer(pointer __p) _NOEXCEPT
1233 {__r_.first().__l.__data_ = __p;}
1234 _LIBCPP_INLINE_VISIBILITY
1235 pointer __get_long_pointer() _NOEXCEPT
1236 {return __r_.first().__l.__data_;}
1237 _LIBCPP_INLINE_VISIBILITY
1238 const_pointer __get_long_pointer() const _NOEXCEPT
1239 {return __r_.first().__l.__data_;}
1240 _LIBCPP_INLINE_VISIBILITY
1241 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001242 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001243 _LIBCPP_INLINE_VISIBILITY
1244 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001245 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001246 _LIBCPP_INLINE_VISIBILITY
1247 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001248 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001249 _LIBCPP_INLINE_VISIBILITY
1250 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001251 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1252
Howard Hinnanta6119a82011-05-29 19:57:12 +00001253 _LIBCPP_INLINE_VISIBILITY
1254 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001255 {
1256 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1257 for (unsigned __i = 0; __i < __n_words; ++__i)
1258 __a[__i] = 0;
1259 }
1260
1261 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001262 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:20 +00001263 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001264 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001265 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001266 static _LIBCPP_INLINE_VISIBILITY
1267 size_type __recommend(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001268 {return (__s < __min_cap ? static_cast<size_type>(__min_cap) :
Howard Hinnant7f764502013-08-14 18:00:20 +00001269 __align_it<sizeof(value_type) < __alignment ?
Howard Hinnanta6119a82011-05-29 19:57:12 +00001270 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001271
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001272 void __init(const value_type* __s, size_type __sz, size_type __reserve);
1273 void __init(const value_type* __s, size_type __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001274 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001275
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001276 template <class _InputIterator>
1277 typename enable_if
1278 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001279 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001280 void
1281 >::type
1282 __init(_InputIterator __first, _InputIterator __last);
1283
1284 template <class _ForwardIterator>
1285 typename enable_if
1286 <
1287 __is_forward_iterator<_ForwardIterator>::value,
1288 void
1289 >::type
1290 __init(_ForwardIterator __first, _ForwardIterator __last);
1291
1292 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001293 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001294 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1295 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001296 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001297
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001298 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001299 void __erase_to_end(size_type __pos);
1300
Howard Hinnante32b5e22010-11-17 17:55:08 +00001301 _LIBCPP_INLINE_VISIBILITY
1302 void __copy_assign_alloc(const basic_string& __str)
1303 {__copy_assign_alloc(__str, integral_constant<bool,
1304 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1305
1306 _LIBCPP_INLINE_VISIBILITY
1307 void __copy_assign_alloc(const basic_string& __str, true_type)
1308 {
1309 if (__alloc() != __str.__alloc())
1310 {
1311 clear();
1312 shrink_to_fit();
1313 }
1314 __alloc() = __str.__alloc();
1315 }
1316
1317 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001318 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001319 {}
1320
1321#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001322 _LIBCPP_INLINE_VISIBILITY
Marshall Clowaf961ed2015-08-18 18:57:00 +00001323 void __move_assign(basic_string& __str, false_type)
1324 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001325 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001326 void __move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001327#if _LIBCPP_STD_VER > 14
1328 _NOEXCEPT;
1329#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001330 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001331#endif
Marshall Clowaf961ed2015-08-18 18:57:00 +00001332#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00001333
1334 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001335 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001336 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001337 _NOEXCEPT_(
1338 !__alloc_traits::propagate_on_container_move_assignment::value ||
1339 is_nothrow_move_assignable<allocator_type>::value)
1340 {__move_assign_alloc(__str, integral_constant<bool,
1341 __alloc_traits::propagate_on_container_move_assignment::value>());}
1342
1343 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001344 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001345 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1346 {
1347 __alloc() = _VSTD::move(__c.__alloc());
1348 }
1349
1350 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001351 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001352 _NOEXCEPT
1353 {}
1354
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001355 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1356 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001357
1358 friend basic_string operator+<>(const basic_string&, const basic_string&);
1359 friend basic_string operator+<>(const value_type*, const basic_string&);
1360 friend basic_string operator+<>(value_type, const basic_string&);
1361 friend basic_string operator+<>(const basic_string&, const value_type*);
1362 friend basic_string operator+<>(const basic_string&, value_type);
1363};
1364
1365template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001366inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001367void
1368basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1369{
Howard Hinnant499cea12013-08-23 17:37:05 +00001370#if _LIBCPP_DEBUG_LEVEL >= 2
1371 __get_db()->__invalidate_all(this);
1372#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001373}
1374
1375template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001376inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001377void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001378basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant499cea12013-08-23 17:37:05 +00001379#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantec3773c2011-12-01 20:21:04 +00001380 __pos
1381#endif
1382 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001383{
Howard Hinnant499cea12013-08-23 17:37:05 +00001384#if _LIBCPP_DEBUG_LEVEL >= 2
1385 __c_node* __c = __get_db()->__find_c_and_lock(this);
1386 if (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001387 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001388 const_pointer __new_last = __get_pointer() + __pos;
1389 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001390 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001391 --__p;
1392 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1393 if (__i->base() > __new_last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001394 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001395 (*__p)->__c_ = nullptr;
1396 if (--__c->end_ != __p)
1397 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001398 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001399 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001400 __get_db()->unlock();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001401 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001402#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001403}
1404
1405template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001406inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001407basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowc912c0c2015-06-04 02:05:41 +00001408 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001409{
Howard Hinnant499cea12013-08-23 17:37:05 +00001410#if _LIBCPP_DEBUG_LEVEL >= 2
1411 __get_db()->__insert_c(this);
1412#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001413 __zero();
1414}
1415
1416template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001417inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001418basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiselier692177d2015-07-18 20:40:46 +00001419#if _LIBCPP_STD_VER <= 14
1420 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1421#else
1422 _NOEXCEPT
1423#endif
1424: __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001425{
Howard Hinnant499cea12013-08-23 17:37:05 +00001426#if _LIBCPP_DEBUG_LEVEL >= 2
1427 __get_db()->__insert_c(this);
1428#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001429 __zero();
1430}
1431
1432template <class _CharT, class _Traits, class _Allocator>
Sebastian Popbb11bc42016-08-11 16:51:48 +00001433inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001434void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001435basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001436{
1437 if (__reserve > max_size())
1438 this->__throw_length_error();
1439 pointer __p;
1440 if (__reserve < __min_cap)
1441 {
1442 __set_short_size(__sz);
1443 __p = __get_short_pointer();
1444 }
1445 else
1446 {
1447 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001448 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001449 __set_long_pointer(__p);
1450 __set_long_cap(__cap+1);
1451 __set_long_size(__sz);
1452 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001453 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001454 traits_type::assign(__p[__sz], value_type());
1455}
1456
1457template <class _CharT, class _Traits, class _Allocator>
Sebastian Popbb11bc42016-08-11 16:51:48 +00001458inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001459void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001460basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001461{
1462 if (__sz > max_size())
1463 this->__throw_length_error();
1464 pointer __p;
1465 if (__sz < __min_cap)
1466 {
1467 __set_short_size(__sz);
1468 __p = __get_short_pointer();
1469 }
1470 else
1471 {
1472 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001473 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001474 __set_long_pointer(__p);
1475 __set_long_cap(__cap+1);
1476 __set_long_size(__sz);
1477 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001478 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001479 traits_type::assign(__p[__sz], value_type());
1480}
1481
1482template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001483inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001484basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001485{
Howard Hinnant499cea12013-08-23 17:37:05 +00001486 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001487 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00001488#if _LIBCPP_DEBUG_LEVEL >= 2
1489 __get_db()->__insert_c(this);
1490#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001491}
1492
1493template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001494inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001495basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001496 : __r_(__a)
1497{
Howard Hinnant499cea12013-08-23 17:37:05 +00001498 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001499 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00001500#if _LIBCPP_DEBUG_LEVEL >= 2
1501 __get_db()->__insert_c(this);
1502#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001503}
1504
1505template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001506inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001507basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001508{
Howard Hinnant499cea12013-08-23 17:37:05 +00001509 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001510 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001511#if _LIBCPP_DEBUG_LEVEL >= 2
1512 __get_db()->__insert_c(this);
1513#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001514}
1515
1516template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001517inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001518basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001519 : __r_(__a)
1520{
Howard Hinnant499cea12013-08-23 17:37:05 +00001521 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001522 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001523#if _LIBCPP_DEBUG_LEVEL >= 2
1524 __get_db()->__insert_c(this);
1525#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001526}
1527
1528template <class _CharT, class _Traits, class _Allocator>
1529basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001530 : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001531{
1532 if (!__str.__is_long())
1533 __r_.first().__r = __str.__r_.first().__r;
1534 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001535 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001536#if _LIBCPP_DEBUG_LEVEL >= 2
1537 __get_db()->__insert_c(this);
1538#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001539}
1540
1541template <class _CharT, class _Traits, class _Allocator>
1542basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
1543 : __r_(__a)
1544{
1545 if (!__str.__is_long())
1546 __r_.first().__r = __str.__r_.first().__r;
1547 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001548 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001549#if _LIBCPP_DEBUG_LEVEL >= 2
1550 __get_db()->__insert_c(this);
1551#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001552}
1553
Howard Hinnant73d21a42010-09-04 23:28:19 +00001554#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001555
1556template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001557inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001558basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +00001559#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001560 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clow7b193f72015-06-03 19:56:43 +00001561#else
1562 _NOEXCEPT
1563#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001564 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001565{
1566 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:05 +00001567#if _LIBCPP_DEBUG_LEVEL >= 2
1568 __get_db()->__insert_c(this);
1569 if (__is_long())
1570 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001571#endif
1572}
1573
1574template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001575inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001576basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001577 : __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001578{
Marshall Clowd5549cc2014-07-17 15:32:20 +00001579 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001580 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd5549cc2014-07-17 15:32:20 +00001581 else
1582 {
1583 __r_.first().__r = __str.__r_.first().__r;
1584 __str.__zero();
1585 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001586#if _LIBCPP_DEBUG_LEVEL >= 2
1587 __get_db()->__insert_c(this);
1588 if (__is_long())
1589 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001590#endif
1591}
1592
Howard Hinnant73d21a42010-09-04 23:28:19 +00001593#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001594
1595template <class _CharT, class _Traits, class _Allocator>
Sebastian Popbb11bc42016-08-11 16:51:48 +00001596inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001597void
1598basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1599{
1600 if (__n > max_size())
1601 this->__throw_length_error();
1602 pointer __p;
1603 if (__n < __min_cap)
1604 {
1605 __set_short_size(__n);
1606 __p = __get_short_pointer();
1607 }
1608 else
1609 {
1610 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001611 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001612 __set_long_pointer(__p);
1613 __set_long_cap(__cap+1);
1614 __set_long_size(__n);
1615 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001616 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001617 traits_type::assign(__p[__n], value_type());
1618}
1619
1620template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001621inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001622basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
1623{
1624 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001625#if _LIBCPP_DEBUG_LEVEL >= 2
1626 __get_db()->__insert_c(this);
1627#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001628}
1629
1630template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001631inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001632basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
1633 : __r_(__a)
1634{
1635 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001636#if _LIBCPP_DEBUG_LEVEL >= 2
1637 __get_db()->__insert_c(this);
1638#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001639}
1640
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001641template <class _CharT, class _Traits, class _Allocator>
1642basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
1643 const allocator_type& __a)
1644 : __r_(__a)
1645{
1646 size_type __str_sz = __str.size();
1647 if (__pos > __str_sz)
1648 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001649 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant499cea12013-08-23 17:37:05 +00001650#if _LIBCPP_DEBUG_LEVEL >= 2
1651 __get_db()->__insert_c(this);
1652#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001653}
1654
1655template <class _CharT, class _Traits, class _Allocator>
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001656inline _LIBCPP_INLINE_VISIBILITY
1657basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
1658 const allocator_type& __a)
1659 : __r_(__a)
1660{
1661 size_type __str_sz = __str.size();
1662 if (__pos > __str_sz)
1663 this->__throw_out_of_range();
1664 __init(__str.data() + __pos, __str_sz - __pos);
1665#if _LIBCPP_DEBUG_LEVEL >= 2
1666 __get_db()->__insert_c(this);
1667#endif
1668}
1669
1670template <class _CharT, class _Traits, class _Allocator>
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001671inline _LIBCPP_INLINE_VISIBILITY
1672basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv)
1673{
1674 __init(__sv.data(), __sv.size());
1675#if _LIBCPP_DEBUG_LEVEL >= 2
1676 __get_db()->__insert_c(this);
1677#endif
1678}
1679
1680template <class _CharT, class _Traits, class _Allocator>
1681inline _LIBCPP_INLINE_VISIBILITY
1682basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv, const allocator_type& __a)
1683 : __r_(__a)
1684{
1685 __init(__sv.data(), __sv.size());
1686#if _LIBCPP_DEBUG_LEVEL >= 2
1687 __get_db()->__insert_c(this);
1688#endif
1689}
1690
1691template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001692template <class _InputIterator>
Sebastian Popbb11bc42016-08-11 16:51:48 +00001693inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001694typename enable_if
1695<
Marshall Clowdf9db312016-01-13 21:54:34 +00001696 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001697 void
1698>::type
1699basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
1700{
1701 __zero();
1702#ifndef _LIBCPP_NO_EXCEPTIONS
1703 try
1704 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001705#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001706 for (; __first != __last; ++__first)
1707 push_back(*__first);
1708#ifndef _LIBCPP_NO_EXCEPTIONS
1709 }
1710 catch (...)
1711 {
1712 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00001713 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001714 throw;
1715 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001716#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001717}
1718
1719template <class _CharT, class _Traits, class _Allocator>
1720template <class _ForwardIterator>
Sebastian Popbb11bc42016-08-11 16:51:48 +00001721inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001722typename enable_if
1723<
1724 __is_forward_iterator<_ForwardIterator>::value,
1725 void
1726>::type
1727basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
1728{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001729 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001730 if (__sz > max_size())
1731 this->__throw_length_error();
1732 pointer __p;
1733 if (__sz < __min_cap)
1734 {
1735 __set_short_size(__sz);
1736 __p = __get_short_pointer();
1737 }
1738 else
1739 {
1740 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001741 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001742 __set_long_pointer(__p);
1743 __set_long_cap(__cap+1);
1744 __set_long_size(__sz);
1745 }
Eric Fiselierb9919752014-10-27 19:28:20 +00001746 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001747 traits_type::assign(*__p, *__first);
1748 traits_type::assign(*__p, value_type());
1749}
1750
1751template <class _CharT, class _Traits, class _Allocator>
1752template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001753inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001754basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
1755{
1756 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00001757#if _LIBCPP_DEBUG_LEVEL >= 2
1758 __get_db()->__insert_c(this);
1759#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001760}
1761
1762template <class _CharT, class _Traits, class _Allocator>
1763template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001764inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001765basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
1766 const allocator_type& __a)
1767 : __r_(__a)
1768{
1769 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00001770#if _LIBCPP_DEBUG_LEVEL >= 2
1771 __get_db()->__insert_c(this);
1772#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001773}
1774
Howard Hinnante3e32912011-08-12 21:56:02 +00001775#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1776
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001777template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001778inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001779basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
1780{
1781 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00001782#if _LIBCPP_DEBUG_LEVEL >= 2
1783 __get_db()->__insert_c(this);
1784#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001785}
1786
1787template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001788inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001789basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
1790 : __r_(__a)
1791{
1792 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00001793#if _LIBCPP_DEBUG_LEVEL >= 2
1794 __get_db()->__insert_c(this);
1795#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001796}
1797
Howard Hinnante3e32912011-08-12 21:56:02 +00001798#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1799
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001800template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001801basic_string<_CharT, _Traits, _Allocator>::~basic_string()
1802{
Howard Hinnant499cea12013-08-23 17:37:05 +00001803#if _LIBCPP_DEBUG_LEVEL >= 2
1804 __get_db()->__erase_c(this);
1805#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001806 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00001807 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001808}
1809
1810template <class _CharT, class _Traits, class _Allocator>
1811void
1812basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
1813 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001814 size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001815{
1816 size_type __ms = max_size();
1817 if (__delta_cap > __ms - __old_cap - 1)
1818 this->__throw_length_error();
1819 pointer __old_p = __get_pointer();
1820 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00001821 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001822 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001823 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001824 __invalidate_all_iterators();
1825 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001826 traits_type::copy(_VSTD::__to_raw_pointer(__p),
1827 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001828 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001829 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001830 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
1831 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001832 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
1833 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001834 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001835 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001836 __set_long_pointer(__p);
1837 __set_long_cap(__cap+1);
1838 __old_sz = __n_copy + __n_add + __sec_cp_sz;
1839 __set_long_size(__old_sz);
1840 traits_type::assign(__p[__old_sz], value_type());
1841}
1842
1843template <class _CharT, class _Traits, class _Allocator>
1844void
1845basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1846 size_type __n_copy, size_type __n_del, size_type __n_add)
1847{
1848 size_type __ms = max_size();
Marshall Clowecc8d7b2013-11-06 14:24:38 +00001849 if (__delta_cap > __ms - __old_cap)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001850 this->__throw_length_error();
1851 pointer __old_p = __get_pointer();
1852 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00001853 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001854 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001855 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001856 __invalidate_all_iterators();
1857 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001858 traits_type::copy(_VSTD::__to_raw_pointer(__p),
1859 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001860 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
1861 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001862 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
1863 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
1864 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001865 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001866 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001867 __set_long_pointer(__p);
1868 __set_long_cap(__cap+1);
1869}
1870
1871// assign
1872
1873template <class _CharT, class _Traits, class _Allocator>
1874basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001875basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001876{
Alp Tokerec34c482014-05-15 11:27:39 +00001877 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001878 size_type __cap = capacity();
1879 if (__cap >= __n)
1880 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001881 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001882 traits_type::move(__p, __s, __n);
1883 traits_type::assign(__p[__n], value_type());
1884 __set_size(__n);
1885 __invalidate_iterators_past(__n);
1886 }
1887 else
1888 {
1889 size_type __sz = size();
1890 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
1891 }
1892 return *this;
1893}
1894
1895template <class _CharT, class _Traits, class _Allocator>
1896basic_string<_CharT, _Traits, _Allocator>&
1897basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
1898{
1899 size_type __cap = capacity();
1900 if (__cap < __n)
1901 {
1902 size_type __sz = size();
1903 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
1904 }
1905 else
1906 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001907 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001908 traits_type::assign(__p, __n, __c);
1909 traits_type::assign(__p[__n], value_type());
1910 __set_size(__n);
1911 return *this;
1912}
1913
1914template <class _CharT, class _Traits, class _Allocator>
1915basic_string<_CharT, _Traits, _Allocator>&
1916basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
1917{
1918 pointer __p;
1919 if (__is_long())
1920 {
1921 __p = __get_long_pointer();
1922 __set_long_size(1);
1923 }
1924 else
1925 {
1926 __p = __get_short_pointer();
1927 __set_short_size(1);
1928 }
1929 traits_type::assign(*__p, __c);
1930 traits_type::assign(*++__p, value_type());
1931 __invalidate_iterators_past(1);
1932 return *this;
1933}
1934
1935template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00001936basic_string<_CharT, _Traits, _Allocator>&
1937basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
1938{
1939 if (this != &__str)
1940 {
1941 __copy_assign_alloc(__str);
Marshall Clowf40ec902016-03-09 18:08:29 +00001942 assign(__str.data(), __str.size());
Howard Hinnante32b5e22010-11-17 17:55:08 +00001943 }
1944 return *this;
1945}
1946
1947#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1948
1949template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001950inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00001951void
1952basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001953 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001954{
1955 if (__alloc() != __str.__alloc())
1956 assign(__str);
1957 else
1958 __move_assign(__str, true_type());
1959}
1960
1961template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001962inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00001963void
1964basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001965#if _LIBCPP_STD_VER > 14
1966 _NOEXCEPT
1967#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001968 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001969#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00001970{
1971 clear();
1972 shrink_to_fit();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001973 __r_.first() = __str.__r_.first();
1974 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001975 __str.__zero();
1976}
1977
1978template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001979inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00001980basic_string<_CharT, _Traits, _Allocator>&
1981basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001982 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnante32b5e22010-11-17 17:55:08 +00001983{
1984 __move_assign(__str, integral_constant<bool,
1985 __alloc_traits::propagate_on_container_move_assignment::value>());
1986 return *this;
1987}
1988
1989#endif
1990
1991template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001992template<class _InputIterator>
1993typename enable_if
1994<
Marshall Clowdf9db312016-01-13 21:54:34 +00001995 __is_exactly_input_iterator <_InputIterator>::value
1996 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001997 basic_string<_CharT, _Traits, _Allocator>&
1998>::type
1999basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2000{
Marshall Clowd979eed2016-09-05 01:54:30 +00002001 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002002 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002003 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002004}
2005
2006template <class _CharT, class _Traits, class _Allocator>
2007template<class _ForwardIterator>
2008typename enable_if
2009<
Marshall Clowdf9db312016-01-13 21:54:34 +00002010 __is_forward_iterator<_ForwardIterator>::value
2011 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002012 basic_string<_CharT, _Traits, _Allocator>&
2013>::type
2014basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2015{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002016 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002017 size_type __cap = capacity();
2018 if (__cap < __n)
2019 {
2020 size_type __sz = size();
2021 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2022 }
2023 else
2024 __invalidate_iterators_past(__n);
2025 pointer __p = __get_pointer();
2026 for (; __first != __last; ++__first, ++__p)
2027 traits_type::assign(*__p, *__first);
2028 traits_type::assign(*__p, value_type());
2029 __set_size(__n);
2030 return *this;
2031}
2032
2033template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002034basic_string<_CharT, _Traits, _Allocator>&
2035basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2036{
2037 size_type __sz = __str.size();
2038 if (__pos > __sz)
2039 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002040 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002041}
2042
2043template <class _CharT, class _Traits, class _Allocator>
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002044inline _LIBCPP_INLINE_VISIBILITY
2045basic_string<_CharT, _Traits, _Allocator>&
2046basic_string<_CharT, _Traits, _Allocator>::assign(__self_view __sv, size_type __pos, size_type __n)
2047{
2048 size_type __sz = __sv.size();
2049 if (__pos > __sz)
2050 this->__throw_out_of_range();
2051 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2052}
2053
2054
2055template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002056basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002057basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002058{
Alp Tokerec34c482014-05-15 11:27:39 +00002059 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002060 return assign(__s, traits_type::length(__s));
2061}
2062
2063// append
2064
2065template <class _CharT, class _Traits, class _Allocator>
2066basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002067basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002068{
Alp Tokerec34c482014-05-15 11:27:39 +00002069 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002070 size_type __cap = capacity();
2071 size_type __sz = size();
2072 if (__cap - __sz >= __n)
2073 {
2074 if (__n)
2075 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002076 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002077 traits_type::copy(__p + __sz, __s, __n);
2078 __sz += __n;
2079 __set_size(__sz);
2080 traits_type::assign(__p[__sz], value_type());
2081 }
2082 }
2083 else
2084 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2085 return *this;
2086}
2087
2088template <class _CharT, class _Traits, class _Allocator>
2089basic_string<_CharT, _Traits, _Allocator>&
2090basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2091{
2092 if (__n)
2093 {
2094 size_type __cap = capacity();
2095 size_type __sz = size();
2096 if (__cap - __sz < __n)
2097 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2098 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002099 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002100 __sz += __n;
2101 __set_size(__sz);
2102 traits_type::assign(__p[__sz], value_type());
2103 }
2104 return *this;
2105}
2106
2107template <class _CharT, class _Traits, class _Allocator>
2108void
2109basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2110{
Howard Hinnant15467182013-04-30 21:44:48 +00002111 bool __is_short = !__is_long();
2112 size_type __cap;
2113 size_type __sz;
2114 if (__is_short)
2115 {
2116 __cap = __min_cap - 1;
2117 __sz = __get_short_size();
2118 }
2119 else
2120 {
2121 __cap = __get_long_cap() - 1;
2122 __sz = __get_long_size();
2123 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002124 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002125 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002126 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002127 __is_short = !__is_long();
2128 }
2129 pointer __p;
2130 if (__is_short)
2131 {
2132 __p = __get_short_pointer() + __sz;
2133 __set_short_size(__sz+1);
2134 }
2135 else
2136 {
2137 __p = __get_long_pointer() + __sz;
2138 __set_long_size(__sz+1);
2139 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002140 traits_type::assign(*__p, __c);
2141 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002142}
2143
2144template <class _CharT, class _Traits, class _Allocator>
2145template<class _InputIterator>
2146typename enable_if
2147<
Marshall Clowdf9db312016-01-13 21:54:34 +00002148 __is_exactly_input_iterator<_InputIterator>::value
2149 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002150 basic_string<_CharT, _Traits, _Allocator>&
2151>::type
2152basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
2153{
Marshall Clowd979eed2016-09-05 01:54:30 +00002154 const basic_string __temp (__first, __last, __alloc());
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002155 append(__temp.data(), __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002156 return *this;
2157}
2158
Marshall Clowac655ef2016-09-07 03:32:06 +00002159template <class _Tp>
Marshall Clowd979eed2016-09-05 01:54:30 +00002160bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
2161{
2162 return __first <= __p && __p < __last;
2163}
2164
Marshall Clowac655ef2016-09-07 03:32:06 +00002165template <class _Tp1, class _Tp2>
2166bool __ptr_in_range (const _Tp1* __p, const _Tp2* __first, const _Tp2* __last)
2167{
2168 return false;
2169}
2170
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002171template <class _CharT, class _Traits, class _Allocator>
2172template<class _ForwardIterator>
2173typename enable_if
2174<
Marshall Clowdf9db312016-01-13 21:54:34 +00002175 __is_forward_iterator<_ForwardIterator>::value
2176 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002177 basic_string<_CharT, _Traits, _Allocator>&
2178>::type
2179basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
2180{
2181 size_type __sz = size();
2182 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002183 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002184 if (__n)
2185 {
Marshall Clowd979eed2016-09-05 01:54:30 +00002186 if ( __ptr_in_range(&*__first, data(), data() + size()))
2187 {
2188 const basic_string __temp (__first, __last, __alloc());
2189 append(__temp.data(), __temp.size());
2190 }
2191 else
2192 {
2193 if (__cap - __sz < __n)
2194 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2195 pointer __p = __get_pointer() + __sz;
2196 for (; __first != __last; ++__p, ++__first)
2197 traits_type::assign(*__p, *__first);
2198 traits_type::assign(*__p, value_type());
2199 __set_size(__sz + __n);
2200 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002201 }
2202 return *this;
2203}
2204
2205template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002206inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002207basic_string<_CharT, _Traits, _Allocator>&
2208basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2209{
2210 return append(__str.data(), __str.size());
2211}
2212
2213template <class _CharT, class _Traits, class _Allocator>
2214basic_string<_CharT, _Traits, _Allocator>&
2215basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2216{
2217 size_type __sz = __str.size();
2218 if (__pos > __sz)
2219 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002220 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002221}
2222
2223template <class _CharT, class _Traits, class _Allocator>
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002224inline _LIBCPP_INLINE_VISIBILITY
2225basic_string<_CharT, _Traits, _Allocator>&
2226basic_string<_CharT, _Traits, _Allocator>::append(__self_view __sv, size_type __pos, size_type __n)
2227{
2228 size_type __sz = __sv.size();
2229 if (__pos > __sz)
2230 this->__throw_out_of_range();
2231 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2232}
2233
2234template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002235basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002236basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002237{
Alp Tokerec34c482014-05-15 11:27:39 +00002238 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002239 return append(__s, traits_type::length(__s));
2240}
2241
2242// insert
2243
2244template <class _CharT, class _Traits, class _Allocator>
2245basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002246basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002247{
Alp Tokerec34c482014-05-15 11:27:39 +00002248 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002249 size_type __sz = size();
2250 if (__pos > __sz)
2251 this->__throw_out_of_range();
2252 size_type __cap = capacity();
2253 if (__cap - __sz >= __n)
2254 {
2255 if (__n)
2256 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002257 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002258 size_type __n_move = __sz - __pos;
2259 if (__n_move != 0)
2260 {
2261 if (__p + __pos <= __s && __s < __p + __sz)
2262 __s += __n;
2263 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2264 }
2265 traits_type::move(__p + __pos, __s, __n);
2266 __sz += __n;
2267 __set_size(__sz);
2268 traits_type::assign(__p[__sz], value_type());
2269 }
2270 }
2271 else
2272 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2273 return *this;
2274}
2275
2276template <class _CharT, class _Traits, class _Allocator>
2277basic_string<_CharT, _Traits, _Allocator>&
2278basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2279{
2280 size_type __sz = size();
2281 if (__pos > __sz)
2282 this->__throw_out_of_range();
2283 if (__n)
2284 {
2285 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002286 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002287 if (__cap - __sz >= __n)
2288 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002289 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002290 size_type __n_move = __sz - __pos;
2291 if (__n_move != 0)
2292 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2293 }
2294 else
2295 {
2296 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002297 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002298 }
2299 traits_type::assign(__p + __pos, __n, __c);
2300 __sz += __n;
2301 __set_size(__sz);
2302 traits_type::assign(__p[__sz], value_type());
2303 }
2304 return *this;
2305}
2306
2307template <class _CharT, class _Traits, class _Allocator>
2308template<class _InputIterator>
2309typename enable_if
2310<
Marshall Clowdf9db312016-01-13 21:54:34 +00002311 __is_exactly_input_iterator<_InputIterator>::value
2312 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2313 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002314>::type
2315basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2316{
Howard Hinnant499cea12013-08-23 17:37:05 +00002317#if _LIBCPP_DEBUG_LEVEL >= 2
2318 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2319 "string::insert(iterator, range) called with an iterator not"
2320 " referring to this string");
2321#endif
Marshall Clowd979eed2016-09-05 01:54:30 +00002322 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002323 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002324}
2325
2326template <class _CharT, class _Traits, class _Allocator>
2327template<class _ForwardIterator>
2328typename enable_if
2329<
Marshall Clowdf9db312016-01-13 21:54:34 +00002330 __is_forward_iterator<_ForwardIterator>::value
2331 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002332 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2333>::type
2334basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2335{
Howard Hinnant499cea12013-08-23 17:37:05 +00002336#if _LIBCPP_DEBUG_LEVEL >= 2
2337 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2338 "string::insert(iterator, range) called with an iterator not"
2339 " referring to this string");
2340#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002341 size_type __ip = static_cast<size_type>(__pos - begin());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002342 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002343 if (__n)
2344 {
Marshall Clowd979eed2016-09-05 01:54:30 +00002345 if ( __ptr_in_range(&*__first, data(), data() + size()))
2346 {
2347 const basic_string __temp(__first, __last, __alloc());
2348 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2349 }
2350
2351 size_type __sz = size();
2352 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002353 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002354 if (__cap - __sz >= __n)
2355 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002356 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002357 size_type __n_move = __sz - __ip;
2358 if (__n_move != 0)
2359 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2360 }
2361 else
2362 {
2363 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002364 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002365 }
2366 __sz += __n;
2367 __set_size(__sz);
2368 traits_type::assign(__p[__sz], value_type());
2369 for (__p += __ip; __first != __last; ++__p, ++__first)
2370 traits_type::assign(*__p, *__first);
2371 }
2372 return begin() + __ip;
2373}
2374
2375template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002376inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002377basic_string<_CharT, _Traits, _Allocator>&
2378basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2379{
2380 return insert(__pos1, __str.data(), __str.size());
2381}
2382
2383template <class _CharT, class _Traits, class _Allocator>
2384basic_string<_CharT, _Traits, _Allocator>&
2385basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2386 size_type __pos2, size_type __n)
2387{
2388 size_type __str_sz = __str.size();
2389 if (__pos2 > __str_sz)
2390 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002391 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002392}
2393
2394template <class _CharT, class _Traits, class _Allocator>
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002395inline _LIBCPP_INLINE_VISIBILITY
2396basic_string<_CharT, _Traits, _Allocator>&
2397basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, __self_view __sv,
2398 size_type __pos2, size_type __n)
2399{
2400 size_type __str_sz = __sv.size();
2401 if (__pos2 > __str_sz)
2402 this->__throw_out_of_range();
2403 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2404}
2405
2406template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002407basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002408basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002409{
Alp Tokerec34c482014-05-15 11:27:39 +00002410 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002411 return insert(__pos, __s, traits_type::length(__s));
2412}
2413
2414template <class _CharT, class _Traits, class _Allocator>
2415typename basic_string<_CharT, _Traits, _Allocator>::iterator
2416basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2417{
2418 size_type __ip = static_cast<size_type>(__pos - begin());
2419 size_type __sz = size();
2420 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002421 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002422 if (__cap == __sz)
2423 {
2424 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002425 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002426 }
2427 else
2428 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002429 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002430 size_type __n_move = __sz - __ip;
2431 if (__n_move != 0)
2432 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2433 }
2434 traits_type::assign(__p[__ip], __c);
2435 traits_type::assign(__p[++__sz], value_type());
2436 __set_size(__sz);
2437 return begin() + static_cast<difference_type>(__ip);
2438}
2439
2440template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002441inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002442typename basic_string<_CharT, _Traits, _Allocator>::iterator
2443basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2444{
Howard Hinnant499cea12013-08-23 17:37:05 +00002445#if _LIBCPP_DEBUG_LEVEL >= 2
2446 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2447 "string::insert(iterator, n, value) called with an iterator not"
2448 " referring to this string");
2449#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002450 difference_type __p = __pos - begin();
2451 insert(static_cast<size_type>(__p), __n, __c);
2452 return begin() + __p;
2453}
2454
2455// replace
2456
2457template <class _CharT, class _Traits, class _Allocator>
2458basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002459basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002460{
Alp Tokerec34c482014-05-15 11:27:39 +00002461 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002462 size_type __sz = size();
2463 if (__pos > __sz)
2464 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002465 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002466 size_type __cap = capacity();
2467 if (__cap - __sz + __n1 >= __n2)
2468 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002469 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002470 if (__n1 != __n2)
2471 {
2472 size_type __n_move = __sz - __pos - __n1;
2473 if (__n_move != 0)
2474 {
2475 if (__n1 > __n2)
2476 {
2477 traits_type::move(__p + __pos, __s, __n2);
2478 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2479 goto __finish;
2480 }
2481 if (__p + __pos < __s && __s < __p + __sz)
2482 {
2483 if (__p + __pos + __n1 <= __s)
2484 __s += __n2 - __n1;
2485 else // __p + __pos < __s < __p + __pos + __n1
2486 {
2487 traits_type::move(__p + __pos, __s, __n1);
2488 __pos += __n1;
2489 __s += __n2;
2490 __n2 -= __n1;
2491 __n1 = 0;
2492 }
2493 }
2494 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2495 }
2496 }
2497 traits_type::move(__p + __pos, __s, __n2);
2498__finish:
2499 __sz += __n2 - __n1;
2500 __set_size(__sz);
2501 __invalidate_iterators_past(__sz);
2502 traits_type::assign(__p[__sz], value_type());
2503 }
2504 else
2505 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2506 return *this;
2507}
2508
2509template <class _CharT, class _Traits, class _Allocator>
2510basic_string<_CharT, _Traits, _Allocator>&
2511basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
2512{
2513 size_type __sz = size();
2514 if (__pos > __sz)
2515 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002516 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002517 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002518 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002519 if (__cap - __sz + __n1 >= __n2)
2520 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002521 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002522 if (__n1 != __n2)
2523 {
2524 size_type __n_move = __sz - __pos - __n1;
2525 if (__n_move != 0)
2526 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2527 }
2528 }
2529 else
2530 {
2531 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002532 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002533 }
2534 traits_type::assign(__p + __pos, __n2, __c);
2535 __sz += __n2 - __n1;
2536 __set_size(__sz);
2537 __invalidate_iterators_past(__sz);
2538 traits_type::assign(__p[__sz], value_type());
2539 return *this;
2540}
2541
2542template <class _CharT, class _Traits, class _Allocator>
2543template<class _InputIterator>
2544typename enable_if
2545<
2546 __is_input_iterator<_InputIterator>::value,
2547 basic_string<_CharT, _Traits, _Allocator>&
2548>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002549basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002550 _InputIterator __j1, _InputIterator __j2)
2551{
Marshall Clowd979eed2016-09-05 01:54:30 +00002552 const basic_string __temp(__j1, __j2, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002553 return this->replace(__i1, __i2, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002554}
2555
2556template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002557inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002558basic_string<_CharT, _Traits, _Allocator>&
2559basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2560{
2561 return replace(__pos1, __n1, __str.data(), __str.size());
2562}
2563
2564template <class _CharT, class _Traits, class _Allocator>
2565basic_string<_CharT, _Traits, _Allocator>&
2566basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2567 size_type __pos2, size_type __n2)
2568{
2569 size_type __str_sz = __str.size();
2570 if (__pos2 > __str_sz)
2571 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002572 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002573}
2574
2575template <class _CharT, class _Traits, class _Allocator>
2576basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002577basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, __self_view __sv,
2578 size_type __pos2, size_type __n2)
2579{
2580 size_type __str_sz = __sv.size();
2581 if (__pos2 > __str_sz)
2582 this->__throw_out_of_range();
2583 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2584}
2585
2586template <class _CharT, class _Traits, class _Allocator>
2587basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002588basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002589{
Alp Tokerec34c482014-05-15 11:27:39 +00002590 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002591 return replace(__pos, __n1, __s, traits_type::length(__s));
2592}
2593
2594template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002595inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002596basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002597basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002598{
2599 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2600 __str.data(), __str.size());
2601}
2602
2603template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002604inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002605basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002606basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002607{
2608 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2609}
2610
2611template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002612inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002613basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002614basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002615{
2616 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2617}
2618
2619template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002620inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002621basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002622basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002623{
2624 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2625}
2626
2627// erase
2628
2629template <class _CharT, class _Traits, class _Allocator>
2630basic_string<_CharT, _Traits, _Allocator>&
2631basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2632{
2633 size_type __sz = size();
2634 if (__pos > __sz)
2635 this->__throw_out_of_range();
2636 if (__n)
2637 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002638 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002639 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002640 size_type __n_move = __sz - __pos - __n;
2641 if (__n_move != 0)
2642 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2643 __sz -= __n;
2644 __set_size(__sz);
2645 __invalidate_iterators_past(__sz);
2646 traits_type::assign(__p[__sz], value_type());
2647 }
2648 return *this;
2649}
2650
2651template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002652inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002653typename basic_string<_CharT, _Traits, _Allocator>::iterator
2654basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2655{
Howard Hinnant499cea12013-08-23 17:37:05 +00002656#if _LIBCPP_DEBUG_LEVEL >= 2
2657 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2658 "string::erase(iterator) called with an iterator not"
2659 " referring to this string");
2660#endif
2661 _LIBCPP_ASSERT(__pos != end(),
2662 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002663 iterator __b = begin();
2664 size_type __r = static_cast<size_type>(__pos - __b);
2665 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00002666 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002667}
2668
2669template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002670inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002671typename basic_string<_CharT, _Traits, _Allocator>::iterator
2672basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
2673{
Howard Hinnant499cea12013-08-23 17:37:05 +00002674#if _LIBCPP_DEBUG_LEVEL >= 2
2675 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
2676 "string::erase(iterator, iterator) called with an iterator not"
2677 " referring to this string");
2678#endif
2679 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002680 iterator __b = begin();
2681 size_type __r = static_cast<size_type>(__first - __b);
2682 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00002683 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002684}
2685
2686template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002687inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002688void
2689basic_string<_CharT, _Traits, _Allocator>::pop_back()
2690{
Howard Hinnant499cea12013-08-23 17:37:05 +00002691 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002692 size_type __sz;
2693 if (__is_long())
2694 {
2695 __sz = __get_long_size() - 1;
2696 __set_long_size(__sz);
2697 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
2698 }
2699 else
2700 {
2701 __sz = __get_short_size() - 1;
2702 __set_short_size(__sz);
2703 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
2704 }
2705 __invalidate_iterators_past(__sz);
2706}
2707
2708template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002709inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002710void
Howard Hinnanta6119a82011-05-29 19:57:12 +00002711basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002712{
2713 __invalidate_all_iterators();
2714 if (__is_long())
2715 {
2716 traits_type::assign(*__get_long_pointer(), value_type());
2717 __set_long_size(0);
2718 }
2719 else
2720 {
2721 traits_type::assign(*__get_short_pointer(), value_type());
2722 __set_short_size(0);
2723 }
2724}
2725
2726template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002727inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002728void
2729basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
2730{
2731 if (__is_long())
2732 {
2733 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
2734 __set_long_size(__pos);
2735 }
2736 else
2737 {
2738 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
2739 __set_short_size(__pos);
2740 }
2741 __invalidate_iterators_past(__pos);
2742}
2743
2744template <class _CharT, class _Traits, class _Allocator>
2745void
2746basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
2747{
2748 size_type __sz = size();
2749 if (__n > __sz)
2750 append(__n - __sz, __c);
2751 else
2752 __erase_to_end(__n);
2753}
2754
2755template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002756inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002757typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00002758basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002759{
Howard Hinnante32b5e22010-11-17 17:55:08 +00002760 size_type __m = __alloc_traits::max_size(__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002761#if _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:08 +00002762 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002763#else
Marshall Clow09f85502013-10-31 17:23:08 +00002764 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002765#endif
2766}
2767
2768template <class _CharT, class _Traits, class _Allocator>
2769void
2770basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
2771{
2772 if (__res_arg > max_size())
2773 this->__throw_length_error();
2774 size_type __cap = capacity();
2775 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002776 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002777 __res_arg = __recommend(__res_arg);
2778 if (__res_arg != __cap)
2779 {
2780 pointer __new_data, __p;
2781 bool __was_long, __now_long;
2782 if (__res_arg == __min_cap - 1)
2783 {
2784 __was_long = true;
2785 __now_long = false;
2786 __new_data = __get_short_pointer();
2787 __p = __get_long_pointer();
2788 }
2789 else
2790 {
2791 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002792 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002793 else
2794 {
2795 #ifndef _LIBCPP_NO_EXCEPTIONS
2796 try
2797 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002798 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00002799 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002800 #ifndef _LIBCPP_NO_EXCEPTIONS
2801 }
2802 catch (...)
2803 {
2804 return;
2805 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002806 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002807 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002808 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00002809 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002810 }
2811 __now_long = true;
2812 __was_long = __is_long();
2813 __p = __get_pointer();
2814 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002815 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
2816 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002817 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002818 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002819 if (__now_long)
2820 {
2821 __set_long_cap(__res_arg+1);
2822 __set_long_size(__sz);
2823 __set_long_pointer(__new_data);
2824 }
2825 else
2826 __set_short_size(__sz);
2827 __invalidate_all_iterators();
2828 }
2829}
2830
2831template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002832inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002833typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002834basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002835{
Howard Hinnant499cea12013-08-23 17:37:05 +00002836 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002837 return *(data() + __pos);
2838}
2839
2840template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002841inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002842typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002843basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002844{
Howard Hinnant499cea12013-08-23 17:37:05 +00002845 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002846 return *(__get_pointer() + __pos);
2847}
2848
2849template <class _CharT, class _Traits, class _Allocator>
2850typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2851basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
2852{
2853 if (__n >= size())
2854 this->__throw_out_of_range();
2855 return (*this)[__n];
2856}
2857
2858template <class _CharT, class _Traits, class _Allocator>
2859typename basic_string<_CharT, _Traits, _Allocator>::reference
2860basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
2861{
2862 if (__n >= size())
2863 this->__throw_out_of_range();
2864 return (*this)[__n];
2865}
2866
2867template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002868inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002869typename basic_string<_CharT, _Traits, _Allocator>::reference
2870basic_string<_CharT, _Traits, _Allocator>::front()
2871{
Howard Hinnant499cea12013-08-23 17:37:05 +00002872 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002873 return *__get_pointer();
2874}
2875
2876template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002877inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002878typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2879basic_string<_CharT, _Traits, _Allocator>::front() const
2880{
Howard Hinnant499cea12013-08-23 17:37:05 +00002881 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002882 return *data();
2883}
2884
2885template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002886inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002887typename basic_string<_CharT, _Traits, _Allocator>::reference
2888basic_string<_CharT, _Traits, _Allocator>::back()
2889{
Howard Hinnant499cea12013-08-23 17:37:05 +00002890 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002891 return *(__get_pointer() + size() - 1);
2892}
2893
2894template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002895inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002896typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2897basic_string<_CharT, _Traits, _Allocator>::back() const
2898{
Howard Hinnant499cea12013-08-23 17:37:05 +00002899 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002900 return *(data() + size() - 1);
2901}
2902
2903template <class _CharT, class _Traits, class _Allocator>
2904typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002905basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002906{
2907 size_type __sz = size();
2908 if (__pos > __sz)
2909 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002910 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002911 traits_type::copy(__s, data() + __pos, __rlen);
2912 return __rlen;
2913}
2914
2915template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002916inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002917basic_string<_CharT, _Traits, _Allocator>
2918basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
2919{
2920 return basic_string(*this, __pos, __n, __alloc());
2921}
2922
2923template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002924inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002925void
2926basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00002927#if _LIBCPP_STD_VER >= 14
2928 _NOEXCEPT
2929#else
2930 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2931 __is_nothrow_swappable<allocator_type>::value)
2932#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002933{
Howard Hinnant499cea12013-08-23 17:37:05 +00002934#if _LIBCPP_DEBUG_LEVEL >= 2
2935 if (!__is_long())
2936 __get_db()->__invalidate_all(this);
2937 if (!__str.__is_long())
2938 __get_db()->__invalidate_all(&__str);
2939 __get_db()->swap(this, &__str);
2940#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00002941 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow7d914d12015-07-13 20:04:56 +00002942 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002943}
2944
2945// find
2946
2947template <class _Traits>
2948struct _LIBCPP_HIDDEN __traits_eq
2949{
2950 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00002951 _LIBCPP_INLINE_VISIBILITY
2952 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
2953 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002954};
2955
2956template<class _CharT, class _Traits, class _Allocator>
2957typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002958basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00002959 size_type __pos,
2960 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002961{
Alp Tokerec34c482014-05-15 11:27:39 +00002962 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002963 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00002964 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002965}
2966
2967template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002968inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002969typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00002970basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
2971 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002972{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002973 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00002974 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002975}
2976
2977template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002978inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002979typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002980basic_string<_CharT, _Traits, _Allocator>::find(__self_view __sv,
2981 size_type __pos) const _NOEXCEPT
2982{
2983 return __str_find<value_type, size_type, traits_type, npos>
2984 (data(), size(), __sv.data(), __pos, __sv.size());
2985}
2986
2987template<class _CharT, class _Traits, class _Allocator>
2988inline _LIBCPP_INLINE_VISIBILITY
2989typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002990basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00002991 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002992{
Alp Tokerec34c482014-05-15 11:27:39 +00002993 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002994 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00002995 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002996}
2997
2998template<class _CharT, class _Traits, class _Allocator>
2999typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003000basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3001 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003002{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003003 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003004 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003005}
3006
3007// rfind
3008
3009template<class _CharT, class _Traits, class _Allocator>
3010typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003011basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003012 size_type __pos,
3013 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003014{
Alp Tokerec34c482014-05-15 11:27:39 +00003015 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003016 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003017 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003018}
3019
3020template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003021inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003022typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003023basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3024 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003025{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003026 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003027 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003028}
3029
3030template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003031inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003032typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003033basic_string<_CharT, _Traits, _Allocator>::rfind(__self_view __sv,
3034 size_type __pos) const _NOEXCEPT
3035{
3036 return __str_rfind<value_type, size_type, traits_type, npos>
3037 (data(), size(), __sv.data(), __pos, __sv.size());
3038}
3039
3040template<class _CharT, class _Traits, class _Allocator>
3041inline _LIBCPP_INLINE_VISIBILITY
3042typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003043basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003044 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003045{
Alp Tokerec34c482014-05-15 11:27:39 +00003046 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003047 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003048 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003049}
3050
3051template<class _CharT, class _Traits, class _Allocator>
3052typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003053basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3054 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003055{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003056 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003057 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003058}
3059
3060// find_first_of
3061
3062template<class _CharT, class _Traits, class _Allocator>
3063typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003064basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003065 size_type __pos,
3066 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003067{
Alp Tokerec34c482014-05-15 11:27:39 +00003068 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003069 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003070 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003071}
3072
3073template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003074inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003075typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003076basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3077 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003078{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003079 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003080 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003081}
3082
3083template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003084inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003085typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003086basic_string<_CharT, _Traits, _Allocator>::find_first_of(__self_view __sv,
3087 size_type __pos) const _NOEXCEPT
3088{
3089 return __str_find_first_of<value_type, size_type, traits_type, npos>
3090 (data(), size(), __sv.data(), __pos, __sv.size());
3091}
3092
3093template<class _CharT, class _Traits, class _Allocator>
3094inline _LIBCPP_INLINE_VISIBILITY
3095typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003096basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003097 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003098{
Alp Tokerec34c482014-05-15 11:27:39 +00003099 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003100 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003101 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003102}
3103
3104template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003105inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003106typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003107basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3108 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003109{
3110 return find(__c, __pos);
3111}
3112
3113// find_last_of
3114
3115template<class _CharT, class _Traits, class _Allocator>
3116typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003117basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003118 size_type __pos,
3119 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003120{
Alp Tokerec34c482014-05-15 11:27:39 +00003121 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003122 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003123 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003124}
3125
3126template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003127inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003128typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003129basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3130 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003131{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003132 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003133 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003134}
3135
3136template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003137inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003138typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003139basic_string<_CharT, _Traits, _Allocator>::find_last_of(__self_view __sv,
3140 size_type __pos) const _NOEXCEPT
3141{
3142 return __str_find_last_of<value_type, size_type, traits_type, npos>
3143 (data(), size(), __sv.data(), __pos, __sv.size());
3144}
3145
3146template<class _CharT, class _Traits, class _Allocator>
3147inline _LIBCPP_INLINE_VISIBILITY
3148typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003149basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003150 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003151{
Alp Tokerec34c482014-05-15 11:27:39 +00003152 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003153 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003154 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003155}
3156
3157template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003158inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003159typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003160basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3161 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003162{
3163 return rfind(__c, __pos);
3164}
3165
3166// find_first_not_of
3167
3168template<class _CharT, class _Traits, class _Allocator>
3169typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003170basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003171 size_type __pos,
3172 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003173{
Alp Tokerec34c482014-05-15 11:27:39 +00003174 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003175 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003176 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003177}
3178
3179template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003180inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003181typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003182basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3183 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003184{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003185 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003186 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003187}
3188
3189template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003190inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003191typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003192basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(__self_view __sv,
3193 size_type __pos) const _NOEXCEPT
3194{
3195 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3196 (data(), size(), __sv.data(), __pos, __sv.size());
3197}
3198
3199template<class _CharT, class _Traits, class _Allocator>
3200inline _LIBCPP_INLINE_VISIBILITY
3201typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003202basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003203 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003204{
Alp Tokerec34c482014-05-15 11:27:39 +00003205 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003206 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003207 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003208}
3209
3210template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003211inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003212typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003213basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3214 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003215{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003216 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003217 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003218}
3219
3220// find_last_not_of
3221
3222template<class _CharT, class _Traits, class _Allocator>
3223typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003224basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003225 size_type __pos,
3226 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003227{
Alp Tokerec34c482014-05-15 11:27:39 +00003228 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003229 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003230 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003231}
3232
3233template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003234inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003235typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003236basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3237 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003238{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003239 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003240 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003241}
3242
3243template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003244inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003245typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003246basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(__self_view __sv,
3247 size_type __pos) const _NOEXCEPT
3248{
3249 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3250 (data(), size(), __sv.data(), __pos, __sv.size());
3251}
3252
3253template<class _CharT, class _Traits, class _Allocator>
3254inline _LIBCPP_INLINE_VISIBILITY
3255typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003256basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003257 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003258{
Alp Tokerec34c482014-05-15 11:27:39 +00003259 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003260 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003261 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003262}
3263
3264template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003265inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003266typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003267basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3268 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003269{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003270 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003271 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003272}
3273
3274// compare
3275
3276template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003277inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003278int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003279basic_string<_CharT, _Traits, _Allocator>::compare(__self_view __sv) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003280{
Howard Hinnantfa06d752011-07-24 21:45:06 +00003281 size_t __lhs_sz = size();
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003282 size_t __rhs_sz = __sv.size();
3283 int __result = traits_type::compare(data(), __sv.data(),
Howard Hinnantfa06d752011-07-24 21:45:06 +00003284 _VSTD::min(__lhs_sz, __rhs_sz));
3285 if (__result != 0)
3286 return __result;
3287 if (__lhs_sz < __rhs_sz)
3288 return -1;
3289 if (__lhs_sz > __rhs_sz)
3290 return 1;
3291 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003292}
3293
3294template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003295inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003296int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003297basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003298{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003299 return compare(__self_view(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003300}
3301
3302template <class _CharT, class _Traits, class _Allocator>
3303int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003304basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3305 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003306 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003307 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003308{
Alp Tokerec34c482014-05-15 11:27:39 +00003309 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003310 size_type __sz = size();
3311 if (__pos1 > __sz || __n2 == npos)
3312 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003313 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3314 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003315 if (__r == 0)
3316 {
3317 if (__rlen < __n2)
3318 __r = -1;
3319 else if (__rlen > __n2)
3320 __r = 1;
3321 }
3322 return __r;
3323}
3324
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003325template <class _CharT, class _Traits, class _Allocator>
3326inline _LIBCPP_INLINE_VISIBILITY
3327int
3328basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3329 size_type __n1,
3330 __self_view __sv) const
3331{
3332 return compare(__pos1, __n1, __sv.data(), __sv.size());
3333}
3334
3335template <class _CharT, class _Traits, class _Allocator>
3336inline _LIBCPP_INLINE_VISIBILITY
3337int
3338basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3339 size_type __n1,
3340 const basic_string& __str) const
3341{
3342 return compare(__pos1, __n1, __str.data(), __str.size());
3343}
3344
3345template <class _CharT, class _Traits, class _Allocator>
3346int inline _LIBCPP_INLINE_VISIBILITY
3347basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3348 size_type __n1,
3349 __self_view __sv,
3350 size_type __pos2,
3351 size_type __n2) const
3352{
3353 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3354}
3355
3356template <class _CharT, class _Traits, class _Allocator>
3357int
3358basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3359 size_type __n1,
3360 const basic_string& __str,
3361 size_type __pos2,
3362 size_type __n2) const
3363{
3364 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3365}
3366
3367template <class _CharT, class _Traits, class _Allocator>
3368int
3369basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3370{
3371 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3372 return compare(0, npos, __s, traits_type::length(__s));
3373}
3374
3375template <class _CharT, class _Traits, class _Allocator>
3376int
3377basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3378 size_type __n1,
3379 const value_type* __s) const
3380{
3381 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3382 return compare(__pos1, __n1, __s, traits_type::length(__s));
3383}
3384
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003385// __invariants
3386
3387template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003388inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003389bool
3390basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3391{
3392 if (size() > capacity())
3393 return false;
3394 if (capacity() < __min_cap - 1)
3395 return false;
3396 if (data() == 0)
3397 return false;
3398 if (data()[size()] != value_type(0))
3399 return false;
3400 return true;
3401}
3402
3403// operator==
3404
3405template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003406inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003407bool
3408operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003409 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003410{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003411 size_t __lhs_sz = __lhs.size();
3412 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3413 __rhs.data(),
3414 __lhs_sz) == 0;
3415}
3416
3417template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003418inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:13 +00003419bool
3420operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3421 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3422{
3423 size_t __lhs_sz = __lhs.size();
3424 if (__lhs_sz != __rhs.size())
3425 return false;
3426 const char* __lp = __lhs.data();
3427 const char* __rp = __rhs.data();
3428 if (__lhs.__is_long())
3429 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3430 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3431 if (*__lp != *__rp)
3432 return false;
3433 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003434}
3435
3436template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003437inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003438bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003439operator==(const _CharT* __lhs,
3440 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003441{
Eric Fiselier4f241822015-08-28 03:02:37 +00003442 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3443 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3444 size_t __lhs_len = _Traits::length(__lhs);
3445 if (__lhs_len != __rhs.size()) return false;
3446 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003447}
3448
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003449template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003450inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003451bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003452operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3453 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003454{
Eric Fiselier4f241822015-08-28 03:02:37 +00003455 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3456 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3457 size_t __rhs_len = _Traits::length(__rhs);
3458 if (__rhs_len != __lhs.size()) return false;
3459 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003460}
3461
Howard Hinnant324bb032010-08-22 00:02:43 +00003462template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003463inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003464bool
3465operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003466 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003467{
3468 return !(__lhs == __rhs);
3469}
3470
3471template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003472inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003473bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003474operator!=(const _CharT* __lhs,
3475 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003476{
3477 return !(__lhs == __rhs);
3478}
3479
3480template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003481inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003482bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003483operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3484 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003485{
3486 return !(__lhs == __rhs);
3487}
3488
3489// operator<
3490
3491template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003492inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003493bool
3494operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003495 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003496{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003497 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003498}
3499
3500template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003501inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003502bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003503operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3504 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003505{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003506 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003507}
3508
3509template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003510inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003511bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003512operator< (const _CharT* __lhs,
3513 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003514{
3515 return __rhs.compare(__lhs) > 0;
3516}
3517
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003518// operator>
3519
3520template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003521inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003522bool
3523operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003524 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003525{
3526 return __rhs < __lhs;
3527}
3528
3529template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003530inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003531bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003532operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3533 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003534{
3535 return __rhs < __lhs;
3536}
3537
3538template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003539inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003540bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003541operator> (const _CharT* __lhs,
3542 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003543{
3544 return __rhs < __lhs;
3545}
3546
3547// operator<=
3548
3549template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003550inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003551bool
3552operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003553 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003554{
3555 return !(__rhs < __lhs);
3556}
3557
3558template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003559inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003560bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003561operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3562 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003563{
3564 return !(__rhs < __lhs);
3565}
3566
3567template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003568inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003569bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003570operator<=(const _CharT* __lhs,
3571 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003572{
3573 return !(__rhs < __lhs);
3574}
3575
3576// operator>=
3577
3578template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003579inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003580bool
3581operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003582 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003583{
3584 return !(__lhs < __rhs);
3585}
3586
3587template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003588inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003589bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003590operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3591 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003592{
3593 return !(__lhs < __rhs);
3594}
3595
3596template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003597inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003598bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003599operator>=(const _CharT* __lhs,
3600 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003601{
3602 return !(__lhs < __rhs);
3603}
3604
3605// operator +
3606
3607template<class _CharT, class _Traits, class _Allocator>
3608basic_string<_CharT, _Traits, _Allocator>
3609operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3610 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3611{
3612 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3613 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3614 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3615 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3616 __r.append(__rhs.data(), __rhs_sz);
3617 return __r;
3618}
3619
3620template<class _CharT, class _Traits, class _Allocator>
3621basic_string<_CharT, _Traits, _Allocator>
3622operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3623{
3624 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3625 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
3626 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3627 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
3628 __r.append(__rhs.data(), __rhs_sz);
3629 return __r;
3630}
3631
3632template<class _CharT, class _Traits, class _Allocator>
3633basic_string<_CharT, _Traits, _Allocator>
3634operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3635{
3636 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3637 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3638 __r.__init(&__lhs, 1, 1 + __rhs_sz);
3639 __r.append(__rhs.data(), __rhs_sz);
3640 return __r;
3641}
3642
3643template<class _CharT, class _Traits, class _Allocator>
3644basic_string<_CharT, _Traits, _Allocator>
3645operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
3646{
3647 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3648 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3649 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
3650 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3651 __r.append(__rhs, __rhs_sz);
3652 return __r;
3653}
3654
3655template<class _CharT, class _Traits, class _Allocator>
3656basic_string<_CharT, _Traits, _Allocator>
3657operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
3658{
3659 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3660 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3661 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
3662 __r.push_back(__rhs);
3663 return __r;
3664}
3665
Howard Hinnant73d21a42010-09-04 23:28:19 +00003666#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003667
3668template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003669inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003670basic_string<_CharT, _Traits, _Allocator>
3671operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3672{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003673 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003674}
3675
3676template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003677inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003678basic_string<_CharT, _Traits, _Allocator>
3679operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3680{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003681 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003682}
3683
3684template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003685inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003686basic_string<_CharT, _Traits, _Allocator>
3687operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3688{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003689 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003690}
3691
3692template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003693inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003694basic_string<_CharT, _Traits, _Allocator>
3695operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3696{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003697 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003698}
3699
3700template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003701inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003702basic_string<_CharT, _Traits, _Allocator>
3703operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3704{
3705 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003706 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003707}
3708
3709template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003710inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003711basic_string<_CharT, _Traits, _Allocator>
3712operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
3713{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003714 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003715}
3716
3717template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003718inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003719basic_string<_CharT, _Traits, _Allocator>
3720operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
3721{
3722 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003723 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003724}
3725
Howard Hinnant73d21a42010-09-04 23:28:19 +00003726#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003727
3728// swap
3729
3730template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003731inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003732void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003733swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00003734 basic_string<_CharT, _Traits, _Allocator>& __rhs)
3735 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003736{
3737 __lhs.swap(__rhs);
3738}
3739
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003740#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
3741
3742typedef basic_string<char16_t> u16string;
3743typedef basic_string<char32_t> u32string;
3744
Howard Hinnant324bb032010-08-22 00:02:43 +00003745#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003746
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003747_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
3748_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
3749_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
3750_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
3751_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003752
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003753_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
3754_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
3755_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003756
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003757_LIBCPP_FUNC_VIS string to_string(int __val);
3758_LIBCPP_FUNC_VIS string to_string(unsigned __val);
3759_LIBCPP_FUNC_VIS string to_string(long __val);
3760_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
3761_LIBCPP_FUNC_VIS string to_string(long long __val);
3762_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
3763_LIBCPP_FUNC_VIS string to_string(float __val);
3764_LIBCPP_FUNC_VIS string to_string(double __val);
3765_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003766
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003767_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
3768_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
3769_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
3770_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
3771_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003772
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003773_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
3774_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
3775_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003776
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003777_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
3778_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
3779_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
3780_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
3781_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
3782_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
3783_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
3784_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
3785_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003786
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003787template<class _CharT, class _Traits, class _Allocator>
3788 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
3789 basic_string<_CharT, _Traits, _Allocator>::npos;
3790
3791template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003792struct _LIBCPP_TYPE_VIS_ONLY hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003793 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
3794{
3795 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00003796 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003797};
3798
3799template<class _CharT, class _Traits, class _Allocator>
3800size_t
3801hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00003802 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003803{
Sean Huntaffd9e52011-07-29 23:31:56 +00003804 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003805}
3806
Howard Hinnant464aa5c2011-07-18 15:51:59 +00003807template<class _CharT, class _Traits, class _Allocator>
3808basic_ostream<_CharT, _Traits>&
3809operator<<(basic_ostream<_CharT, _Traits>& __os,
3810 const basic_string<_CharT, _Traits, _Allocator>& __str);
3811
3812template<class _CharT, class _Traits, class _Allocator>
3813basic_istream<_CharT, _Traits>&
3814operator>>(basic_istream<_CharT, _Traits>& __is,
3815 basic_string<_CharT, _Traits, _Allocator>& __str);
3816
3817template<class _CharT, class _Traits, class _Allocator>
3818basic_istream<_CharT, _Traits>&
3819getline(basic_istream<_CharT, _Traits>& __is,
3820 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3821
3822template<class _CharT, class _Traits, class _Allocator>
3823inline _LIBCPP_INLINE_VISIBILITY
3824basic_istream<_CharT, _Traits>&
3825getline(basic_istream<_CharT, _Traits>& __is,
3826 basic_string<_CharT, _Traits, _Allocator>& __str);
3827
3828#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3829
3830template<class _CharT, class _Traits, class _Allocator>
3831inline _LIBCPP_INLINE_VISIBILITY
3832basic_istream<_CharT, _Traits>&
3833getline(basic_istream<_CharT, _Traits>&& __is,
3834 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3835
3836template<class _CharT, class _Traits, class _Allocator>
3837inline _LIBCPP_INLINE_VISIBILITY
3838basic_istream<_CharT, _Traits>&
3839getline(basic_istream<_CharT, _Traits>&& __is,
3840 basic_string<_CharT, _Traits, _Allocator>& __str);
3841
3842#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3843
Howard Hinnant499cea12013-08-23 17:37:05 +00003844#if _LIBCPP_DEBUG_LEVEL >= 2
3845
3846template<class _CharT, class _Traits, class _Allocator>
3847bool
3848basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
3849{
3850 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
3851 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
3852}
3853
3854template<class _CharT, class _Traits, class _Allocator>
3855bool
3856basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
3857{
3858 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
3859 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
3860}
3861
3862template<class _CharT, class _Traits, class _Allocator>
3863bool
3864basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
3865{
3866 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
3867 return this->data() <= __p && __p <= this->data() + this->size();
3868}
3869
3870template<class _CharT, class _Traits, class _Allocator>
3871bool
3872basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
3873{
3874 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
3875 return this->data() <= __p && __p < this->data() + this->size();
3876}
3877
3878#endif // _LIBCPP_DEBUG_LEVEL >= 2
3879
Marshall Clow15234322013-07-23 17:05:24 +00003880#if _LIBCPP_STD_VER > 11
3881// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:32 +00003882inline namespace literals
Marshall Clow15234322013-07-23 17:05:24 +00003883{
3884 inline namespace string_literals
3885 {
Howard Hinnantab61b2c2013-08-07 19:39:48 +00003886 inline _LIBCPP_INLINE_VISIBILITY
3887 basic_string<char> operator "" s( const char *__str, size_t __len )
3888 {
3889 return basic_string<char> (__str, __len);
3890 }
Marshall Clow15234322013-07-23 17:05:24 +00003891
Howard Hinnantab61b2c2013-08-07 19:39:48 +00003892 inline _LIBCPP_INLINE_VISIBILITY
3893 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
3894 {
3895 return basic_string<wchar_t> (__str, __len);
3896 }
Marshall Clow15234322013-07-23 17:05:24 +00003897
Howard Hinnantab61b2c2013-08-07 19:39:48 +00003898 inline _LIBCPP_INLINE_VISIBILITY
3899 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
3900 {
3901 return basic_string<char16_t> (__str, __len);
3902 }
Marshall Clow15234322013-07-23 17:05:24 +00003903
Howard Hinnantab61b2c2013-08-07 19:39:48 +00003904 inline _LIBCPP_INLINE_VISIBILITY
3905 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
3906 {
3907 return basic_string<char32_t> (__str, __len);
3908 }
Marshall Clow15234322013-07-23 17:05:24 +00003909 }
3910}
3911#endif
3912
Eric Fiselier833d6442016-09-15 22:27:07 +00003913_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>)
3914_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>)
Howard Hinnant499cea12013-08-23 17:37:05 +00003915_LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003916
3917_LIBCPP_END_NAMESPACE_STD
3918
3919#endif // _LIBCPP_STRING