blob: 53ddf5e3bfbc16f447014d9df696b28329c25f16 [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
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000577_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_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);
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001027 _LIBCPP_INLINE_VISIBILITY
1028 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 Clowdf9db312016-01-13 21:54:34 +00002001 basic_string __temp(__first, __last, __alloc());
2002 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 Clow1e00d6d2016-07-21 05:31:24 +00002154 basic_string __temp (__first, __last, __alloc());
2155 append(__temp.data(), __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002156 return *this;
2157}
2158
2159template <class _CharT, class _Traits, class _Allocator>
2160template<class _ForwardIterator>
2161typename enable_if
2162<
Marshall Clowdf9db312016-01-13 21:54:34 +00002163 __is_forward_iterator<_ForwardIterator>::value
2164 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002165 basic_string<_CharT, _Traits, _Allocator>&
2166>::type
2167basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
2168{
2169 size_type __sz = size();
2170 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002171 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002172 if (__n)
2173 {
2174 if (__cap - __sz < __n)
2175 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2176 pointer __p = __get_pointer() + __sz;
2177 for (; __first != __last; ++__p, ++__first)
2178 traits_type::assign(*__p, *__first);
2179 traits_type::assign(*__p, value_type());
2180 __set_size(__sz + __n);
2181 }
2182 return *this;
2183}
2184
2185template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002186inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002187basic_string<_CharT, _Traits, _Allocator>&
2188basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2189{
2190 return append(__str.data(), __str.size());
2191}
2192
2193template <class _CharT, class _Traits, class _Allocator>
2194basic_string<_CharT, _Traits, _Allocator>&
2195basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2196{
2197 size_type __sz = __str.size();
2198 if (__pos > __sz)
2199 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002200 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002201}
2202
2203template <class _CharT, class _Traits, class _Allocator>
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002204inline _LIBCPP_INLINE_VISIBILITY
2205basic_string<_CharT, _Traits, _Allocator>&
2206basic_string<_CharT, _Traits, _Allocator>::append(__self_view __sv, size_type __pos, size_type __n)
2207{
2208 size_type __sz = __sv.size();
2209 if (__pos > __sz)
2210 this->__throw_out_of_range();
2211 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2212}
2213
2214template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002215basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002216basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002217{
Alp Tokerec34c482014-05-15 11:27:39 +00002218 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002219 return append(__s, traits_type::length(__s));
2220}
2221
2222// insert
2223
2224template <class _CharT, class _Traits, class _Allocator>
2225basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002226basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002227{
Alp Tokerec34c482014-05-15 11:27:39 +00002228 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002229 size_type __sz = size();
2230 if (__pos > __sz)
2231 this->__throw_out_of_range();
2232 size_type __cap = capacity();
2233 if (__cap - __sz >= __n)
2234 {
2235 if (__n)
2236 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002237 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002238 size_type __n_move = __sz - __pos;
2239 if (__n_move != 0)
2240 {
2241 if (__p + __pos <= __s && __s < __p + __sz)
2242 __s += __n;
2243 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2244 }
2245 traits_type::move(__p + __pos, __s, __n);
2246 __sz += __n;
2247 __set_size(__sz);
2248 traits_type::assign(__p[__sz], value_type());
2249 }
2250 }
2251 else
2252 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2253 return *this;
2254}
2255
2256template <class _CharT, class _Traits, class _Allocator>
2257basic_string<_CharT, _Traits, _Allocator>&
2258basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2259{
2260 size_type __sz = size();
2261 if (__pos > __sz)
2262 this->__throw_out_of_range();
2263 if (__n)
2264 {
2265 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002266 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002267 if (__cap - __sz >= __n)
2268 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002269 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002270 size_type __n_move = __sz - __pos;
2271 if (__n_move != 0)
2272 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2273 }
2274 else
2275 {
2276 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002277 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002278 }
2279 traits_type::assign(__p + __pos, __n, __c);
2280 __sz += __n;
2281 __set_size(__sz);
2282 traits_type::assign(__p[__sz], value_type());
2283 }
2284 return *this;
2285}
2286
2287template <class _CharT, class _Traits, class _Allocator>
2288template<class _InputIterator>
2289typename enable_if
2290<
Marshall Clowdf9db312016-01-13 21:54:34 +00002291 __is_exactly_input_iterator<_InputIterator>::value
2292 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2293 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002294>::type
2295basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2296{
Howard Hinnant499cea12013-08-23 17:37:05 +00002297#if _LIBCPP_DEBUG_LEVEL >= 2
2298 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2299 "string::insert(iterator, range) called with an iterator not"
2300 " referring to this string");
2301#endif
Marshall Clowdf9db312016-01-13 21:54:34 +00002302 basic_string __temp(__first, __last, __alloc());
2303 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002304}
2305
2306template <class _CharT, class _Traits, class _Allocator>
2307template<class _ForwardIterator>
2308typename enable_if
2309<
Marshall Clowdf9db312016-01-13 21:54:34 +00002310 __is_forward_iterator<_ForwardIterator>::value
2311 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002312 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2313>::type
2314basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2315{
Howard Hinnant499cea12013-08-23 17:37:05 +00002316#if _LIBCPP_DEBUG_LEVEL >= 2
2317 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2318 "string::insert(iterator, range) called with an iterator not"
2319 " referring to this string");
2320#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002321 size_type __ip = static_cast<size_type>(__pos - begin());
2322 size_type __sz = size();
2323 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002324 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002325 if (__n)
2326 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002327 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002328 if (__cap - __sz >= __n)
2329 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002330 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002331 size_type __n_move = __sz - __ip;
2332 if (__n_move != 0)
2333 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2334 }
2335 else
2336 {
2337 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002338 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002339 }
2340 __sz += __n;
2341 __set_size(__sz);
2342 traits_type::assign(__p[__sz], value_type());
2343 for (__p += __ip; __first != __last; ++__p, ++__first)
2344 traits_type::assign(*__p, *__first);
2345 }
2346 return begin() + __ip;
2347}
2348
2349template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002350inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002351basic_string<_CharT, _Traits, _Allocator>&
2352basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2353{
2354 return insert(__pos1, __str.data(), __str.size());
2355}
2356
2357template <class _CharT, class _Traits, class _Allocator>
2358basic_string<_CharT, _Traits, _Allocator>&
2359basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2360 size_type __pos2, size_type __n)
2361{
2362 size_type __str_sz = __str.size();
2363 if (__pos2 > __str_sz)
2364 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002365 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002366}
2367
2368template <class _CharT, class _Traits, class _Allocator>
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002369inline _LIBCPP_INLINE_VISIBILITY
2370basic_string<_CharT, _Traits, _Allocator>&
2371basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, __self_view __sv,
2372 size_type __pos2, size_type __n)
2373{
2374 size_type __str_sz = __sv.size();
2375 if (__pos2 > __str_sz)
2376 this->__throw_out_of_range();
2377 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2378}
2379
2380template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002381basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002382basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002383{
Alp Tokerec34c482014-05-15 11:27:39 +00002384 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002385 return insert(__pos, __s, traits_type::length(__s));
2386}
2387
2388template <class _CharT, class _Traits, class _Allocator>
2389typename basic_string<_CharT, _Traits, _Allocator>::iterator
2390basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2391{
2392 size_type __ip = static_cast<size_type>(__pos - begin());
2393 size_type __sz = size();
2394 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002395 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002396 if (__cap == __sz)
2397 {
2398 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002399 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002400 }
2401 else
2402 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002403 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002404 size_type __n_move = __sz - __ip;
2405 if (__n_move != 0)
2406 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2407 }
2408 traits_type::assign(__p[__ip], __c);
2409 traits_type::assign(__p[++__sz], value_type());
2410 __set_size(__sz);
2411 return begin() + static_cast<difference_type>(__ip);
2412}
2413
2414template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002415inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002416typename basic_string<_CharT, _Traits, _Allocator>::iterator
2417basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2418{
Howard Hinnant499cea12013-08-23 17:37:05 +00002419#if _LIBCPP_DEBUG_LEVEL >= 2
2420 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2421 "string::insert(iterator, n, value) called with an iterator not"
2422 " referring to this string");
2423#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002424 difference_type __p = __pos - begin();
2425 insert(static_cast<size_type>(__p), __n, __c);
2426 return begin() + __p;
2427}
2428
2429// replace
2430
2431template <class _CharT, class _Traits, class _Allocator>
2432basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002433basic_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 +00002434{
Alp Tokerec34c482014-05-15 11:27:39 +00002435 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002436 size_type __sz = size();
2437 if (__pos > __sz)
2438 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002439 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002440 size_type __cap = capacity();
2441 if (__cap - __sz + __n1 >= __n2)
2442 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002443 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002444 if (__n1 != __n2)
2445 {
2446 size_type __n_move = __sz - __pos - __n1;
2447 if (__n_move != 0)
2448 {
2449 if (__n1 > __n2)
2450 {
2451 traits_type::move(__p + __pos, __s, __n2);
2452 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2453 goto __finish;
2454 }
2455 if (__p + __pos < __s && __s < __p + __sz)
2456 {
2457 if (__p + __pos + __n1 <= __s)
2458 __s += __n2 - __n1;
2459 else // __p + __pos < __s < __p + __pos + __n1
2460 {
2461 traits_type::move(__p + __pos, __s, __n1);
2462 __pos += __n1;
2463 __s += __n2;
2464 __n2 -= __n1;
2465 __n1 = 0;
2466 }
2467 }
2468 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2469 }
2470 }
2471 traits_type::move(__p + __pos, __s, __n2);
2472__finish:
2473 __sz += __n2 - __n1;
2474 __set_size(__sz);
2475 __invalidate_iterators_past(__sz);
2476 traits_type::assign(__p[__sz], value_type());
2477 }
2478 else
2479 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2480 return *this;
2481}
2482
2483template <class _CharT, class _Traits, class _Allocator>
2484basic_string<_CharT, _Traits, _Allocator>&
2485basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
2486{
2487 size_type __sz = size();
2488 if (__pos > __sz)
2489 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002490 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002491 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002492 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002493 if (__cap - __sz + __n1 >= __n2)
2494 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002495 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002496 if (__n1 != __n2)
2497 {
2498 size_type __n_move = __sz - __pos - __n1;
2499 if (__n_move != 0)
2500 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2501 }
2502 }
2503 else
2504 {
2505 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002506 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002507 }
2508 traits_type::assign(__p + __pos, __n2, __c);
2509 __sz += __n2 - __n1;
2510 __set_size(__sz);
2511 __invalidate_iterators_past(__sz);
2512 traits_type::assign(__p[__sz], value_type());
2513 return *this;
2514}
2515
2516template <class _CharT, class _Traits, class _Allocator>
2517template<class _InputIterator>
2518typename enable_if
2519<
2520 __is_input_iterator<_InputIterator>::value,
2521 basic_string<_CharT, _Traits, _Allocator>&
2522>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002523basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002524 _InputIterator __j1, _InputIterator __j2)
2525{
Marshall Clowdf9db312016-01-13 21:54:34 +00002526 basic_string __temp(__j1, __j2, __alloc());
2527 return this->replace(__i1, __i2, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002528}
2529
2530template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002531inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002532basic_string<_CharT, _Traits, _Allocator>&
2533basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2534{
2535 return replace(__pos1, __n1, __str.data(), __str.size());
2536}
2537
2538template <class _CharT, class _Traits, class _Allocator>
2539basic_string<_CharT, _Traits, _Allocator>&
2540basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2541 size_type __pos2, size_type __n2)
2542{
2543 size_type __str_sz = __str.size();
2544 if (__pos2 > __str_sz)
2545 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002546 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002547}
2548
2549template <class _CharT, class _Traits, class _Allocator>
2550basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002551basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, __self_view __sv,
2552 size_type __pos2, size_type __n2)
2553{
2554 size_type __str_sz = __sv.size();
2555 if (__pos2 > __str_sz)
2556 this->__throw_out_of_range();
2557 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2558}
2559
2560template <class _CharT, class _Traits, class _Allocator>
2561basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002562basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002563{
Alp Tokerec34c482014-05-15 11:27:39 +00002564 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002565 return replace(__pos, __n1, __s, traits_type::length(__s));
2566}
2567
2568template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002569inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002570basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002571basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002572{
2573 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2574 __str.data(), __str.size());
2575}
2576
2577template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002578inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002579basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002580basic_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 +00002581{
2582 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2583}
2584
2585template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002586inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002587basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002588basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002589{
2590 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2591}
2592
2593template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002594inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002595basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002596basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002597{
2598 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2599}
2600
2601// erase
2602
2603template <class _CharT, class _Traits, class _Allocator>
2604basic_string<_CharT, _Traits, _Allocator>&
2605basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2606{
2607 size_type __sz = size();
2608 if (__pos > __sz)
2609 this->__throw_out_of_range();
2610 if (__n)
2611 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002612 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002613 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002614 size_type __n_move = __sz - __pos - __n;
2615 if (__n_move != 0)
2616 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2617 __sz -= __n;
2618 __set_size(__sz);
2619 __invalidate_iterators_past(__sz);
2620 traits_type::assign(__p[__sz], value_type());
2621 }
2622 return *this;
2623}
2624
2625template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002626inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002627typename basic_string<_CharT, _Traits, _Allocator>::iterator
2628basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2629{
Howard Hinnant499cea12013-08-23 17:37:05 +00002630#if _LIBCPP_DEBUG_LEVEL >= 2
2631 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2632 "string::erase(iterator) called with an iterator not"
2633 " referring to this string");
2634#endif
2635 _LIBCPP_ASSERT(__pos != end(),
2636 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002637 iterator __b = begin();
2638 size_type __r = static_cast<size_type>(__pos - __b);
2639 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00002640 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002641}
2642
2643template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002644inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002645typename basic_string<_CharT, _Traits, _Allocator>::iterator
2646basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
2647{
Howard Hinnant499cea12013-08-23 17:37:05 +00002648#if _LIBCPP_DEBUG_LEVEL >= 2
2649 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
2650 "string::erase(iterator, iterator) called with an iterator not"
2651 " referring to this string");
2652#endif
2653 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002654 iterator __b = begin();
2655 size_type __r = static_cast<size_type>(__first - __b);
2656 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00002657 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002658}
2659
2660template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002661inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002662void
2663basic_string<_CharT, _Traits, _Allocator>::pop_back()
2664{
Howard Hinnant499cea12013-08-23 17:37:05 +00002665 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002666 size_type __sz;
2667 if (__is_long())
2668 {
2669 __sz = __get_long_size() - 1;
2670 __set_long_size(__sz);
2671 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
2672 }
2673 else
2674 {
2675 __sz = __get_short_size() - 1;
2676 __set_short_size(__sz);
2677 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
2678 }
2679 __invalidate_iterators_past(__sz);
2680}
2681
2682template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002683inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002684void
Howard Hinnanta6119a82011-05-29 19:57:12 +00002685basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002686{
2687 __invalidate_all_iterators();
2688 if (__is_long())
2689 {
2690 traits_type::assign(*__get_long_pointer(), value_type());
2691 __set_long_size(0);
2692 }
2693 else
2694 {
2695 traits_type::assign(*__get_short_pointer(), value_type());
2696 __set_short_size(0);
2697 }
2698}
2699
2700template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002701inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002702void
2703basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
2704{
2705 if (__is_long())
2706 {
2707 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
2708 __set_long_size(__pos);
2709 }
2710 else
2711 {
2712 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
2713 __set_short_size(__pos);
2714 }
2715 __invalidate_iterators_past(__pos);
2716}
2717
2718template <class _CharT, class _Traits, class _Allocator>
2719void
2720basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
2721{
2722 size_type __sz = size();
2723 if (__n > __sz)
2724 append(__n - __sz, __c);
2725 else
2726 __erase_to_end(__n);
2727}
2728
2729template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002730inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002731typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00002732basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002733{
Howard Hinnante32b5e22010-11-17 17:55:08 +00002734 size_type __m = __alloc_traits::max_size(__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002735#if _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:08 +00002736 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002737#else
Marshall Clow09f85502013-10-31 17:23:08 +00002738 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002739#endif
2740}
2741
2742template <class _CharT, class _Traits, class _Allocator>
2743void
2744basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
2745{
2746 if (__res_arg > max_size())
2747 this->__throw_length_error();
2748 size_type __cap = capacity();
2749 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002750 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002751 __res_arg = __recommend(__res_arg);
2752 if (__res_arg != __cap)
2753 {
2754 pointer __new_data, __p;
2755 bool __was_long, __now_long;
2756 if (__res_arg == __min_cap - 1)
2757 {
2758 __was_long = true;
2759 __now_long = false;
2760 __new_data = __get_short_pointer();
2761 __p = __get_long_pointer();
2762 }
2763 else
2764 {
2765 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002766 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002767 else
2768 {
2769 #ifndef _LIBCPP_NO_EXCEPTIONS
2770 try
2771 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002772 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00002773 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002774 #ifndef _LIBCPP_NO_EXCEPTIONS
2775 }
2776 catch (...)
2777 {
2778 return;
2779 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002780 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002781 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002782 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00002783 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002784 }
2785 __now_long = true;
2786 __was_long = __is_long();
2787 __p = __get_pointer();
2788 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002789 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
2790 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002791 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002792 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002793 if (__now_long)
2794 {
2795 __set_long_cap(__res_arg+1);
2796 __set_long_size(__sz);
2797 __set_long_pointer(__new_data);
2798 }
2799 else
2800 __set_short_size(__sz);
2801 __invalidate_all_iterators();
2802 }
2803}
2804
2805template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002806inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002807typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002808basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002809{
Howard Hinnant499cea12013-08-23 17:37:05 +00002810 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002811 return *(data() + __pos);
2812}
2813
2814template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002815inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002816typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002817basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002818{
Howard Hinnant499cea12013-08-23 17:37:05 +00002819 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002820 return *(__get_pointer() + __pos);
2821}
2822
2823template <class _CharT, class _Traits, class _Allocator>
2824typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2825basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
2826{
2827 if (__n >= size())
2828 this->__throw_out_of_range();
2829 return (*this)[__n];
2830}
2831
2832template <class _CharT, class _Traits, class _Allocator>
2833typename basic_string<_CharT, _Traits, _Allocator>::reference
2834basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
2835{
2836 if (__n >= size())
2837 this->__throw_out_of_range();
2838 return (*this)[__n];
2839}
2840
2841template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002842inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002843typename basic_string<_CharT, _Traits, _Allocator>::reference
2844basic_string<_CharT, _Traits, _Allocator>::front()
2845{
Howard Hinnant499cea12013-08-23 17:37:05 +00002846 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002847 return *__get_pointer();
2848}
2849
2850template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002851inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002852typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2853basic_string<_CharT, _Traits, _Allocator>::front() const
2854{
Howard Hinnant499cea12013-08-23 17:37:05 +00002855 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002856 return *data();
2857}
2858
2859template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002860inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002861typename basic_string<_CharT, _Traits, _Allocator>::reference
2862basic_string<_CharT, _Traits, _Allocator>::back()
2863{
Howard Hinnant499cea12013-08-23 17:37:05 +00002864 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002865 return *(__get_pointer() + size() - 1);
2866}
2867
2868template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002869inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002870typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2871basic_string<_CharT, _Traits, _Allocator>::back() const
2872{
Howard Hinnant499cea12013-08-23 17:37:05 +00002873 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002874 return *(data() + size() - 1);
2875}
2876
2877template <class _CharT, class _Traits, class _Allocator>
2878typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002879basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002880{
2881 size_type __sz = size();
2882 if (__pos > __sz)
2883 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002884 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002885 traits_type::copy(__s, data() + __pos, __rlen);
2886 return __rlen;
2887}
2888
2889template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002890inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002891basic_string<_CharT, _Traits, _Allocator>
2892basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
2893{
2894 return basic_string(*this, __pos, __n, __alloc());
2895}
2896
2897template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002898inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002899void
2900basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00002901#if _LIBCPP_STD_VER >= 14
2902 _NOEXCEPT
2903#else
2904 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2905 __is_nothrow_swappable<allocator_type>::value)
2906#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002907{
Howard Hinnant499cea12013-08-23 17:37:05 +00002908#if _LIBCPP_DEBUG_LEVEL >= 2
2909 if (!__is_long())
2910 __get_db()->__invalidate_all(this);
2911 if (!__str.__is_long())
2912 __get_db()->__invalidate_all(&__str);
2913 __get_db()->swap(this, &__str);
2914#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00002915 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow7d914d12015-07-13 20:04:56 +00002916 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002917}
2918
2919// find
2920
2921template <class _Traits>
2922struct _LIBCPP_HIDDEN __traits_eq
2923{
2924 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00002925 _LIBCPP_INLINE_VISIBILITY
2926 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
2927 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002928};
2929
2930template<class _CharT, class _Traits, class _Allocator>
2931typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002932basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00002933 size_type __pos,
2934 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002935{
Alp Tokerec34c482014-05-15 11:27:39 +00002936 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002937 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00002938 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002939}
2940
2941template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002942inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002943typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00002944basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
2945 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002946{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002947 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00002948 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002949}
2950
2951template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002952inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002953typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002954basic_string<_CharT, _Traits, _Allocator>::find(__self_view __sv,
2955 size_type __pos) const _NOEXCEPT
2956{
2957 return __str_find<value_type, size_type, traits_type, npos>
2958 (data(), size(), __sv.data(), __pos, __sv.size());
2959}
2960
2961template<class _CharT, class _Traits, class _Allocator>
2962inline _LIBCPP_INLINE_VISIBILITY
2963typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002964basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00002965 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002966{
Alp Tokerec34c482014-05-15 11:27:39 +00002967 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002968 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00002969 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002970}
2971
2972template<class _CharT, class _Traits, class _Allocator>
2973typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00002974basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
2975 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002976{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002977 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00002978 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002979}
2980
2981// rfind
2982
2983template<class _CharT, class _Traits, class _Allocator>
2984typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002985basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00002986 size_type __pos,
2987 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002988{
Alp Tokerec34c482014-05-15 11:27:39 +00002989 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002990 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00002991 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002992}
2993
2994template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002995inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002996typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00002997basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
2998 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002999{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003000 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003001 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003002}
3003
3004template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003005inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003006typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003007basic_string<_CharT, _Traits, _Allocator>::rfind(__self_view __sv,
3008 size_type __pos) const _NOEXCEPT
3009{
3010 return __str_rfind<value_type, size_type, traits_type, npos>
3011 (data(), size(), __sv.data(), __pos, __sv.size());
3012}
3013
3014template<class _CharT, class _Traits, class _Allocator>
3015inline _LIBCPP_INLINE_VISIBILITY
3016typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003017basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003018 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003019{
Alp Tokerec34c482014-05-15 11:27:39 +00003020 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003021 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003022 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003023}
3024
3025template<class _CharT, class _Traits, class _Allocator>
3026typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003027basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3028 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003029{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003030 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003031 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003032}
3033
3034// find_first_of
3035
3036template<class _CharT, class _Traits, class _Allocator>
3037typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003038basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003039 size_type __pos,
3040 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003041{
Alp Tokerec34c482014-05-15 11:27:39 +00003042 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003043 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003044 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003045}
3046
3047template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003048inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003049typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003050basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3051 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003052{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003053 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003054 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003055}
3056
3057template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003058inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003059typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003060basic_string<_CharT, _Traits, _Allocator>::find_first_of(__self_view __sv,
3061 size_type __pos) const _NOEXCEPT
3062{
3063 return __str_find_first_of<value_type, size_type, traits_type, npos>
3064 (data(), size(), __sv.data(), __pos, __sv.size());
3065}
3066
3067template<class _CharT, class _Traits, class _Allocator>
3068inline _LIBCPP_INLINE_VISIBILITY
3069typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003070basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003071 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003072{
Alp Tokerec34c482014-05-15 11:27:39 +00003073 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003074 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003075 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003076}
3077
3078template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003079inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003080typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003081basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3082 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003083{
3084 return find(__c, __pos);
3085}
3086
3087// find_last_of
3088
3089template<class _CharT, class _Traits, class _Allocator>
3090typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003091basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003092 size_type __pos,
3093 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003094{
Alp Tokerec34c482014-05-15 11:27:39 +00003095 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003096 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003097 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003098}
3099
3100template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003101inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003102typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003103basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3104 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003105{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003106 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003107 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003108}
3109
3110template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003111inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003112typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003113basic_string<_CharT, _Traits, _Allocator>::find_last_of(__self_view __sv,
3114 size_type __pos) const _NOEXCEPT
3115{
3116 return __str_find_last_of<value_type, size_type, traits_type, npos>
3117 (data(), size(), __sv.data(), __pos, __sv.size());
3118}
3119
3120template<class _CharT, class _Traits, class _Allocator>
3121inline _LIBCPP_INLINE_VISIBILITY
3122typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003123basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003124 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003125{
Alp Tokerec34c482014-05-15 11:27:39 +00003126 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003127 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003128 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003129}
3130
3131template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003132inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003133typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003134basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3135 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003136{
3137 return rfind(__c, __pos);
3138}
3139
3140// find_first_not_of
3141
3142template<class _CharT, class _Traits, class _Allocator>
3143typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003144basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003145 size_type __pos,
3146 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003147{
Alp Tokerec34c482014-05-15 11:27:39 +00003148 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003149 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003150 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003151}
3152
3153template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003154inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003155typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003156basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3157 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003158{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003159 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003160 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003161}
3162
3163template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003164inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003165typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003166basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(__self_view __sv,
3167 size_type __pos) const _NOEXCEPT
3168{
3169 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3170 (data(), size(), __sv.data(), __pos, __sv.size());
3171}
3172
3173template<class _CharT, class _Traits, class _Allocator>
3174inline _LIBCPP_INLINE_VISIBILITY
3175typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003176basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003177 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003178{
Alp Tokerec34c482014-05-15 11:27:39 +00003179 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003180 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003181 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003182}
3183
3184template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003185inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003186typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003187basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3188 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003189{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003190 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003191 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003192}
3193
3194// find_last_not_of
3195
3196template<class _CharT, class _Traits, class _Allocator>
3197typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003198basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003199 size_type __pos,
3200 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003201{
Alp Tokerec34c482014-05-15 11:27:39 +00003202 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003203 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003204 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003205}
3206
3207template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003208inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003209typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003210basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3211 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003212{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003213 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003214 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003215}
3216
3217template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003218inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003219typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003220basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(__self_view __sv,
3221 size_type __pos) const _NOEXCEPT
3222{
3223 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3224 (data(), size(), __sv.data(), __pos, __sv.size());
3225}
3226
3227template<class _CharT, class _Traits, class _Allocator>
3228inline _LIBCPP_INLINE_VISIBILITY
3229typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003230basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003231 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003232{
Alp Tokerec34c482014-05-15 11:27:39 +00003233 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003234 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003235 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003236}
3237
3238template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003239inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003240typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003241basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3242 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003243{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003244 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003245 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003246}
3247
3248// compare
3249
3250template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003251inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003252int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003253basic_string<_CharT, _Traits, _Allocator>::compare(__self_view __sv) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003254{
Howard Hinnantfa06d752011-07-24 21:45:06 +00003255 size_t __lhs_sz = size();
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003256 size_t __rhs_sz = __sv.size();
3257 int __result = traits_type::compare(data(), __sv.data(),
Howard Hinnantfa06d752011-07-24 21:45:06 +00003258 _VSTD::min(__lhs_sz, __rhs_sz));
3259 if (__result != 0)
3260 return __result;
3261 if (__lhs_sz < __rhs_sz)
3262 return -1;
3263 if (__lhs_sz > __rhs_sz)
3264 return 1;
3265 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003266}
3267
3268template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003269inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003270int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003271basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003272{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003273 return compare(__self_view(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003274}
3275
3276template <class _CharT, class _Traits, class _Allocator>
3277int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003278basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3279 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003280 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003281 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003282{
Alp Tokerec34c482014-05-15 11:27:39 +00003283 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003284 size_type __sz = size();
3285 if (__pos1 > __sz || __n2 == npos)
3286 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003287 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3288 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003289 if (__r == 0)
3290 {
3291 if (__rlen < __n2)
3292 __r = -1;
3293 else if (__rlen > __n2)
3294 __r = 1;
3295 }
3296 return __r;
3297}
3298
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003299template <class _CharT, class _Traits, class _Allocator>
3300inline _LIBCPP_INLINE_VISIBILITY
3301int
3302basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3303 size_type __n1,
3304 __self_view __sv) const
3305{
3306 return compare(__pos1, __n1, __sv.data(), __sv.size());
3307}
3308
3309template <class _CharT, class _Traits, class _Allocator>
3310inline _LIBCPP_INLINE_VISIBILITY
3311int
3312basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3313 size_type __n1,
3314 const basic_string& __str) const
3315{
3316 return compare(__pos1, __n1, __str.data(), __str.size());
3317}
3318
3319template <class _CharT, class _Traits, class _Allocator>
3320int inline _LIBCPP_INLINE_VISIBILITY
3321basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3322 size_type __n1,
3323 __self_view __sv,
3324 size_type __pos2,
3325 size_type __n2) const
3326{
3327 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3328}
3329
3330template <class _CharT, class _Traits, class _Allocator>
3331int
3332basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3333 size_type __n1,
3334 const basic_string& __str,
3335 size_type __pos2,
3336 size_type __n2) const
3337{
3338 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3339}
3340
3341template <class _CharT, class _Traits, class _Allocator>
3342int
3343basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3344{
3345 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3346 return compare(0, npos, __s, traits_type::length(__s));
3347}
3348
3349template <class _CharT, class _Traits, class _Allocator>
3350int
3351basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3352 size_type __n1,
3353 const value_type* __s) const
3354{
3355 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3356 return compare(__pos1, __n1, __s, traits_type::length(__s));
3357}
3358
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003359// __invariants
3360
3361template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003362inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003363bool
3364basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3365{
3366 if (size() > capacity())
3367 return false;
3368 if (capacity() < __min_cap - 1)
3369 return false;
3370 if (data() == 0)
3371 return false;
3372 if (data()[size()] != value_type(0))
3373 return false;
3374 return true;
3375}
3376
3377// operator==
3378
3379template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003380inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003381bool
3382operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003383 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003384{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003385 size_t __lhs_sz = __lhs.size();
3386 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3387 __rhs.data(),
3388 __lhs_sz) == 0;
3389}
3390
3391template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003392inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:13 +00003393bool
3394operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3395 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3396{
3397 size_t __lhs_sz = __lhs.size();
3398 if (__lhs_sz != __rhs.size())
3399 return false;
3400 const char* __lp = __lhs.data();
3401 const char* __rp = __rhs.data();
3402 if (__lhs.__is_long())
3403 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3404 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3405 if (*__lp != *__rp)
3406 return false;
3407 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003408}
3409
3410template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003411inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003412bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003413operator==(const _CharT* __lhs,
3414 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003415{
Eric Fiselier4f241822015-08-28 03:02:37 +00003416 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3417 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3418 size_t __lhs_len = _Traits::length(__lhs);
3419 if (__lhs_len != __rhs.size()) return false;
3420 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003421}
3422
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003423template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003424inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003425bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003426operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3427 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003428{
Eric Fiselier4f241822015-08-28 03:02:37 +00003429 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3430 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3431 size_t __rhs_len = _Traits::length(__rhs);
3432 if (__rhs_len != __lhs.size()) return false;
3433 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003434}
3435
Howard Hinnant324bb032010-08-22 00:02:43 +00003436template<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
3439operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003440 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003441{
3442 return !(__lhs == __rhs);
3443}
3444
3445template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003446inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003447bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003448operator!=(const _CharT* __lhs,
3449 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003450{
3451 return !(__lhs == __rhs);
3452}
3453
3454template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003455inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003456bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003457operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3458 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003459{
3460 return !(__lhs == __rhs);
3461}
3462
3463// operator<
3464
3465template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003466inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003467bool
3468operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003469 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003470{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003471 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003472}
3473
3474template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003475inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003476bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003477operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3478 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003479{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003480 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003481}
3482
3483template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003484inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003485bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003486operator< (const _CharT* __lhs,
3487 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003488{
3489 return __rhs.compare(__lhs) > 0;
3490}
3491
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003492// operator>
3493
3494template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003495inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003496bool
3497operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003498 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003499{
3500 return __rhs < __lhs;
3501}
3502
3503template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003504inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003505bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003506operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3507 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003508{
3509 return __rhs < __lhs;
3510}
3511
3512template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003513inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003514bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003515operator> (const _CharT* __lhs,
3516 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003517{
3518 return __rhs < __lhs;
3519}
3520
3521// operator<=
3522
3523template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003524inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003525bool
3526operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003527 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003528{
3529 return !(__rhs < __lhs);
3530}
3531
3532template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003533inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003534bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003535operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3536 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003537{
3538 return !(__rhs < __lhs);
3539}
3540
3541template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003542inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003543bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003544operator<=(const _CharT* __lhs,
3545 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003546{
3547 return !(__rhs < __lhs);
3548}
3549
3550// operator>=
3551
3552template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003553inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003554bool
3555operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003556 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003557{
3558 return !(__lhs < __rhs);
3559}
3560
3561template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003562inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003563bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003564operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3565 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003566{
3567 return !(__lhs < __rhs);
3568}
3569
3570template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003571inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003572bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003573operator>=(const _CharT* __lhs,
3574 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003575{
3576 return !(__lhs < __rhs);
3577}
3578
3579// operator +
3580
3581template<class _CharT, class _Traits, class _Allocator>
3582basic_string<_CharT, _Traits, _Allocator>
3583operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3584 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3585{
3586 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3587 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3588 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3589 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3590 __r.append(__rhs.data(), __rhs_sz);
3591 return __r;
3592}
3593
3594template<class _CharT, class _Traits, class _Allocator>
3595basic_string<_CharT, _Traits, _Allocator>
3596operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3597{
3598 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3599 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
3600 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3601 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
3602 __r.append(__rhs.data(), __rhs_sz);
3603 return __r;
3604}
3605
3606template<class _CharT, class _Traits, class _Allocator>
3607basic_string<_CharT, _Traits, _Allocator>
3608operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3609{
3610 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3611 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3612 __r.__init(&__lhs, 1, 1 + __rhs_sz);
3613 __r.append(__rhs.data(), __rhs_sz);
3614 return __r;
3615}
3616
3617template<class _CharT, class _Traits, class _Allocator>
3618basic_string<_CharT, _Traits, _Allocator>
3619operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
3620{
3621 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3622 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3623 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
3624 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3625 __r.append(__rhs, __rhs_sz);
3626 return __r;
3627}
3628
3629template<class _CharT, class _Traits, class _Allocator>
3630basic_string<_CharT, _Traits, _Allocator>
3631operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
3632{
3633 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3634 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3635 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
3636 __r.push_back(__rhs);
3637 return __r;
3638}
3639
Howard Hinnant73d21a42010-09-04 23:28:19 +00003640#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003641
3642template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003643inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003644basic_string<_CharT, _Traits, _Allocator>
3645operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3646{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003647 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003648}
3649
3650template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003651inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003652basic_string<_CharT, _Traits, _Allocator>
3653operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3654{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003655 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003656}
3657
3658template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003659inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003660basic_string<_CharT, _Traits, _Allocator>
3661operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3662{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003663 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003664}
3665
3666template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003667inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003668basic_string<_CharT, _Traits, _Allocator>
3669operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3670{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003671 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003672}
3673
3674template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003675inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003676basic_string<_CharT, _Traits, _Allocator>
3677operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3678{
3679 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003680 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003681}
3682
3683template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003684inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003685basic_string<_CharT, _Traits, _Allocator>
3686operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
3687{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003688 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003689}
3690
3691template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003692inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003693basic_string<_CharT, _Traits, _Allocator>
3694operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
3695{
3696 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003697 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003698}
3699
Howard Hinnant73d21a42010-09-04 23:28:19 +00003700#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003701
3702// swap
3703
3704template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003705inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003706void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003707swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00003708 basic_string<_CharT, _Traits, _Allocator>& __rhs)
3709 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003710{
3711 __lhs.swap(__rhs);
3712}
3713
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003714#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
3715
3716typedef basic_string<char16_t> u16string;
3717typedef basic_string<char32_t> u32string;
3718
Howard Hinnant324bb032010-08-22 00:02:43 +00003719#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003720
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003721_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
3722_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
3723_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
3724_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
3725_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003726
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003727_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
3728_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
3729_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003730
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003731_LIBCPP_FUNC_VIS string to_string(int __val);
3732_LIBCPP_FUNC_VIS string to_string(unsigned __val);
3733_LIBCPP_FUNC_VIS string to_string(long __val);
3734_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
3735_LIBCPP_FUNC_VIS string to_string(long long __val);
3736_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
3737_LIBCPP_FUNC_VIS string to_string(float __val);
3738_LIBCPP_FUNC_VIS string to_string(double __val);
3739_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003740
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003741_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
3742_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
3743_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
3744_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
3745_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003746
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003747_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
3748_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
3749_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003750
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003751_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
3752_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
3753_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
3754_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
3755_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
3756_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
3757_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
3758_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
3759_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003760
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003761template<class _CharT, class _Traits, class _Allocator>
3762 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
3763 basic_string<_CharT, _Traits, _Allocator>::npos;
3764
3765template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003766struct _LIBCPP_TYPE_VIS_ONLY hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003767 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
3768{
3769 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00003770 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003771};
3772
3773template<class _CharT, class _Traits, class _Allocator>
3774size_t
3775hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00003776 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003777{
Sean Huntaffd9e52011-07-29 23:31:56 +00003778 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003779}
3780
Howard Hinnant464aa5c2011-07-18 15:51:59 +00003781template<class _CharT, class _Traits, class _Allocator>
3782basic_ostream<_CharT, _Traits>&
3783operator<<(basic_ostream<_CharT, _Traits>& __os,
3784 const basic_string<_CharT, _Traits, _Allocator>& __str);
3785
3786template<class _CharT, class _Traits, class _Allocator>
3787basic_istream<_CharT, _Traits>&
3788operator>>(basic_istream<_CharT, _Traits>& __is,
3789 basic_string<_CharT, _Traits, _Allocator>& __str);
3790
3791template<class _CharT, class _Traits, class _Allocator>
3792basic_istream<_CharT, _Traits>&
3793getline(basic_istream<_CharT, _Traits>& __is,
3794 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3795
3796template<class _CharT, class _Traits, class _Allocator>
3797inline _LIBCPP_INLINE_VISIBILITY
3798basic_istream<_CharT, _Traits>&
3799getline(basic_istream<_CharT, _Traits>& __is,
3800 basic_string<_CharT, _Traits, _Allocator>& __str);
3801
3802#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3803
3804template<class _CharT, class _Traits, class _Allocator>
3805inline _LIBCPP_INLINE_VISIBILITY
3806basic_istream<_CharT, _Traits>&
3807getline(basic_istream<_CharT, _Traits>&& __is,
3808 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3809
3810template<class _CharT, class _Traits, class _Allocator>
3811inline _LIBCPP_INLINE_VISIBILITY
3812basic_istream<_CharT, _Traits>&
3813getline(basic_istream<_CharT, _Traits>&& __is,
3814 basic_string<_CharT, _Traits, _Allocator>& __str);
3815
3816#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3817
Howard Hinnant499cea12013-08-23 17:37:05 +00003818#if _LIBCPP_DEBUG_LEVEL >= 2
3819
3820template<class _CharT, class _Traits, class _Allocator>
3821bool
3822basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
3823{
3824 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
3825 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
3826}
3827
3828template<class _CharT, class _Traits, class _Allocator>
3829bool
3830basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
3831{
3832 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
3833 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
3834}
3835
3836template<class _CharT, class _Traits, class _Allocator>
3837bool
3838basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
3839{
3840 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
3841 return this->data() <= __p && __p <= this->data() + this->size();
3842}
3843
3844template<class _CharT, class _Traits, class _Allocator>
3845bool
3846basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
3847{
3848 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
3849 return this->data() <= __p && __p < this->data() + this->size();
3850}
3851
3852#endif // _LIBCPP_DEBUG_LEVEL >= 2
3853
Marshall Clow15234322013-07-23 17:05:24 +00003854#if _LIBCPP_STD_VER > 11
3855// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:32 +00003856inline namespace literals
Marshall Clow15234322013-07-23 17:05:24 +00003857{
3858 inline namespace string_literals
3859 {
Howard Hinnantab61b2c2013-08-07 19:39:48 +00003860 inline _LIBCPP_INLINE_VISIBILITY
3861 basic_string<char> operator "" s( const char *__str, size_t __len )
3862 {
3863 return basic_string<char> (__str, __len);
3864 }
Marshall Clow15234322013-07-23 17:05:24 +00003865
Howard Hinnantab61b2c2013-08-07 19:39:48 +00003866 inline _LIBCPP_INLINE_VISIBILITY
3867 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
3868 {
3869 return basic_string<wchar_t> (__str, __len);
3870 }
Marshall Clow15234322013-07-23 17:05:24 +00003871
Howard Hinnantab61b2c2013-08-07 19:39:48 +00003872 inline _LIBCPP_INLINE_VISIBILITY
3873 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
3874 {
3875 return basic_string<char16_t> (__str, __len);
3876 }
Marshall Clow15234322013-07-23 17:05:24 +00003877
Howard Hinnantab61b2c2013-08-07 19:39:48 +00003878 inline _LIBCPP_INLINE_VISIBILITY
3879 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
3880 {
3881 return basic_string<char32_t> (__str, __len);
3882 }
Marshall Clow15234322013-07-23 17:05:24 +00003883 }
3884}
3885#endif
3886
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003887_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<char>)
3888_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<wchar_t>)
Howard Hinnant499cea12013-08-23 17:37:05 +00003889_LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003890
3891_LIBCPP_END_NAMESPACE_STD
3892
3893#endif // _LIBCPP_STRING