blob: 3ffe74d3232928367411a254dc305ec52fa73576 [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 Clow6ac8de02016-09-24 22:45:42 +0000173 template <class T>
174 basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000175 basic_string& append(const value_type* s, size_type n);
176 basic_string& append(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000177 basic_string& append(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000178 template<class InputIterator>
179 basic_string& append(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000180 basic_string& append(initializer_list<value_type>);
181
182 void push_back(value_type c);
183 void pop_back();
184 reference front();
185 const_reference front() const;
186 reference back();
187 const_reference back() const;
188
189 basic_string& assign(const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000190 basic_string& assign(basic_string_view<charT, traits> sv);
Howard Hinnanta6119a82011-05-29 19:57:12 +0000191 basic_string& assign(basic_string&& str);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000192 basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000193 template <class T>
194 basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000195 basic_string& assign(const value_type* s, size_type n);
196 basic_string& assign(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000197 basic_string& assign(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000198 template<class InputIterator>
199 basic_string& assign(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000200 basic_string& assign(initializer_list<value_type>);
201
202 basic_string& insert(size_type pos1, const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000203 basic_string& insert(size_type pos1, basic_string_view<charT, traits> sv);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000204 basic_string& insert(size_type pos1, const basic_string& str,
205 size_type pos2, size_type n);
Marshall Clow6ac8de02016-09-24 22:45:42 +0000206 template <class T>
207 basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17
Marshall Clowa93b5e22014-03-04 19:17:19 +0000208 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000209 basic_string& insert(size_type pos, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000210 basic_string& insert(size_type pos, size_type n, value_type c);
211 iterator insert(const_iterator p, value_type c);
212 iterator insert(const_iterator p, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000213 template<class InputIterator>
214 iterator insert(const_iterator p, InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000215 iterator insert(const_iterator p, initializer_list<value_type>);
216
217 basic_string& erase(size_type pos = 0, size_type n = npos);
218 iterator erase(const_iterator position);
219 iterator erase(const_iterator first, const_iterator last);
220
221 basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000222 basic_string& replace(size_type pos1, size_type n1, basic_string_view<charT, traits> sv);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000223 basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000224 size_type pos2, size_type n2=npos); // C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000225 template <class T>
226 basic_string& replace(size_type pos1, size_type n1, const T& t,
227 size_type pos2, size_type n); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000228 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
229 basic_string& replace(size_type pos, size_type n1, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000230 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000231 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000232 basic_string& replace(const_iterator i1, const_iterator i2, basic_string_view<charT, traits> sv);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000233 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
234 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000235 basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000236 template<class InputIterator>
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000237 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
238 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000239
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000240 size_type copy(value_type* s, size_type n, size_type pos = 0) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000241 basic_string substr(size_type pos = 0, size_type n = npos) const;
242
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000243 void swap(basic_string& str)
Marshall Clow7d914d12015-07-13 20:04:56 +0000244 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
245 allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000246
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000247 const value_type* c_str() const noexcept;
248 const value_type* data() const noexcept;
Marshall Clowf532a702016-03-08 15:44:30 +0000249 value_type* data() noexcept; // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000250
Howard Hinnanta6119a82011-05-29 19:57:12 +0000251 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000252
Howard Hinnanta6119a82011-05-29 19:57:12 +0000253 size_type find(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000254 size_type find(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000255 size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
256 size_type find(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000257 size_type find(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000258
Howard Hinnanta6119a82011-05-29 19:57:12 +0000259 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000260 size_type ffind(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000261 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
262 size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000263 size_type rfind(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000264
Howard Hinnanta6119a82011-05-29 19:57:12 +0000265 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000266 size_type find_first_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000267 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
268 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000269 size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000270
Howard Hinnanta6119a82011-05-29 19:57:12 +0000271 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000272 size_type find_last_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000273 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
274 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000275 size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000276
Howard Hinnanta6119a82011-05-29 19:57:12 +0000277 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000278 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 +0000279 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
280 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000281 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000282
Howard Hinnanta6119a82011-05-29 19:57:12 +0000283 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000284 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 +0000285 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
286 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000287 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000288
Howard Hinnanta6119a82011-05-29 19:57:12 +0000289 int compare(const basic_string& str) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000290 int compare(basic_string_view<charT, traits> sv) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000291 int compare(size_type pos1, size_type n1, const basic_string& str) const;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000292 int compare(size_type pos1, size_type n1, basic_string_view<charT, traits> sv) const;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000293 int compare(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000294 size_type pos2, size_type n2=npos) const; // C++14
Marshall Clow6ac8de02016-09-24 22:45:42 +0000295 template <class T>
296 int compare(size_type pos1, size_type n1, const T& t,
297 size_type pos2, size_type n2=npos) const; // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000298 int compare(const value_type* s) const noexcept;
299 int compare(size_type pos1, size_type n1, const value_type* s) const;
300 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000301
302 bool __invariants() const;
303};
304
305template<class charT, class traits, class Allocator>
306basic_string<charT, traits, Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000307operator+(const basic_string<charT, traits, Allocator>& lhs,
308 const basic_string<charT, traits, Allocator>& rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000309
310template<class charT, class traits, class Allocator>
311basic_string<charT, traits, Allocator>
312operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
313
314template<class charT, class traits, class Allocator>
315basic_string<charT, traits, Allocator>
316operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
317
318template<class charT, class traits, class Allocator>
319basic_string<charT, traits, Allocator>
320operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
321
322template<class charT, class traits, class Allocator>
323basic_string<charT, traits, Allocator>
324operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
325
326template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000327bool operator==(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000328 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000329
330template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000331bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000332
333template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000334bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000335
Howard Hinnant324bb032010-08-22 00:02:43 +0000336template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000337bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000338 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000339
340template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000341bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000342
343template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000344bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000345
346template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000347bool operator< (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000348 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000349
350template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000351bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000352
353template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000354bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000355
356template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000357bool operator> (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000358 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000359
360template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000361bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000362
363template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000364bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000365
366template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000367bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000368 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000369
370template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000371bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000372
373template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000374bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000375
376template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000377bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000378 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000379
380template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000381bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000382
383template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000384bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000385
386template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000387void swap(basic_string<charT, traits, Allocator>& lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000388 basic_string<charT, traits, Allocator>& rhs)
389 noexcept(noexcept(lhs.swap(rhs)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000390
391template<class charT, class traits, class Allocator>
392basic_istream<charT, traits>&
393operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
394
395template<class charT, class traits, class Allocator>
396basic_ostream<charT, traits>&
397operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
398
399template<class charT, class traits, class Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +0000400basic_istream<charT, traits>&
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000401getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
402 charT delim);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000403
404template<class charT, class traits, class Allocator>
405basic_istream<charT, traits>&
406getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
407
408typedef basic_string<char> string;
409typedef basic_string<wchar_t> wstring;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000410typedef basic_string<char16_t> u16string;
411typedef basic_string<char32_t> u32string;
412
413int stoi (const string& str, size_t* idx = 0, int base = 10);
414long stol (const string& str, size_t* idx = 0, int base = 10);
415unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
416long long stoll (const string& str, size_t* idx = 0, int base = 10);
417unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
418
419float stof (const string& str, size_t* idx = 0);
420double stod (const string& str, size_t* idx = 0);
421long double stold(const string& str, size_t* idx = 0);
422
423string to_string(int val);
424string to_string(unsigned val);
425string to_string(long val);
426string to_string(unsigned long val);
427string to_string(long long val);
428string to_string(unsigned long long val);
429string to_string(float val);
430string to_string(double val);
431string to_string(long double val);
432
433int stoi (const wstring& str, size_t* idx = 0, int base = 10);
434long stol (const wstring& str, size_t* idx = 0, int base = 10);
435unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
436long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
437unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
438
439float stof (const wstring& str, size_t* idx = 0);
440double stod (const wstring& str, size_t* idx = 0);
441long double stold(const wstring& str, size_t* idx = 0);
442
443wstring to_wstring(int val);
444wstring to_wstring(unsigned val);
445wstring to_wstring(long val);
446wstring to_wstring(unsigned long val);
447wstring to_wstring(long long val);
448wstring to_wstring(unsigned long long val);
449wstring to_wstring(float val);
450wstring to_wstring(double val);
451wstring to_wstring(long double val);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000452
453template <> struct hash<string>;
454template <> struct hash<u16string>;
455template <> struct hash<u32string>;
456template <> struct hash<wstring>;
457
Marshall Clow15234322013-07-23 17:05:24 +0000458basic_string<char> operator "" s( const char *str, size_t len ); // C++14
459basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
460basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
461basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
462
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000463} // std
464
465*/
466
467#include <__config>
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000468#include <string_view>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000469#include <iosfwd>
470#include <cstring>
Howard Hinnantadff4892010-05-24 17:49:41 +0000471#include <cstdio> // For EOF.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000472#include <cwchar>
473#include <algorithm>
474#include <iterator>
475#include <utility>
476#include <memory>
477#include <stdexcept>
478#include <type_traits>
479#include <initializer_list>
480#include <__functional_base>
481#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
482#include <cstdint>
483#endif
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000484
Howard Hinnant66c6f972011-11-29 16:45:27 +0000485#include <__undef_min_max>
486
Eric Fiselierb9536102014-08-10 23:53:08 +0000487#include <__debug>
488
Howard Hinnant08e17472011-10-17 20:05:10 +0000489#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000490#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000491#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000492
493_LIBCPP_BEGIN_NAMESPACE_STD
494
495// fpos
496
497template <class _StateT>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000498class _LIBCPP_TYPE_VIS_ONLY fpos
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000499{
500private:
501 _StateT __st_;
502 streamoff __off_;
503public:
504 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
505
506 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
507
508 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
509 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
510
511 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
512 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
513 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
514 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
515};
516
517template <class _StateT>
518inline _LIBCPP_INLINE_VISIBILITY
519streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
520 {return streamoff(__x) - streamoff(__y);}
521
522template <class _StateT>
523inline _LIBCPP_INLINE_VISIBILITY
524bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
525 {return streamoff(__x) == streamoff(__y);}
526
527template <class _StateT>
528inline _LIBCPP_INLINE_VISIBILITY
529bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
530 {return streamoff(__x) != streamoff(__y);}
531
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000532// basic_string
533
534template<class _CharT, class _Traits, class _Allocator>
535basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000536operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
537 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+(const _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+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __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, const _CharT* __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000550
551template<class _CharT, class _Traits, class _Allocator>
552basic_string<_CharT, _Traits, _Allocator>
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000553operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000554
555template <bool>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000556class _LIBCPP_TYPE_VIS_ONLY __basic_string_common
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000557{
558protected:
Marshall Clow14c09a22016-08-25 15:09:01 +0000559 _LIBCPP_NORETURN void __throw_length_error() const;
560 _LIBCPP_NORETURN void __throw_out_of_range() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000561};
562
563template <bool __b>
564void
565__basic_string_common<__b>::__throw_length_error() const
566{
Marshall Clow14c09a22016-08-25 15:09:01 +0000567 _VSTD::__throw_length_error("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000568}
569
570template <bool __b>
571void
572__basic_string_common<__b>::__throw_out_of_range() const
573{
Marshall Clow14c09a22016-08-25 15:09:01 +0000574 _VSTD::__throw_out_of_range("basic_string");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000575}
576
Howard Hinnante9df0a52013-08-01 18:17:34 +0000577#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +0000578#pragma warning( push )
579#pragma warning( disable: 4231 )
Howard Hinnante9df0a52013-08-01 18:17:34 +0000580#endif // _LIBCPP_MSVC
Eric Fiselier833d6442016-09-15 22:27:07 +0000581_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>)
Howard Hinnante9df0a52013-08-01 18:17:34 +0000582#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +0000583#pragma warning( pop )
Howard Hinnante9df0a52013-08-01 18:17:34 +0000584#endif // _LIBCPP_MSVC
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000585
Marshall Clowdf9db312016-01-13 21:54:34 +0000586#ifdef _LIBCPP_NO_EXCEPTIONS
587template <class _Iter>
588struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
589#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
590template <class _Iter>
591struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
592#else
593template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
594struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
595 noexcept(++(declval<_Iter&>())) &&
596 is_nothrow_assignable<_Iter&, _Iter>::value &&
597 noexcept(declval<_Iter>() == declval<_Iter>()) &&
598 noexcept(*declval<_Iter>())
599)) {};
600
601template <class _Iter>
602struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
603#endif
604
605
606template <class _Iter>
607struct __libcpp_string_gets_noexcept_iterator
608 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
609
Marshall Clow6ac8de02016-09-24 22:45:42 +0000610template <class _CharT, class _Traits, class _Tp>
611struct __can_be_converted_to_string_view : public _LIBCPP_BOOL_CONSTANT(
612 ( is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
613 !is_convertible<const _Tp&, const _CharT*>::value)) {};
614
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000615#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000616
617template <class _CharT, size_t = sizeof(_CharT)>
618struct __padding
619{
620 unsigned char __xx[sizeof(_CharT)-1];
621};
622
623template <class _CharT>
624struct __padding<_CharT, 1>
625{
626};
627
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000628#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000629
Howard Hinnant324bb032010-08-22 00:02:43 +0000630template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000631class _LIBCPP_TYPE_VIS_ONLY basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000632 : private __basic_string_common<true>
633{
634public:
635 typedef basic_string __self;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000636 typedef basic_string_view<_CharT, _Traits> __self_view;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000637 typedef _Traits traits_type;
638 typedef typename traits_type::char_type value_type;
639 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000640 typedef allocator_traits<allocator_type> __alloc_traits;
641 typedef typename __alloc_traits::size_type size_type;
642 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000643 typedef value_type& reference;
644 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000645 typedef typename __alloc_traits::pointer pointer;
646 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000647
Howard Hinnant499cea12013-08-23 17:37:05 +0000648 static_assert(is_pod<value_type>::value, "Character type of basic_string must be a POD");
649 static_assert((is_same<_CharT, value_type>::value),
650 "traits_type::char_type must be the same type as CharT");
651 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
652 "Allocator::value_type must be same type as value_type");
653#if defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000654 typedef pointer iterator;
655 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000656#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000657 typedef __wrap_iter<pointer> iterator;
658 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000659#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000660 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
661 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000662
663private:
Howard Hinnant15467182013-04-30 21:44:48 +0000664
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000665#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000666
667 struct __long
668 {
669 pointer __data_;
670 size_type __size_;
671 size_type __cap_;
672 };
673
674#if _LIBCPP_BIG_ENDIAN
675 enum {__short_mask = 0x01};
676 enum {__long_mask = 0x1ul};
677#else // _LIBCPP_BIG_ENDIAN
678 enum {__short_mask = 0x80};
679 enum {__long_mask = ~(size_type(~0) >> 1)};
680#endif // _LIBCPP_BIG_ENDIAN
681
682 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
683 (sizeof(__long) - 1)/sizeof(value_type) : 2};
684
685 struct __short
686 {
687 value_type __data_[__min_cap];
688 struct
689 : __padding<value_type>
690 {
691 unsigned char __size_;
692 };
693 };
694
695#else
696
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000697 struct __long
698 {
699 size_type __cap_;
700 size_type __size_;
701 pointer __data_;
702 };
703
704#if _LIBCPP_BIG_ENDIAN
705 enum {__short_mask = 0x80};
706 enum {__long_mask = ~(size_type(~0) >> 1)};
Howard Hinnant324bb032010-08-22 00:02:43 +0000707#else // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000708 enum {__short_mask = 0x01};
Howard Hinnantec3773c2011-12-01 20:21:04 +0000709 enum {__long_mask = 0x1ul};
Howard Hinnant324bb032010-08-22 00:02:43 +0000710#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000711
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000712 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
713 (sizeof(__long) - 1)/sizeof(value_type) : 2};
714
715 struct __short
716 {
717 union
718 {
719 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59 +0000720 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000721 };
722 value_type __data_[__min_cap];
723 };
724
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000725#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000726
Howard Hinnant499cea12013-08-23 17:37:05 +0000727 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000728
Howard Hinnant499cea12013-08-23 17:37:05 +0000729 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000730
731 struct __raw
732 {
733 size_type __words[__n_words];
734 };
735
736 struct __rep
737 {
738 union
739 {
740 __long __l;
741 __short __s;
742 __raw __r;
743 };
744 };
745
746 __compressed_pair<__rep, allocator_type> __r_;
747
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000748public:
749 static const size_type npos = -1;
750
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000751 _LIBCPP_INLINE_VISIBILITY basic_string()
752 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000753
754 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
755#if _LIBCPP_STD_VER <= 14
756 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
757#else
758 _NOEXCEPT;
759#endif
760
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000761 basic_string(const basic_string& __str);
762 basic_string(const basic_string& __str, const allocator_type& __a);
Marshall Clow7b193f72015-06-03 19:56:43 +0000763
Howard Hinnant73d21a42010-09-04 23:28:19 +0000764#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9f193f22011-01-26 00:06:59 +0000765 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000766 basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +0000767#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000768 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000769#else
770 _NOEXCEPT;
771#endif
772
Howard Hinnant9f193f22011-01-26 00:06:59 +0000773 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000774 basic_string(basic_string&& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000775#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000776 _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000777 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000778 basic_string(const value_type* __s, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000779 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000780 basic_string(const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000781 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000782 basic_string(const value_type* __s, size_type __n, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000783 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000784 basic_string(size_type __n, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000785 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000786 basic_string(size_type __n, value_type __c, const allocator_type& __a);
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000787 basic_string(const basic_string& __str, size_type __pos, size_type __n,
788 const allocator_type& __a = allocator_type());
789 _LIBCPP_INLINE_VISIBILITY
790 basic_string(const basic_string& __str, size_type __pos,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000791 const allocator_type& __a = allocator_type());
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000792 _LIBCPP_INLINE_VISIBILITY explicit
793 basic_string(__self_view __sv);
794 _LIBCPP_INLINE_VISIBILITY
795 basic_string(__self_view __sv, const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000796 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000797 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000798 basic_string(_InputIterator __first, _InputIterator __last);
799 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000800 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000801 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000802#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000803 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000804 basic_string(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000805 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000806 basic_string(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000807#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000808
809 ~basic_string();
810
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000811 _LIBCPP_INLINE_VISIBILITY
812 operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
813
Howard Hinnante32b5e22010-11-17 17:55:08 +0000814 basic_string& operator=(const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000815 _LIBCPP_INLINE_VISIBILITY
816 basic_string& operator=(__self_view __sv) {return assign(__sv);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000817#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000819 basic_string& operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +0000820 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000821#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000822 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000823 basic_string& operator=(value_type __c);
Howard Hinnante3e32912011-08-12 21:56:02 +0000824#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000825 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000826 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000827#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000828
Howard Hinnant499cea12013-08-23 17:37:05 +0000829#if _LIBCPP_DEBUG_LEVEL >= 2
830 _LIBCPP_INLINE_VISIBILITY
831 iterator begin() _NOEXCEPT
832 {return iterator(this, __get_pointer());}
833 _LIBCPP_INLINE_VISIBILITY
834 const_iterator begin() const _NOEXCEPT
835 {return const_iterator(this, __get_pointer());}
836 _LIBCPP_INLINE_VISIBILITY
837 iterator end() _NOEXCEPT
838 {return iterator(this, __get_pointer() + size());}
839 _LIBCPP_INLINE_VISIBILITY
840 const_iterator end() const _NOEXCEPT
841 {return const_iterator(this, __get_pointer() + size());}
842#else
Howard Hinnanta6119a82011-05-29 19:57:12 +0000843 _LIBCPP_INLINE_VISIBILITY
844 iterator begin() _NOEXCEPT
845 {return iterator(__get_pointer());}
846 _LIBCPP_INLINE_VISIBILITY
847 const_iterator begin() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000848 {return const_iterator(__get_pointer());}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000849 _LIBCPP_INLINE_VISIBILITY
850 iterator end() _NOEXCEPT
851 {return iterator(__get_pointer() + size());}
852 _LIBCPP_INLINE_VISIBILITY
853 const_iterator end() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000854 {return const_iterator(__get_pointer() + size());}
Howard Hinnant499cea12013-08-23 17:37:05 +0000855#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnanta6119a82011-05-29 19:57:12 +0000856 _LIBCPP_INLINE_VISIBILITY
857 reverse_iterator rbegin() _NOEXCEPT
858 {return reverse_iterator(end());}
859 _LIBCPP_INLINE_VISIBILITY
860 const_reverse_iterator rbegin() const _NOEXCEPT
861 {return const_reverse_iterator(end());}
862 _LIBCPP_INLINE_VISIBILITY
863 reverse_iterator rend() _NOEXCEPT
864 {return reverse_iterator(begin());}
865 _LIBCPP_INLINE_VISIBILITY
866 const_reverse_iterator rend() const _NOEXCEPT
867 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000868
Howard Hinnanta6119a82011-05-29 19:57:12 +0000869 _LIBCPP_INLINE_VISIBILITY
870 const_iterator cbegin() const _NOEXCEPT
871 {return begin();}
872 _LIBCPP_INLINE_VISIBILITY
873 const_iterator cend() const _NOEXCEPT
874 {return end();}
875 _LIBCPP_INLINE_VISIBILITY
876 const_reverse_iterator crbegin() const _NOEXCEPT
877 {return rbegin();}
878 _LIBCPP_INLINE_VISIBILITY
879 const_reverse_iterator crend() const _NOEXCEPT
880 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000881
Howard Hinnanta6119a82011-05-29 19:57:12 +0000882 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000883 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000884 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
885 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
886 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +0000887 {return (__is_long() ? __get_long_cap()
888 : static_cast<size_type>(__min_cap)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000889
890 void resize(size_type __n, value_type __c);
891 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
892
893 void reserve(size_type res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000894 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000895 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +0000897 void clear() _NOEXCEPT;
898 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000899
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000900 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
901 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000902
903 const_reference at(size_type __n) const;
904 reference at(size_type __n);
905
906 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000907 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(__self_view __sv) {return append(__sv);}
908 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000909 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +0000910#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000911 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Howard Hinnante3e32912011-08-12 21:56:02 +0000912#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000913
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000915 basic_string& append(const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000916 _LIBCPP_INLINE_VISIBILITY
917 basic_string& append(__self_view __sv) { return append(__sv.data(), __sv.size()); }
Marshall Clowa93b5e22014-03-04 19:17:19 +0000918 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow42a87db2016-10-03 23:40:48 +0000919 template <class _Tp>
Marshall Clow6ac8de02016-09-24 22:45:42 +0000920 typename enable_if
921 <
922 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
923 basic_string&
924 >::type
925 append(const _Tp& __t, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000926 basic_string& append(const value_type* __s, size_type __n);
927 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000928 basic_string& append(size_type __n, value_type __c);
929 template<class _InputIterator>
930 typename enable_if
931 <
Marshall Clowdf9db312016-01-13 21:54:34 +0000932 __is_exactly_input_iterator<_InputIterator>::value
933 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000934 basic_string&
935 >::type
936 append(_InputIterator __first, _InputIterator __last);
937 template<class _ForwardIterator>
938 typename enable_if
939 <
Marshall Clowdf9db312016-01-13 21:54:34 +0000940 __is_forward_iterator<_ForwardIterator>::value
941 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000942 basic_string&
943 >::type
944 append(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000945#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000946 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000947 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000948#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000949
950 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000951 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000952 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000953 _LIBCPP_INLINE_VISIBILITY reference front();
954 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
955 _LIBCPP_INLINE_VISIBILITY reference back();
956 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000957
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000958 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000959 basic_string& assign(__self_view __sv) { return assign(__sv.data(), __sv.size()); }
960 _LIBCPP_INLINE_VISIBILITY
Marshall Clowf40ec902016-03-09 18:08:29 +0000961 basic_string& assign(const basic_string& __str) { return *this = __str; }
Howard Hinnanta6119a82011-05-29 19:57:12 +0000962#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
963 _LIBCPP_INLINE_VISIBILITY
964 basic_string& assign(basic_string&& str)
Marshall Clow7ed093b2015-10-05 16:17:34 +0000965 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000966 {*this = _VSTD::move(str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000967#endif
Marshall Clowa93b5e22014-03-04 19:17:19 +0000968 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow42a87db2016-10-03 23:40:48 +0000969 template <class _Tp>
Marshall Clow6ac8de02016-09-24 22:45:42 +0000970 typename enable_if
971 <
972 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
973 basic_string&
974 >::type
975 assign(const _Tp & __t, size_type pos, size_type n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000976 basic_string& assign(const value_type* __s, size_type __n);
977 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000978 basic_string& assign(size_type __n, value_type __c);
979 template<class _InputIterator>
980 typename enable_if
981 <
Marshall Clowdf9db312016-01-13 21:54:34 +0000982 __is_exactly_input_iterator<_InputIterator>::value
983 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000984 basic_string&
985 >::type
986 assign(_InputIterator __first, _InputIterator __last);
987 template<class _ForwardIterator>
988 typename enable_if
989 <
Marshall Clowdf9db312016-01-13 21:54:34 +0000990 __is_forward_iterator<_ForwardIterator>::value
991 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000992 basic_string&
993 >::type
994 assign(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000995#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000996 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000997 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000998#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000999
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001000 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001001 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001002 _LIBCPP_INLINE_VISIBILITY
1003 basic_string& insert(size_type __pos1, __self_view __sv) { return insert(__pos1, __sv.data(), __sv.size()); }
Marshall Clow6ac8de02016-09-24 22:45:42 +00001004 template <class _Tp>
1005 typename enable_if
1006 <
1007 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1008 basic_string&
1009 >::type
1010 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
Marshall Clowa93b5e22014-03-04 19:17:19 +00001011 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001012 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1013 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001014 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1015 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001016 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001017 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1018 template<class _InputIterator>
1019 typename enable_if
1020 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001021 __is_exactly_input_iterator<_InputIterator>::value
1022 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001023 iterator
1024 >::type
1025 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1026 template<class _ForwardIterator>
1027 typename enable_if
1028 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001029 __is_forward_iterator<_ForwardIterator>::value
1030 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001031 iterator
1032 >::type
1033 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001034#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001035 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001036 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1037 {return insert(__pos, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001038#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001039
1040 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001041 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001042 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001043 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001044 iterator erase(const_iterator __first, const_iterator __last);
1045
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001046 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001047 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001048 _LIBCPP_INLINE_VISIBILITY
1049 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 +00001050 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
Marshall Clow6ac8de02016-09-24 22:45:42 +00001051 template <class _Tp>
1052 typename enable_if
1053 <
1054 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1055 basic_string&
1056 >::type
1057 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001058 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1059 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001060 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001061 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001062 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001063 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001064 basic_string& replace(const_iterator __i1, const_iterator __i2, __self_view __sv) { return replace(__i1 - begin(), __i2 - __i1, __sv); }
1065 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001066 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001067 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001068 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001069 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001070 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001071 template<class _InputIterator>
1072 typename enable_if
1073 <
1074 __is_input_iterator<_InputIterator>::value,
1075 basic_string&
1076 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001077 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Howard Hinnante3e32912011-08-12 21:56:02 +00001078#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001079 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001080 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001081 {return replace(__i1, __i2, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001082#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001083
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001084 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001085 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001086 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1087
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001088 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001089 void swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00001090#if _LIBCPP_STD_VER >= 14
1091 _NOEXCEPT;
1092#else
1093 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1094 __is_nothrow_swappable<allocator_type>::value);
1095#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001096
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001097 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001098 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001099 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001100 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Marshall Clowf532a702016-03-08 15:44:30 +00001101#if _LIBCPP_STD_VER > 14
1102 _LIBCPP_INLINE_VISIBILITY
1103 value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1104#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001105
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001106 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001107 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001108
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001109 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001110 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001111 _LIBCPP_INLINE_VISIBILITY
1112 size_type find(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001113 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001114 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001115 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001116 size_type find(value_type __c, size_type __pos = 0) 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 rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001120 _LIBCPP_INLINE_VISIBILITY
1121 size_type rfind(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001122 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001123 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001124 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001125 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001126
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001127 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001128 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001129 _LIBCPP_INLINE_VISIBILITY
1130 size_type find_first_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001131 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001132 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001133 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001134 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001135 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001136
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001137 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001138 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001139 _LIBCPP_INLINE_VISIBILITY
1140 size_type find_last_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001141 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001142 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001143 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001144 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001145 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001146
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001147 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001148 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001149 _LIBCPP_INLINE_VISIBILITY
1150 size_type find_first_not_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001151 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 +00001152 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001153 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001154 _LIBCPP_INLINE_VISIBILITY
1155 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1156
1157 _LIBCPP_INLINE_VISIBILITY
1158 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001159 _LIBCPP_INLINE_VISIBILITY
1160 size_type find_last_not_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001161 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 +00001162 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001163 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001164 _LIBCPP_INLINE_VISIBILITY
1165 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1166
1167 _LIBCPP_INLINE_VISIBILITY
1168 int compare(const basic_string& __str) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001169 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001170 int compare(__self_view __sv) const _NOEXCEPT;
1171 _LIBCPP_INLINE_VISIBILITY
1172 int compare(size_type __pos1, size_type __n1, __self_view __sv) const;
1173 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001174 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clowa93b5e22014-03-04 19:17:19 +00001175 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
Marshall Clow6ac8de02016-09-24 22:45:42 +00001176 template <class _Tp>
1177 typename enable_if
1178 <
1179 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1180 int
1181 >::type
1182 compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001183 int compare(const value_type* __s) const _NOEXCEPT;
1184 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1185 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001186
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001187 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:13 +00001188
1189 _LIBCPP_INLINE_VISIBILITY
1190 bool __is_long() const _NOEXCEPT
1191 {return bool(__r_.first().__s.__size_ & __short_mask);}
1192
Howard Hinnant499cea12013-08-23 17:37:05 +00001193#if _LIBCPP_DEBUG_LEVEL >= 2
1194
1195 bool __dereferenceable(const const_iterator* __i) const;
1196 bool __decrementable(const const_iterator* __i) const;
1197 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1198 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1199
1200#endif // _LIBCPP_DEBUG_LEVEL >= 2
1201
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001202private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001203 _LIBCPP_INLINE_VISIBILITY
1204 allocator_type& __alloc() _NOEXCEPT
1205 {return __r_.second();}
1206 _LIBCPP_INLINE_VISIBILITY
1207 const allocator_type& __alloc() const _NOEXCEPT
1208 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001209
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001210#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001211
Howard Hinnanta6119a82011-05-29 19:57:12 +00001212 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001213 void __set_short_size(size_type __s) _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001214# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001215 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:48 +00001216# else
1217 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1218# endif
1219
Howard Hinnanta6119a82011-05-29 19:57:12 +00001220 _LIBCPP_INLINE_VISIBILITY
1221 size_type __get_short_size() const _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001222# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001223 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:48 +00001224# else
1225 {return __r_.first().__s.__size_;}
1226# endif
1227
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001228#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001229
1230 _LIBCPP_INLINE_VISIBILITY
1231 void __set_short_size(size_type __s) _NOEXCEPT
1232# if _LIBCPP_BIG_ENDIAN
1233 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1234# else
1235 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1236# endif
1237
1238 _LIBCPP_INLINE_VISIBILITY
1239 size_type __get_short_size() const _NOEXCEPT
1240# if _LIBCPP_BIG_ENDIAN
1241 {return __r_.first().__s.__size_;}
1242# else
1243 {return __r_.first().__s.__size_ >> 1;}
1244# endif
1245
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001246#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001247
Howard Hinnanta6119a82011-05-29 19:57:12 +00001248 _LIBCPP_INLINE_VISIBILITY
1249 void __set_long_size(size_type __s) _NOEXCEPT
1250 {__r_.first().__l.__size_ = __s;}
1251 _LIBCPP_INLINE_VISIBILITY
1252 size_type __get_long_size() const _NOEXCEPT
1253 {return __r_.first().__l.__size_;}
1254 _LIBCPP_INLINE_VISIBILITY
1255 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001256 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1257
Howard Hinnanta6119a82011-05-29 19:57:12 +00001258 _LIBCPP_INLINE_VISIBILITY
1259 void __set_long_cap(size_type __s) _NOEXCEPT
1260 {__r_.first().__l.__cap_ = __long_mask | __s;}
1261 _LIBCPP_INLINE_VISIBILITY
1262 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001263 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001264
Howard Hinnanta6119a82011-05-29 19:57:12 +00001265 _LIBCPP_INLINE_VISIBILITY
1266 void __set_long_pointer(pointer __p) _NOEXCEPT
1267 {__r_.first().__l.__data_ = __p;}
1268 _LIBCPP_INLINE_VISIBILITY
1269 pointer __get_long_pointer() _NOEXCEPT
1270 {return __r_.first().__l.__data_;}
1271 _LIBCPP_INLINE_VISIBILITY
1272 const_pointer __get_long_pointer() const _NOEXCEPT
1273 {return __r_.first().__l.__data_;}
1274 _LIBCPP_INLINE_VISIBILITY
1275 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001276 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001277 _LIBCPP_INLINE_VISIBILITY
1278 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001279 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001280 _LIBCPP_INLINE_VISIBILITY
1281 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001282 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001283 _LIBCPP_INLINE_VISIBILITY
1284 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001285 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1286
Howard Hinnanta6119a82011-05-29 19:57:12 +00001287 _LIBCPP_INLINE_VISIBILITY
1288 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001289 {
1290 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1291 for (unsigned __i = 0; __i < __n_words; ++__i)
1292 __a[__i] = 0;
1293 }
1294
1295 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001296 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:20 +00001297 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001298 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001299 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001300 static _LIBCPP_INLINE_VISIBILITY
1301 size_type __recommend(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001302 {return (__s < __min_cap ? static_cast<size_type>(__min_cap) :
Howard Hinnant7f764502013-08-14 18:00:20 +00001303 __align_it<sizeof(value_type) < __alignment ?
Howard Hinnanta6119a82011-05-29 19:57:12 +00001304 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001305
Eric Fiselier6dbed462016-09-16 00:00:48 +00001306 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001307 void __init(const value_type* __s, size_type __sz, size_type __reserve);
Eric Fiselier6dbed462016-09-16 00:00:48 +00001308 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001309 void __init(const value_type* __s, size_type __sz);
Eric Fiselier6dbed462016-09-16 00:00:48 +00001310 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001311 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001312
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001313 template <class _InputIterator>
Eric Fiselier6dbed462016-09-16 00:00:48 +00001314 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001315 typename enable_if
1316 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001317 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001318 void
1319 >::type
1320 __init(_InputIterator __first, _InputIterator __last);
1321
1322 template <class _ForwardIterator>
Eric Fiselier6dbed462016-09-16 00:00:48 +00001323 inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001324 typename enable_if
1325 <
1326 __is_forward_iterator<_ForwardIterator>::value,
1327 void
1328 >::type
1329 __init(_ForwardIterator __first, _ForwardIterator __last);
1330
1331 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001332 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001333 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1334 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001335 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001336
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001337 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001338 void __erase_to_end(size_type __pos);
1339
Howard Hinnante32b5e22010-11-17 17:55:08 +00001340 _LIBCPP_INLINE_VISIBILITY
1341 void __copy_assign_alloc(const basic_string& __str)
1342 {__copy_assign_alloc(__str, integral_constant<bool,
1343 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1344
1345 _LIBCPP_INLINE_VISIBILITY
1346 void __copy_assign_alloc(const basic_string& __str, true_type)
1347 {
1348 if (__alloc() != __str.__alloc())
1349 {
1350 clear();
1351 shrink_to_fit();
1352 }
1353 __alloc() = __str.__alloc();
1354 }
1355
1356 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001357 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001358 {}
1359
1360#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001361 _LIBCPP_INLINE_VISIBILITY
Marshall Clowaf961ed2015-08-18 18:57:00 +00001362 void __move_assign(basic_string& __str, false_type)
1363 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001364 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001365 void __move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001366#if _LIBCPP_STD_VER > 14
1367 _NOEXCEPT;
1368#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001369 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001370#endif
Marshall Clowaf961ed2015-08-18 18:57:00 +00001371#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00001372
1373 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001374 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001375 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001376 _NOEXCEPT_(
1377 !__alloc_traits::propagate_on_container_move_assignment::value ||
1378 is_nothrow_move_assignable<allocator_type>::value)
1379 {__move_assign_alloc(__str, integral_constant<bool,
1380 __alloc_traits::propagate_on_container_move_assignment::value>());}
1381
1382 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001383 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001384 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1385 {
1386 __alloc() = _VSTD::move(__c.__alloc());
1387 }
1388
1389 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001390 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001391 _NOEXCEPT
1392 {}
1393
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001394 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1395 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001396
1397 friend basic_string operator+<>(const basic_string&, const basic_string&);
1398 friend basic_string operator+<>(const value_type*, const basic_string&);
1399 friend basic_string operator+<>(value_type, const basic_string&);
1400 friend basic_string operator+<>(const basic_string&, const value_type*);
1401 friend basic_string operator+<>(const basic_string&, value_type);
1402};
1403
1404template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001405inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001406void
1407basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1408{
Howard Hinnant499cea12013-08-23 17:37:05 +00001409#if _LIBCPP_DEBUG_LEVEL >= 2
1410 __get_db()->__invalidate_all(this);
1411#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001412}
1413
1414template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001415inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001416void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001417basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant499cea12013-08-23 17:37:05 +00001418#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantec3773c2011-12-01 20:21:04 +00001419 __pos
1420#endif
1421 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001422{
Howard Hinnant499cea12013-08-23 17:37:05 +00001423#if _LIBCPP_DEBUG_LEVEL >= 2
1424 __c_node* __c = __get_db()->__find_c_and_lock(this);
1425 if (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001426 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001427 const_pointer __new_last = __get_pointer() + __pos;
1428 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001429 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001430 --__p;
1431 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1432 if (__i->base() > __new_last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001433 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001434 (*__p)->__c_ = nullptr;
1435 if (--__c->end_ != __p)
1436 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001437 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001438 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001439 __get_db()->unlock();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001440 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001441#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001442}
1443
1444template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001445inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001446basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowc912c0c2015-06-04 02:05:41 +00001447 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001448{
Howard Hinnant499cea12013-08-23 17:37:05 +00001449#if _LIBCPP_DEBUG_LEVEL >= 2
1450 __get_db()->__insert_c(this);
1451#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001452 __zero();
1453}
1454
1455template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001456inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001457basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiselier692177d2015-07-18 20:40:46 +00001458#if _LIBCPP_STD_VER <= 14
1459 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1460#else
1461 _NOEXCEPT
1462#endif
1463: __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001464{
Howard Hinnant499cea12013-08-23 17:37:05 +00001465#if _LIBCPP_DEBUG_LEVEL >= 2
1466 __get_db()->__insert_c(this);
1467#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001468 __zero();
1469}
1470
1471template <class _CharT, class _Traits, class _Allocator>
Eric Fiselier6dbed462016-09-16 00:00:48 +00001472void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1473 size_type __sz,
1474 size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001475{
1476 if (__reserve > max_size())
1477 this->__throw_length_error();
1478 pointer __p;
1479 if (__reserve < __min_cap)
1480 {
1481 __set_short_size(__sz);
1482 __p = __get_short_pointer();
1483 }
1484 else
1485 {
1486 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001487 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001488 __set_long_pointer(__p);
1489 __set_long_cap(__cap+1);
1490 __set_long_size(__sz);
1491 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001492 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001493 traits_type::assign(__p[__sz], value_type());
1494}
1495
1496template <class _CharT, class _Traits, class _Allocator>
1497void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001498basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001499{
1500 if (__sz > max_size())
1501 this->__throw_length_error();
1502 pointer __p;
1503 if (__sz < __min_cap)
1504 {
1505 __set_short_size(__sz);
1506 __p = __get_short_pointer();
1507 }
1508 else
1509 {
1510 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001511 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001512 __set_long_pointer(__p);
1513 __set_long_cap(__cap+1);
1514 __set_long_size(__sz);
1515 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001516 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001517 traits_type::assign(__p[__sz], value_type());
1518}
1519
1520template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001521inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001522basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001523{
Howard Hinnant499cea12013-08-23 17:37:05 +00001524 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001525 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00001526#if _LIBCPP_DEBUG_LEVEL >= 2
1527 __get_db()->__insert_c(this);
1528#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001529}
1530
1531template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001532inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001533basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001534 : __r_(__a)
1535{
Howard Hinnant499cea12013-08-23 17:37:05 +00001536 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001537 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00001538#if _LIBCPP_DEBUG_LEVEL >= 2
1539 __get_db()->__insert_c(this);
1540#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001541}
1542
1543template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001544inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001545basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001546{
Howard Hinnant499cea12013-08-23 17:37:05 +00001547 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001548 __init(__s, __n);
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
1554template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001555inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001556basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001557 : __r_(__a)
1558{
Howard Hinnant499cea12013-08-23 17:37:05 +00001559 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001560 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001561#if _LIBCPP_DEBUG_LEVEL >= 2
1562 __get_db()->__insert_c(this);
1563#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001564}
1565
1566template <class _CharT, class _Traits, class _Allocator>
1567basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001568 : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001569{
1570 if (!__str.__is_long())
1571 __r_.first().__r = __str.__r_.first().__r;
1572 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001573 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001574#if _LIBCPP_DEBUG_LEVEL >= 2
1575 __get_db()->__insert_c(this);
1576#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001577}
1578
1579template <class _CharT, class _Traits, class _Allocator>
1580basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
1581 : __r_(__a)
1582{
1583 if (!__str.__is_long())
1584 __r_.first().__r = __str.__r_.first().__r;
1585 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001586 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001587#if _LIBCPP_DEBUG_LEVEL >= 2
1588 __get_db()->__insert_c(this);
1589#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001590}
1591
Howard Hinnant73d21a42010-09-04 23:28:19 +00001592#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001593
1594template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001595inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001596basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +00001597#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001598 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clow7b193f72015-06-03 19:56:43 +00001599#else
1600 _NOEXCEPT
1601#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001602 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001603{
1604 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:05 +00001605#if _LIBCPP_DEBUG_LEVEL >= 2
1606 __get_db()->__insert_c(this);
1607 if (__is_long())
1608 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001609#endif
1610}
1611
1612template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001613inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001614basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001615 : __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001616{
Marshall Clowd5549cc2014-07-17 15:32:20 +00001617 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001618 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd5549cc2014-07-17 15:32:20 +00001619 else
1620 {
1621 __r_.first().__r = __str.__r_.first().__r;
1622 __str.__zero();
1623 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001624#if _LIBCPP_DEBUG_LEVEL >= 2
1625 __get_db()->__insert_c(this);
1626 if (__is_long())
1627 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001628#endif
1629}
1630
Howard Hinnant73d21a42010-09-04 23:28:19 +00001631#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001632
1633template <class _CharT, class _Traits, class _Allocator>
1634void
1635basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1636{
1637 if (__n > max_size())
1638 this->__throw_length_error();
1639 pointer __p;
1640 if (__n < __min_cap)
1641 {
1642 __set_short_size(__n);
1643 __p = __get_short_pointer();
1644 }
1645 else
1646 {
1647 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001648 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001649 __set_long_pointer(__p);
1650 __set_long_cap(__cap+1);
1651 __set_long_size(__n);
1652 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001653 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001654 traits_type::assign(__p[__n], value_type());
1655}
1656
1657template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001658inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001659basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
1660{
1661 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001662#if _LIBCPP_DEBUG_LEVEL >= 2
1663 __get_db()->__insert_c(this);
1664#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001665}
1666
1667template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001668inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001669basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
1670 : __r_(__a)
1671{
1672 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001673#if _LIBCPP_DEBUG_LEVEL >= 2
1674 __get_db()->__insert_c(this);
1675#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001676}
1677
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001678template <class _CharT, class _Traits, class _Allocator>
1679basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
1680 const allocator_type& __a)
1681 : __r_(__a)
1682{
1683 size_type __str_sz = __str.size();
1684 if (__pos > __str_sz)
1685 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001686 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
Howard Hinnant499cea12013-08-23 17:37:05 +00001687#if _LIBCPP_DEBUG_LEVEL >= 2
1688 __get_db()->__insert_c(this);
1689#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001690}
1691
1692template <class _CharT, class _Traits, class _Allocator>
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001693inline _LIBCPP_INLINE_VISIBILITY
1694basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
1695 const allocator_type& __a)
1696 : __r_(__a)
1697{
1698 size_type __str_sz = __str.size();
1699 if (__pos > __str_sz)
1700 this->__throw_out_of_range();
1701 __init(__str.data() + __pos, __str_sz - __pos);
1702#if _LIBCPP_DEBUG_LEVEL >= 2
1703 __get_db()->__insert_c(this);
1704#endif
1705}
1706
1707template <class _CharT, class _Traits, class _Allocator>
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001708inline _LIBCPP_INLINE_VISIBILITY
1709basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv)
1710{
1711 __init(__sv.data(), __sv.size());
1712#if _LIBCPP_DEBUG_LEVEL >= 2
1713 __get_db()->__insert_c(this);
1714#endif
1715}
1716
1717template <class _CharT, class _Traits, class _Allocator>
1718inline _LIBCPP_INLINE_VISIBILITY
1719basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv, const allocator_type& __a)
1720 : __r_(__a)
1721{
1722 __init(__sv.data(), __sv.size());
1723#if _LIBCPP_DEBUG_LEVEL >= 2
1724 __get_db()->__insert_c(this);
1725#endif
1726}
1727
1728template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001729template <class _InputIterator>
1730typename enable_if
1731<
Marshall Clowdf9db312016-01-13 21:54:34 +00001732 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001733 void
1734>::type
1735basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
1736{
1737 __zero();
1738#ifndef _LIBCPP_NO_EXCEPTIONS
1739 try
1740 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001741#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001742 for (; __first != __last; ++__first)
1743 push_back(*__first);
1744#ifndef _LIBCPP_NO_EXCEPTIONS
1745 }
1746 catch (...)
1747 {
1748 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00001749 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001750 throw;
1751 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001752#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001753}
1754
1755template <class _CharT, class _Traits, class _Allocator>
1756template <class _ForwardIterator>
1757typename enable_if
1758<
1759 __is_forward_iterator<_ForwardIterator>::value,
1760 void
1761>::type
1762basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
1763{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001764 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001765 if (__sz > max_size())
1766 this->__throw_length_error();
1767 pointer __p;
1768 if (__sz < __min_cap)
1769 {
1770 __set_short_size(__sz);
1771 __p = __get_short_pointer();
1772 }
1773 else
1774 {
1775 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001776 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001777 __set_long_pointer(__p);
1778 __set_long_cap(__cap+1);
1779 __set_long_size(__sz);
1780 }
Eric Fiselierb9919752014-10-27 19:28:20 +00001781 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001782 traits_type::assign(*__p, *__first);
1783 traits_type::assign(*__p, value_type());
1784}
1785
1786template <class _CharT, class _Traits, class _Allocator>
1787template<class _InputIterator>
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(_InputIterator __first, _InputIterator __last)
1790{
1791 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00001792#if _LIBCPP_DEBUG_LEVEL >= 2
1793 __get_db()->__insert_c(this);
1794#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001795}
1796
1797template <class _CharT, class _Traits, class _Allocator>
1798template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001799inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001800basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
1801 const allocator_type& __a)
1802 : __r_(__a)
1803{
1804 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00001805#if _LIBCPP_DEBUG_LEVEL >= 2
1806 __get_db()->__insert_c(this);
1807#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001808}
1809
Howard Hinnante3e32912011-08-12 21:56:02 +00001810#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1811
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001812template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001813inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001814basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
1815{
1816 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00001817#if _LIBCPP_DEBUG_LEVEL >= 2
1818 __get_db()->__insert_c(this);
1819#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001820}
1821
1822template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001823inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001824basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
1825 : __r_(__a)
1826{
1827 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00001828#if _LIBCPP_DEBUG_LEVEL >= 2
1829 __get_db()->__insert_c(this);
1830#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001831}
1832
Howard Hinnante3e32912011-08-12 21:56:02 +00001833#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1834
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001835template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001836basic_string<_CharT, _Traits, _Allocator>::~basic_string()
1837{
Howard Hinnant499cea12013-08-23 17:37:05 +00001838#if _LIBCPP_DEBUG_LEVEL >= 2
1839 __get_db()->__erase_c(this);
1840#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001841 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00001842 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001843}
1844
1845template <class _CharT, class _Traits, class _Allocator>
1846void
1847basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
1848 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001849 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 +00001850{
1851 size_type __ms = max_size();
1852 if (__delta_cap > __ms - __old_cap - 1)
1853 this->__throw_length_error();
1854 pointer __old_p = __get_pointer();
1855 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00001856 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001857 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001858 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001859 __invalidate_all_iterators();
1860 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001861 traits_type::copy(_VSTD::__to_raw_pointer(__p),
1862 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001863 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001864 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001865 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
1866 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001867 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
1868 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001869 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001870 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001871 __set_long_pointer(__p);
1872 __set_long_cap(__cap+1);
1873 __old_sz = __n_copy + __n_add + __sec_cp_sz;
1874 __set_long_size(__old_sz);
1875 traits_type::assign(__p[__old_sz], value_type());
1876}
1877
1878template <class _CharT, class _Traits, class _Allocator>
1879void
1880basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1881 size_type __n_copy, size_type __n_del, size_type __n_add)
1882{
1883 size_type __ms = max_size();
Marshall Clowecc8d7b2013-11-06 14:24:38 +00001884 if (__delta_cap > __ms - __old_cap)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001885 this->__throw_length_error();
1886 pointer __old_p = __get_pointer();
1887 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00001888 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001889 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001890 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001891 __invalidate_all_iterators();
1892 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001893 traits_type::copy(_VSTD::__to_raw_pointer(__p),
1894 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001895 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
1896 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001897 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
1898 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
1899 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001900 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001901 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001902 __set_long_pointer(__p);
1903 __set_long_cap(__cap+1);
1904}
1905
1906// assign
1907
1908template <class _CharT, class _Traits, class _Allocator>
1909basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001910basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001911{
Alp Tokerec34c482014-05-15 11:27:39 +00001912 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001913 size_type __cap = capacity();
1914 if (__cap >= __n)
1915 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001916 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001917 traits_type::move(__p, __s, __n);
1918 traits_type::assign(__p[__n], value_type());
1919 __set_size(__n);
1920 __invalidate_iterators_past(__n);
1921 }
1922 else
1923 {
1924 size_type __sz = size();
1925 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
1926 }
1927 return *this;
1928}
1929
1930template <class _CharT, class _Traits, class _Allocator>
1931basic_string<_CharT, _Traits, _Allocator>&
1932basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
1933{
1934 size_type __cap = capacity();
1935 if (__cap < __n)
1936 {
1937 size_type __sz = size();
1938 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
1939 }
1940 else
1941 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001942 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001943 traits_type::assign(__p, __n, __c);
1944 traits_type::assign(__p[__n], value_type());
1945 __set_size(__n);
1946 return *this;
1947}
1948
1949template <class _CharT, class _Traits, class _Allocator>
1950basic_string<_CharT, _Traits, _Allocator>&
1951basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
1952{
1953 pointer __p;
1954 if (__is_long())
1955 {
1956 __p = __get_long_pointer();
1957 __set_long_size(1);
1958 }
1959 else
1960 {
1961 __p = __get_short_pointer();
1962 __set_short_size(1);
1963 }
1964 traits_type::assign(*__p, __c);
1965 traits_type::assign(*++__p, value_type());
1966 __invalidate_iterators_past(1);
1967 return *this;
1968}
1969
1970template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00001971basic_string<_CharT, _Traits, _Allocator>&
1972basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
1973{
1974 if (this != &__str)
1975 {
1976 __copy_assign_alloc(__str);
Marshall Clowf40ec902016-03-09 18:08:29 +00001977 assign(__str.data(), __str.size());
Howard Hinnante32b5e22010-11-17 17:55:08 +00001978 }
1979 return *this;
1980}
1981
1982#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1983
1984template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001985inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00001986void
1987basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001988 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001989{
1990 if (__alloc() != __str.__alloc())
1991 assign(__str);
1992 else
1993 __move_assign(__str, true_type());
1994}
1995
1996template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001997inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00001998void
1999basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002000#if _LIBCPP_STD_VER > 14
2001 _NOEXCEPT
2002#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00002003 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002004#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00002005{
2006 clear();
2007 shrink_to_fit();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00002008 __r_.first() = __str.__r_.first();
2009 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00002010 __str.__zero();
2011}
2012
2013template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002014inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00002015basic_string<_CharT, _Traits, _Allocator>&
2016basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +00002017 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnante32b5e22010-11-17 17:55:08 +00002018{
2019 __move_assign(__str, integral_constant<bool,
2020 __alloc_traits::propagate_on_container_move_assignment::value>());
2021 return *this;
2022}
2023
2024#endif
2025
2026template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002027template<class _InputIterator>
2028typename enable_if
2029<
Marshall Clowdf9db312016-01-13 21:54:34 +00002030 __is_exactly_input_iterator <_InputIterator>::value
2031 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002032 basic_string<_CharT, _Traits, _Allocator>&
2033>::type
2034basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2035{
Marshall Clowd979eed2016-09-05 01:54:30 +00002036 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002037 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002038 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002039}
2040
2041template <class _CharT, class _Traits, class _Allocator>
2042template<class _ForwardIterator>
2043typename enable_if
2044<
Marshall Clowdf9db312016-01-13 21:54:34 +00002045 __is_forward_iterator<_ForwardIterator>::value
2046 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002047 basic_string<_CharT, _Traits, _Allocator>&
2048>::type
2049basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2050{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002051 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002052 size_type __cap = capacity();
2053 if (__cap < __n)
2054 {
2055 size_type __sz = size();
2056 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2057 }
2058 else
2059 __invalidate_iterators_past(__n);
2060 pointer __p = __get_pointer();
2061 for (; __first != __last; ++__first, ++__p)
2062 traits_type::assign(*__p, *__first);
2063 traits_type::assign(*__p, value_type());
2064 __set_size(__n);
2065 return *this;
2066}
2067
2068template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002069basic_string<_CharT, _Traits, _Allocator>&
2070basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2071{
2072 size_type __sz = __str.size();
2073 if (__pos > __sz)
2074 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002075 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002076}
2077
2078template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002079template <class _Tp>
2080typename enable_if
2081<
2082 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2083 basic_string<_CharT, _Traits, _Allocator>&
2084>::type
2085basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002086{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002087 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002088 size_type __sz = __sv.size();
2089 if (__pos > __sz)
2090 this->__throw_out_of_range();
2091 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2092}
2093
2094
2095template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002096basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002097basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002098{
Alp Tokerec34c482014-05-15 11:27:39 +00002099 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002100 return assign(__s, traits_type::length(__s));
2101}
2102
2103// append
2104
2105template <class _CharT, class _Traits, class _Allocator>
2106basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002107basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002108{
Alp Tokerec34c482014-05-15 11:27:39 +00002109 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002110 size_type __cap = capacity();
2111 size_type __sz = size();
2112 if (__cap - __sz >= __n)
2113 {
2114 if (__n)
2115 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002116 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002117 traits_type::copy(__p + __sz, __s, __n);
2118 __sz += __n;
2119 __set_size(__sz);
2120 traits_type::assign(__p[__sz], value_type());
2121 }
2122 }
2123 else
2124 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2125 return *this;
2126}
2127
2128template <class _CharT, class _Traits, class _Allocator>
2129basic_string<_CharT, _Traits, _Allocator>&
2130basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2131{
2132 if (__n)
2133 {
2134 size_type __cap = capacity();
2135 size_type __sz = size();
2136 if (__cap - __sz < __n)
2137 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2138 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002139 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002140 __sz += __n;
2141 __set_size(__sz);
2142 traits_type::assign(__p[__sz], value_type());
2143 }
2144 return *this;
2145}
2146
2147template <class _CharT, class _Traits, class _Allocator>
2148void
2149basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2150{
Howard Hinnant15467182013-04-30 21:44:48 +00002151 bool __is_short = !__is_long();
2152 size_type __cap;
2153 size_type __sz;
2154 if (__is_short)
2155 {
2156 __cap = __min_cap - 1;
2157 __sz = __get_short_size();
2158 }
2159 else
2160 {
2161 __cap = __get_long_cap() - 1;
2162 __sz = __get_long_size();
2163 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002164 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002165 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002166 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002167 __is_short = !__is_long();
2168 }
2169 pointer __p;
2170 if (__is_short)
2171 {
2172 __p = __get_short_pointer() + __sz;
2173 __set_short_size(__sz+1);
2174 }
2175 else
2176 {
2177 __p = __get_long_pointer() + __sz;
2178 __set_long_size(__sz+1);
2179 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002180 traits_type::assign(*__p, __c);
2181 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002182}
2183
2184template <class _CharT, class _Traits, class _Allocator>
2185template<class _InputIterator>
2186typename enable_if
2187<
Marshall Clowdf9db312016-01-13 21:54:34 +00002188 __is_exactly_input_iterator<_InputIterator>::value
2189 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002190 basic_string<_CharT, _Traits, _Allocator>&
2191>::type
2192basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
2193{
Marshall Clowd979eed2016-09-05 01:54:30 +00002194 const basic_string __temp (__first, __last, __alloc());
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002195 append(__temp.data(), __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002196 return *this;
2197}
2198
Marshall Clowac655ef2016-09-07 03:32:06 +00002199template <class _Tp>
Marshall Clowd979eed2016-09-05 01:54:30 +00002200bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
2201{
2202 return __first <= __p && __p < __last;
2203}
2204
Marshall Clowac655ef2016-09-07 03:32:06 +00002205template <class _Tp1, class _Tp2>
2206bool __ptr_in_range (const _Tp1* __p, const _Tp2* __first, const _Tp2* __last)
2207{
2208 return false;
2209}
2210
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002211template <class _CharT, class _Traits, class _Allocator>
2212template<class _ForwardIterator>
2213typename enable_if
2214<
Marshall Clowdf9db312016-01-13 21:54:34 +00002215 __is_forward_iterator<_ForwardIterator>::value
2216 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002217 basic_string<_CharT, _Traits, _Allocator>&
2218>::type
2219basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
2220{
2221 size_type __sz = size();
2222 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002223 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002224 if (__n)
2225 {
Marshall Clowd979eed2016-09-05 01:54:30 +00002226 if ( __ptr_in_range(&*__first, data(), data() + size()))
2227 {
2228 const basic_string __temp (__first, __last, __alloc());
2229 append(__temp.data(), __temp.size());
2230 }
2231 else
2232 {
2233 if (__cap - __sz < __n)
2234 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2235 pointer __p = __get_pointer() + __sz;
2236 for (; __first != __last; ++__p, ++__first)
2237 traits_type::assign(*__p, *__first);
2238 traits_type::assign(*__p, value_type());
2239 __set_size(__sz + __n);
2240 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002241 }
2242 return *this;
2243}
2244
2245template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002246inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002247basic_string<_CharT, _Traits, _Allocator>&
2248basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2249{
2250 return append(__str.data(), __str.size());
2251}
2252
2253template <class _CharT, class _Traits, class _Allocator>
2254basic_string<_CharT, _Traits, _Allocator>&
2255basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2256{
2257 size_type __sz = __str.size();
2258 if (__pos > __sz)
2259 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002260 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002261}
2262
2263template <class _CharT, class _Traits, class _Allocator>
Marshall Clow42a87db2016-10-03 23:40:48 +00002264template <class _Tp>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002265 typename enable_if
2266 <
2267 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2268 basic_string<_CharT, _Traits, _Allocator>&
2269 >::type
2270basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002271{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002272 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002273 size_type __sz = __sv.size();
2274 if (__pos > __sz)
2275 this->__throw_out_of_range();
2276 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2277}
2278
2279template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002280basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002281basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002282{
Alp Tokerec34c482014-05-15 11:27:39 +00002283 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002284 return append(__s, traits_type::length(__s));
2285}
2286
2287// insert
2288
2289template <class _CharT, class _Traits, class _Allocator>
2290basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002291basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002292{
Alp Tokerec34c482014-05-15 11:27:39 +00002293 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002294 size_type __sz = size();
2295 if (__pos > __sz)
2296 this->__throw_out_of_range();
2297 size_type __cap = capacity();
2298 if (__cap - __sz >= __n)
2299 {
2300 if (__n)
2301 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002302 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002303 size_type __n_move = __sz - __pos;
2304 if (__n_move != 0)
2305 {
2306 if (__p + __pos <= __s && __s < __p + __sz)
2307 __s += __n;
2308 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2309 }
2310 traits_type::move(__p + __pos, __s, __n);
2311 __sz += __n;
2312 __set_size(__sz);
2313 traits_type::assign(__p[__sz], value_type());
2314 }
2315 }
2316 else
2317 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2318 return *this;
2319}
2320
2321template <class _CharT, class _Traits, class _Allocator>
2322basic_string<_CharT, _Traits, _Allocator>&
2323basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2324{
2325 size_type __sz = size();
2326 if (__pos > __sz)
2327 this->__throw_out_of_range();
2328 if (__n)
2329 {
2330 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002331 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002332 if (__cap - __sz >= __n)
2333 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002334 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002335 size_type __n_move = __sz - __pos;
2336 if (__n_move != 0)
2337 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2338 }
2339 else
2340 {
2341 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002342 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002343 }
2344 traits_type::assign(__p + __pos, __n, __c);
2345 __sz += __n;
2346 __set_size(__sz);
2347 traits_type::assign(__p[__sz], value_type());
2348 }
2349 return *this;
2350}
2351
2352template <class _CharT, class _Traits, class _Allocator>
2353template<class _InputIterator>
2354typename enable_if
2355<
Marshall Clowdf9db312016-01-13 21:54:34 +00002356 __is_exactly_input_iterator<_InputIterator>::value
2357 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2358 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002359>::type
2360basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2361{
Howard Hinnant499cea12013-08-23 17:37:05 +00002362#if _LIBCPP_DEBUG_LEVEL >= 2
2363 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2364 "string::insert(iterator, range) called with an iterator not"
2365 " referring to this string");
2366#endif
Marshall Clowd979eed2016-09-05 01:54:30 +00002367 const basic_string __temp(__first, __last, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002368 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002369}
2370
2371template <class _CharT, class _Traits, class _Allocator>
2372template<class _ForwardIterator>
2373typename enable_if
2374<
Marshall Clowdf9db312016-01-13 21:54:34 +00002375 __is_forward_iterator<_ForwardIterator>::value
2376 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002377 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2378>::type
2379basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2380{
Howard Hinnant499cea12013-08-23 17:37:05 +00002381#if _LIBCPP_DEBUG_LEVEL >= 2
2382 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2383 "string::insert(iterator, range) called with an iterator not"
2384 " referring to this string");
2385#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002386 size_type __ip = static_cast<size_type>(__pos - begin());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002387 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002388 if (__n)
2389 {
Marshall Clowd979eed2016-09-05 01:54:30 +00002390 if ( __ptr_in_range(&*__first, data(), data() + size()))
2391 {
2392 const basic_string __temp(__first, __last, __alloc());
2393 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2394 }
2395
2396 size_type __sz = size();
2397 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002398 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002399 if (__cap - __sz >= __n)
2400 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002401 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002402 size_type __n_move = __sz - __ip;
2403 if (__n_move != 0)
2404 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2405 }
2406 else
2407 {
2408 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002409 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002410 }
2411 __sz += __n;
2412 __set_size(__sz);
2413 traits_type::assign(__p[__sz], value_type());
2414 for (__p += __ip; __first != __last; ++__p, ++__first)
2415 traits_type::assign(*__p, *__first);
2416 }
2417 return begin() + __ip;
2418}
2419
2420template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002421inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002422basic_string<_CharT, _Traits, _Allocator>&
2423basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2424{
2425 return insert(__pos1, __str.data(), __str.size());
2426}
2427
2428template <class _CharT, class _Traits, class _Allocator>
2429basic_string<_CharT, _Traits, _Allocator>&
2430basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2431 size_type __pos2, size_type __n)
2432{
2433 size_type __str_sz = __str.size();
2434 if (__pos2 > __str_sz)
2435 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002436 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002437}
2438
2439template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002440template <class _Tp>
2441typename enable_if
2442<
2443 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2444 basic_string<_CharT, _Traits, _Allocator>&
2445>::type
2446basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002447 size_type __pos2, size_type __n)
2448{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002449 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002450 size_type __str_sz = __sv.size();
2451 if (__pos2 > __str_sz)
2452 this->__throw_out_of_range();
2453 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2454}
2455
2456template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002457basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002458basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002459{
Alp Tokerec34c482014-05-15 11:27:39 +00002460 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002461 return insert(__pos, __s, traits_type::length(__s));
2462}
2463
2464template <class _CharT, class _Traits, class _Allocator>
2465typename basic_string<_CharT, _Traits, _Allocator>::iterator
2466basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2467{
2468 size_type __ip = static_cast<size_type>(__pos - begin());
2469 size_type __sz = size();
2470 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002471 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002472 if (__cap == __sz)
2473 {
2474 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002475 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002476 }
2477 else
2478 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002479 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002480 size_type __n_move = __sz - __ip;
2481 if (__n_move != 0)
2482 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2483 }
2484 traits_type::assign(__p[__ip], __c);
2485 traits_type::assign(__p[++__sz], value_type());
2486 __set_size(__sz);
2487 return begin() + static_cast<difference_type>(__ip);
2488}
2489
2490template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002491inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002492typename basic_string<_CharT, _Traits, _Allocator>::iterator
2493basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2494{
Howard Hinnant499cea12013-08-23 17:37:05 +00002495#if _LIBCPP_DEBUG_LEVEL >= 2
2496 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2497 "string::insert(iterator, n, value) called with an iterator not"
2498 " referring to this string");
2499#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002500 difference_type __p = __pos - begin();
2501 insert(static_cast<size_type>(__p), __n, __c);
2502 return begin() + __p;
2503}
2504
2505// replace
2506
2507template <class _CharT, class _Traits, class _Allocator>
2508basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002509basic_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 +00002510{
Alp Tokerec34c482014-05-15 11:27:39 +00002511 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002512 size_type __sz = size();
2513 if (__pos > __sz)
2514 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002515 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002516 size_type __cap = capacity();
2517 if (__cap - __sz + __n1 >= __n2)
2518 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002519 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002520 if (__n1 != __n2)
2521 {
2522 size_type __n_move = __sz - __pos - __n1;
2523 if (__n_move != 0)
2524 {
2525 if (__n1 > __n2)
2526 {
2527 traits_type::move(__p + __pos, __s, __n2);
2528 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2529 goto __finish;
2530 }
2531 if (__p + __pos < __s && __s < __p + __sz)
2532 {
2533 if (__p + __pos + __n1 <= __s)
2534 __s += __n2 - __n1;
2535 else // __p + __pos < __s < __p + __pos + __n1
2536 {
2537 traits_type::move(__p + __pos, __s, __n1);
2538 __pos += __n1;
2539 __s += __n2;
2540 __n2 -= __n1;
2541 __n1 = 0;
2542 }
2543 }
2544 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2545 }
2546 }
2547 traits_type::move(__p + __pos, __s, __n2);
2548__finish:
2549 __sz += __n2 - __n1;
2550 __set_size(__sz);
2551 __invalidate_iterators_past(__sz);
2552 traits_type::assign(__p[__sz], value_type());
2553 }
2554 else
2555 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2556 return *this;
2557}
2558
2559template <class _CharT, class _Traits, class _Allocator>
2560basic_string<_CharT, _Traits, _Allocator>&
2561basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
2562{
2563 size_type __sz = size();
2564 if (__pos > __sz)
2565 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002566 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002567 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002568 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002569 if (__cap - __sz + __n1 >= __n2)
2570 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002571 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002572 if (__n1 != __n2)
2573 {
2574 size_type __n_move = __sz - __pos - __n1;
2575 if (__n_move != 0)
2576 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2577 }
2578 }
2579 else
2580 {
2581 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002582 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002583 }
2584 traits_type::assign(__p + __pos, __n2, __c);
2585 __sz += __n2 - __n1;
2586 __set_size(__sz);
2587 __invalidate_iterators_past(__sz);
2588 traits_type::assign(__p[__sz], value_type());
2589 return *this;
2590}
2591
2592template <class _CharT, class _Traits, class _Allocator>
2593template<class _InputIterator>
2594typename enable_if
2595<
2596 __is_input_iterator<_InputIterator>::value,
2597 basic_string<_CharT, _Traits, _Allocator>&
2598>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002599basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002600 _InputIterator __j1, _InputIterator __j2)
2601{
Marshall Clowd979eed2016-09-05 01:54:30 +00002602 const basic_string __temp(__j1, __j2, __alloc());
Marshall Clowdf9db312016-01-13 21:54:34 +00002603 return this->replace(__i1, __i2, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002604}
2605
2606template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002607inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002608basic_string<_CharT, _Traits, _Allocator>&
2609basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2610{
2611 return replace(__pos1, __n1, __str.data(), __str.size());
2612}
2613
2614template <class _CharT, class _Traits, class _Allocator>
2615basic_string<_CharT, _Traits, _Allocator>&
2616basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2617 size_type __pos2, size_type __n2)
2618{
2619 size_type __str_sz = __str.size();
2620 if (__pos2 > __str_sz)
2621 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002622 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002623}
2624
2625template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00002626template <class _Tp>
2627typename enable_if
2628<
2629 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2630 basic_string<_CharT, _Traits, _Allocator>&
2631>::type
2632basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002633 size_type __pos2, size_type __n2)
2634{
Marshall Clow6ac8de02016-09-24 22:45:42 +00002635 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002636 size_type __str_sz = __sv.size();
2637 if (__pos2 > __str_sz)
2638 this->__throw_out_of_range();
2639 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2640}
2641
2642template <class _CharT, class _Traits, class _Allocator>
2643basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002644basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002645{
Alp Tokerec34c482014-05-15 11:27:39 +00002646 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002647 return replace(__pos, __n1, __s, traits_type::length(__s));
2648}
2649
2650template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002651inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002652basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002653basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002654{
2655 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2656 __str.data(), __str.size());
2657}
2658
2659template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002660inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002661basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002662basic_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 +00002663{
2664 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2665}
2666
2667template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002668inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002669basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002670basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002671{
2672 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2673}
2674
2675template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002676inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002677basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002678basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002679{
2680 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2681}
2682
2683// erase
2684
2685template <class _CharT, class _Traits, class _Allocator>
2686basic_string<_CharT, _Traits, _Allocator>&
2687basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2688{
2689 size_type __sz = size();
2690 if (__pos > __sz)
2691 this->__throw_out_of_range();
2692 if (__n)
2693 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002694 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002695 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002696 size_type __n_move = __sz - __pos - __n;
2697 if (__n_move != 0)
2698 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2699 __sz -= __n;
2700 __set_size(__sz);
2701 __invalidate_iterators_past(__sz);
2702 traits_type::assign(__p[__sz], value_type());
2703 }
2704 return *this;
2705}
2706
2707template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002708inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002709typename basic_string<_CharT, _Traits, _Allocator>::iterator
2710basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2711{
Howard Hinnant499cea12013-08-23 17:37:05 +00002712#if _LIBCPP_DEBUG_LEVEL >= 2
2713 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2714 "string::erase(iterator) called with an iterator not"
2715 " referring to this string");
2716#endif
2717 _LIBCPP_ASSERT(__pos != end(),
2718 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002719 iterator __b = begin();
2720 size_type __r = static_cast<size_type>(__pos - __b);
2721 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00002722 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002723}
2724
2725template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002726inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002727typename basic_string<_CharT, _Traits, _Allocator>::iterator
2728basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
2729{
Howard Hinnant499cea12013-08-23 17:37:05 +00002730#if _LIBCPP_DEBUG_LEVEL >= 2
2731 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
2732 "string::erase(iterator, iterator) called with an iterator not"
2733 " referring to this string");
2734#endif
2735 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002736 iterator __b = begin();
2737 size_type __r = static_cast<size_type>(__first - __b);
2738 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00002739 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002740}
2741
2742template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002743inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002744void
2745basic_string<_CharT, _Traits, _Allocator>::pop_back()
2746{
Howard Hinnant499cea12013-08-23 17:37:05 +00002747 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002748 size_type __sz;
2749 if (__is_long())
2750 {
2751 __sz = __get_long_size() - 1;
2752 __set_long_size(__sz);
2753 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
2754 }
2755 else
2756 {
2757 __sz = __get_short_size() - 1;
2758 __set_short_size(__sz);
2759 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
2760 }
2761 __invalidate_iterators_past(__sz);
2762}
2763
2764template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002765inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002766void
Howard Hinnanta6119a82011-05-29 19:57:12 +00002767basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002768{
2769 __invalidate_all_iterators();
2770 if (__is_long())
2771 {
2772 traits_type::assign(*__get_long_pointer(), value_type());
2773 __set_long_size(0);
2774 }
2775 else
2776 {
2777 traits_type::assign(*__get_short_pointer(), value_type());
2778 __set_short_size(0);
2779 }
2780}
2781
2782template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002783inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002784void
2785basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
2786{
2787 if (__is_long())
2788 {
2789 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
2790 __set_long_size(__pos);
2791 }
2792 else
2793 {
2794 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
2795 __set_short_size(__pos);
2796 }
2797 __invalidate_iterators_past(__pos);
2798}
2799
2800template <class _CharT, class _Traits, class _Allocator>
2801void
2802basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
2803{
2804 size_type __sz = size();
2805 if (__n > __sz)
2806 append(__n - __sz, __c);
2807 else
2808 __erase_to_end(__n);
2809}
2810
2811template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002812inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002813typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00002814basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002815{
Howard Hinnante32b5e22010-11-17 17:55:08 +00002816 size_type __m = __alloc_traits::max_size(__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002817#if _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:08 +00002818 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002819#else
Marshall Clow09f85502013-10-31 17:23:08 +00002820 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002821#endif
2822}
2823
2824template <class _CharT, class _Traits, class _Allocator>
2825void
2826basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
2827{
2828 if (__res_arg > max_size())
2829 this->__throw_length_error();
2830 size_type __cap = capacity();
2831 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002832 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002833 __res_arg = __recommend(__res_arg);
2834 if (__res_arg != __cap)
2835 {
2836 pointer __new_data, __p;
2837 bool __was_long, __now_long;
2838 if (__res_arg == __min_cap - 1)
2839 {
2840 __was_long = true;
2841 __now_long = false;
2842 __new_data = __get_short_pointer();
2843 __p = __get_long_pointer();
2844 }
2845 else
2846 {
2847 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002848 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002849 else
2850 {
2851 #ifndef _LIBCPP_NO_EXCEPTIONS
2852 try
2853 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002854 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00002855 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002856 #ifndef _LIBCPP_NO_EXCEPTIONS
2857 }
2858 catch (...)
2859 {
2860 return;
2861 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002862 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002863 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002864 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00002865 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002866 }
2867 __now_long = true;
2868 __was_long = __is_long();
2869 __p = __get_pointer();
2870 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002871 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
2872 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002873 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002874 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002875 if (__now_long)
2876 {
2877 __set_long_cap(__res_arg+1);
2878 __set_long_size(__sz);
2879 __set_long_pointer(__new_data);
2880 }
2881 else
2882 __set_short_size(__sz);
2883 __invalidate_all_iterators();
2884 }
2885}
2886
2887template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002888inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002889typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002890basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002891{
Howard Hinnant499cea12013-08-23 17:37:05 +00002892 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002893 return *(data() + __pos);
2894}
2895
2896template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002897inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002898typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002899basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002900{
Howard Hinnant499cea12013-08-23 17:37:05 +00002901 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002902 return *(__get_pointer() + __pos);
2903}
2904
2905template <class _CharT, class _Traits, class _Allocator>
2906typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2907basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
2908{
2909 if (__n >= size())
2910 this->__throw_out_of_range();
2911 return (*this)[__n];
2912}
2913
2914template <class _CharT, class _Traits, class _Allocator>
2915typename basic_string<_CharT, _Traits, _Allocator>::reference
2916basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
2917{
2918 if (__n >= size())
2919 this->__throw_out_of_range();
2920 return (*this)[__n];
2921}
2922
2923template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002924inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002925typename basic_string<_CharT, _Traits, _Allocator>::reference
2926basic_string<_CharT, _Traits, _Allocator>::front()
2927{
Howard Hinnant499cea12013-08-23 17:37:05 +00002928 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002929 return *__get_pointer();
2930}
2931
2932template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002933inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002934typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2935basic_string<_CharT, _Traits, _Allocator>::front() const
2936{
Howard Hinnant499cea12013-08-23 17:37:05 +00002937 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002938 return *data();
2939}
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>::reference
2944basic_string<_CharT, _Traits, _Allocator>::back()
2945{
Howard Hinnant499cea12013-08-23 17:37:05 +00002946 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002947 return *(__get_pointer() + size() - 1);
2948}
2949
2950template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002951inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002952typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2953basic_string<_CharT, _Traits, _Allocator>::back() const
2954{
Howard Hinnant499cea12013-08-23 17:37:05 +00002955 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002956 return *(data() + size() - 1);
2957}
2958
2959template <class _CharT, class _Traits, class _Allocator>
2960typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002961basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002962{
2963 size_type __sz = size();
2964 if (__pos > __sz)
2965 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002966 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002967 traits_type::copy(__s, data() + __pos, __rlen);
2968 return __rlen;
2969}
2970
2971template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002972inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002973basic_string<_CharT, _Traits, _Allocator>
2974basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
2975{
2976 return basic_string(*this, __pos, __n, __alloc());
2977}
2978
2979template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002980inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002981void
2982basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00002983#if _LIBCPP_STD_VER >= 14
2984 _NOEXCEPT
2985#else
2986 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2987 __is_nothrow_swappable<allocator_type>::value)
2988#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002989{
Howard Hinnant499cea12013-08-23 17:37:05 +00002990#if _LIBCPP_DEBUG_LEVEL >= 2
2991 if (!__is_long())
2992 __get_db()->__invalidate_all(this);
2993 if (!__str.__is_long())
2994 __get_db()->__invalidate_all(&__str);
2995 __get_db()->swap(this, &__str);
2996#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00002997 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow7d914d12015-07-13 20:04:56 +00002998 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002999}
3000
3001// find
3002
3003template <class _Traits>
3004struct _LIBCPP_HIDDEN __traits_eq
3005{
3006 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00003007 _LIBCPP_INLINE_VISIBILITY
3008 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3009 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003010};
3011
3012template<class _CharT, class _Traits, class _Allocator>
3013typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003014basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003015 size_type __pos,
3016 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003017{
Alp Tokerec34c482014-05-15 11:27:39 +00003018 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003019 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003020 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003021}
3022
3023template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003024inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003025typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003026basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3027 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003028{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003029 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003030 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003031}
3032
3033template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003034inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003035typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003036basic_string<_CharT, _Traits, _Allocator>::find(__self_view __sv,
3037 size_type __pos) const _NOEXCEPT
3038{
3039 return __str_find<value_type, size_type, traits_type, npos>
3040 (data(), size(), __sv.data(), __pos, __sv.size());
3041}
3042
3043template<class _CharT, class _Traits, class _Allocator>
3044inline _LIBCPP_INLINE_VISIBILITY
3045typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003046basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003047 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003048{
Alp Tokerec34c482014-05-15 11:27:39 +00003049 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003050 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003051 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003052}
3053
3054template<class _CharT, class _Traits, class _Allocator>
3055typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003056basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3057 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003058{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003059 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003060 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003061}
3062
3063// rfind
3064
3065template<class _CharT, class _Traits, class _Allocator>
3066typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003067basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003068 size_type __pos,
3069 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003070{
Alp Tokerec34c482014-05-15 11:27:39 +00003071 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003072 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003073 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003074}
3075
3076template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003077inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003078typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003079basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3080 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003081{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003082 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003083 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003084}
3085
3086template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003087inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003088typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003089basic_string<_CharT, _Traits, _Allocator>::rfind(__self_view __sv,
3090 size_type __pos) const _NOEXCEPT
3091{
3092 return __str_rfind<value_type, size_type, traits_type, npos>
3093 (data(), size(), __sv.data(), __pos, __sv.size());
3094}
3095
3096template<class _CharT, class _Traits, class _Allocator>
3097inline _LIBCPP_INLINE_VISIBILITY
3098typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003099basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003100 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003101{
Alp Tokerec34c482014-05-15 11:27:39 +00003102 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003103 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003104 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003105}
3106
3107template<class _CharT, class _Traits, class _Allocator>
3108typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003109basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3110 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003111{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003112 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003113 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003114}
3115
3116// find_first_of
3117
3118template<class _CharT, class _Traits, class _Allocator>
3119typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003120basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003121 size_type __pos,
3122 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003123{
Alp Tokerec34c482014-05-15 11:27:39 +00003124 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003125 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003126 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003127}
3128
3129template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003130inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003131typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003132basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3133 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003134{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003135 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003136 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003137}
3138
3139template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003140inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003141typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003142basic_string<_CharT, _Traits, _Allocator>::find_first_of(__self_view __sv,
3143 size_type __pos) const _NOEXCEPT
3144{
3145 return __str_find_first_of<value_type, size_type, traits_type, npos>
3146 (data(), size(), __sv.data(), __pos, __sv.size());
3147}
3148
3149template<class _CharT, class _Traits, class _Allocator>
3150inline _LIBCPP_INLINE_VISIBILITY
3151typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003152basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003153 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003154{
Alp Tokerec34c482014-05-15 11:27:39 +00003155 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003156 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003157 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003158}
3159
3160template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003161inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003162typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003163basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3164 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003165{
3166 return find(__c, __pos);
3167}
3168
3169// find_last_of
3170
3171template<class _CharT, class _Traits, class _Allocator>
3172typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003173basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003174 size_type __pos,
3175 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003176{
Alp Tokerec34c482014-05-15 11:27:39 +00003177 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003178 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003179 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003180}
3181
3182template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003183inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003184typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003185basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3186 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003187{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003188 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003189 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003190}
3191
3192template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003193inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003194typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003195basic_string<_CharT, _Traits, _Allocator>::find_last_of(__self_view __sv,
3196 size_type __pos) const _NOEXCEPT
3197{
3198 return __str_find_last_of<value_type, size_type, traits_type, npos>
3199 (data(), size(), __sv.data(), __pos, __sv.size());
3200}
3201
3202template<class _CharT, class _Traits, class _Allocator>
3203inline _LIBCPP_INLINE_VISIBILITY
3204typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003205basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003206 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003207{
Alp Tokerec34c482014-05-15 11:27:39 +00003208 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003209 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003210 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003211}
3212
3213template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003214inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003215typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003216basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3217 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003218{
3219 return rfind(__c, __pos);
3220}
3221
3222// find_first_not_of
3223
3224template<class _CharT, class _Traits, class _Allocator>
3225typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003226basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003227 size_type __pos,
3228 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003229{
Alp Tokerec34c482014-05-15 11:27:39 +00003230 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003231 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003232 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003233}
3234
3235template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003236inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003237typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003238basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3239 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003240{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003241 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003242 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003243}
3244
3245template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003246inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003247typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003248basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(__self_view __sv,
3249 size_type __pos) const _NOEXCEPT
3250{
3251 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3252 (data(), size(), __sv.data(), __pos, __sv.size());
3253}
3254
3255template<class _CharT, class _Traits, class _Allocator>
3256inline _LIBCPP_INLINE_VISIBILITY
3257typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003258basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003259 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003260{
Alp Tokerec34c482014-05-15 11:27:39 +00003261 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003262 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003263 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003264}
3265
3266template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003267inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003268typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003269basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3270 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003271{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003272 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003273 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003274}
3275
3276// find_last_not_of
3277
3278template<class _CharT, class _Traits, class _Allocator>
3279typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003280basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003281 size_type __pos,
3282 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003283{
Alp Tokerec34c482014-05-15 11:27:39 +00003284 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003285 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003286 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003287}
3288
3289template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003290inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003291typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003292basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3293 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003294{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003295 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003296 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003297}
3298
3299template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003300inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003301typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003302basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(__self_view __sv,
3303 size_type __pos) const _NOEXCEPT
3304{
3305 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3306 (data(), size(), __sv.data(), __pos, __sv.size());
3307}
3308
3309template<class _CharT, class _Traits, class _Allocator>
3310inline _LIBCPP_INLINE_VISIBILITY
3311typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003312basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003313 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003314{
Alp Tokerec34c482014-05-15 11:27:39 +00003315 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003316 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003317 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003318}
3319
3320template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003321inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003322typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003323basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3324 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003325{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003326 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003327 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003328}
3329
3330// compare
3331
3332template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003333inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003334int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003335basic_string<_CharT, _Traits, _Allocator>::compare(__self_view __sv) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003336{
Howard Hinnantfa06d752011-07-24 21:45:06 +00003337 size_t __lhs_sz = size();
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003338 size_t __rhs_sz = __sv.size();
3339 int __result = traits_type::compare(data(), __sv.data(),
Howard Hinnantfa06d752011-07-24 21:45:06 +00003340 _VSTD::min(__lhs_sz, __rhs_sz));
3341 if (__result != 0)
3342 return __result;
3343 if (__lhs_sz < __rhs_sz)
3344 return -1;
3345 if (__lhs_sz > __rhs_sz)
3346 return 1;
3347 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003348}
3349
3350template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003351inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003352int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003353basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003354{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003355 return compare(__self_view(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003356}
3357
3358template <class _CharT, class _Traits, class _Allocator>
3359int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003360basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3361 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003362 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003363 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003364{
Alp Tokerec34c482014-05-15 11:27:39 +00003365 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003366 size_type __sz = size();
3367 if (__pos1 > __sz || __n2 == npos)
3368 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003369 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3370 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003371 if (__r == 0)
3372 {
3373 if (__rlen < __n2)
3374 __r = -1;
3375 else if (__rlen > __n2)
3376 __r = 1;
3377 }
3378 return __r;
3379}
3380
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003381template <class _CharT, class _Traits, class _Allocator>
3382inline _LIBCPP_INLINE_VISIBILITY
3383int
3384basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3385 size_type __n1,
3386 __self_view __sv) const
3387{
3388 return compare(__pos1, __n1, __sv.data(), __sv.size());
3389}
3390
3391template <class _CharT, class _Traits, class _Allocator>
3392inline _LIBCPP_INLINE_VISIBILITY
3393int
3394basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3395 size_type __n1,
3396 const basic_string& __str) const
3397{
3398 return compare(__pos1, __n1, __str.data(), __str.size());
3399}
3400
3401template <class _CharT, class _Traits, class _Allocator>
Marshall Clow6ac8de02016-09-24 22:45:42 +00003402template <class _Tp>
3403typename enable_if
3404<
3405 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3406 int
3407>::type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003408basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3409 size_type __n1,
Marshall Clow6ac8de02016-09-24 22:45:42 +00003410 const _Tp& __t,
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003411 size_type __pos2,
3412 size_type __n2) const
3413{
Marshall Clow6ac8de02016-09-24 22:45:42 +00003414 __self_view __sv = __t;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003415 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3416}
3417
3418template <class _CharT, class _Traits, class _Allocator>
3419int
3420basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3421 size_type __n1,
3422 const basic_string& __str,
3423 size_type __pos2,
3424 size_type __n2) const
3425{
3426 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3427}
3428
3429template <class _CharT, class _Traits, class _Allocator>
3430int
3431basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3432{
3433 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3434 return compare(0, npos, __s, traits_type::length(__s));
3435}
3436
3437template <class _CharT, class _Traits, class _Allocator>
3438int
3439basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3440 size_type __n1,
3441 const value_type* __s) const
3442{
3443 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3444 return compare(__pos1, __n1, __s, traits_type::length(__s));
3445}
3446
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003447// __invariants
3448
3449template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003450inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003451bool
3452basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3453{
3454 if (size() > capacity())
3455 return false;
3456 if (capacity() < __min_cap - 1)
3457 return false;
3458 if (data() == 0)
3459 return false;
3460 if (data()[size()] != value_type(0))
3461 return false;
3462 return true;
3463}
3464
3465// operator==
3466
3467template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003468inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003469bool
3470operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003471 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003472{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003473 size_t __lhs_sz = __lhs.size();
3474 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3475 __rhs.data(),
3476 __lhs_sz) == 0;
3477}
3478
3479template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003480inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:13 +00003481bool
3482operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3483 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3484{
3485 size_t __lhs_sz = __lhs.size();
3486 if (__lhs_sz != __rhs.size())
3487 return false;
3488 const char* __lp = __lhs.data();
3489 const char* __rp = __rhs.data();
3490 if (__lhs.__is_long())
3491 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3492 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3493 if (*__lp != *__rp)
3494 return false;
3495 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003496}
3497
3498template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003499inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003500bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003501operator==(const _CharT* __lhs,
3502 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003503{
Eric Fiselier4f241822015-08-28 03:02:37 +00003504 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3505 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3506 size_t __lhs_len = _Traits::length(__lhs);
3507 if (__lhs_len != __rhs.size()) return false;
3508 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003509}
3510
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003511template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003512inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003513bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003514operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3515 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003516{
Eric Fiselier4f241822015-08-28 03:02:37 +00003517 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3518 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3519 size_t __rhs_len = _Traits::length(__rhs);
3520 if (__rhs_len != __lhs.size()) return false;
3521 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003522}
3523
Howard Hinnant324bb032010-08-22 00:02:43 +00003524template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003525inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003526bool
3527operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003528 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003529{
3530 return !(__lhs == __rhs);
3531}
3532
3533template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003534inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003535bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003536operator!=(const _CharT* __lhs,
3537 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003538{
3539 return !(__lhs == __rhs);
3540}
3541
3542template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003543inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003544bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003545operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3546 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003547{
3548 return !(__lhs == __rhs);
3549}
3550
3551// operator<
3552
3553template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003554inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003555bool
3556operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003557 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003558{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003559 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003560}
3561
3562template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003563inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003564bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003565operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3566 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003567{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003568 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003569}
3570
3571template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003572inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003573bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003574operator< (const _CharT* __lhs,
3575 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003576{
3577 return __rhs.compare(__lhs) > 0;
3578}
3579
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003580// operator>
3581
3582template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003583inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003584bool
3585operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003586 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003587{
3588 return __rhs < __lhs;
3589}
3590
3591template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003592inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003593bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003594operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3595 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003596{
3597 return __rhs < __lhs;
3598}
3599
3600template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003601inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003602bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003603operator> (const _CharT* __lhs,
3604 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003605{
3606 return __rhs < __lhs;
3607}
3608
3609// operator<=
3610
3611template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003612inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003613bool
3614operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003615 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003616{
3617 return !(__rhs < __lhs);
3618}
3619
3620template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003621inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003622bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003623operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3624 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003625{
3626 return !(__rhs < __lhs);
3627}
3628
3629template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003630inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003631bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003632operator<=(const _CharT* __lhs,
3633 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003634{
3635 return !(__rhs < __lhs);
3636}
3637
3638// operator>=
3639
3640template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003641inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003642bool
3643operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003644 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003645{
3646 return !(__lhs < __rhs);
3647}
3648
3649template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003650inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003651bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003652operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3653 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003654{
3655 return !(__lhs < __rhs);
3656}
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 +00003660bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003661operator>=(const _CharT* __lhs,
3662 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003663{
3664 return !(__lhs < __rhs);
3665}
3666
3667// operator +
3668
3669template<class _CharT, class _Traits, class _Allocator>
3670basic_string<_CharT, _Traits, _Allocator>
3671operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3672 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3673{
3674 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3675 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3676 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3677 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3678 __r.append(__rhs.data(), __rhs_sz);
3679 return __r;
3680}
3681
3682template<class _CharT, class _Traits, class _Allocator>
3683basic_string<_CharT, _Traits, _Allocator>
3684operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3685{
3686 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3687 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
3688 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3689 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
3690 __r.append(__rhs.data(), __rhs_sz);
3691 return __r;
3692}
3693
3694template<class _CharT, class _Traits, class _Allocator>
3695basic_string<_CharT, _Traits, _Allocator>
3696operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3697{
3698 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3699 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3700 __r.__init(&__lhs, 1, 1 + __rhs_sz);
3701 __r.append(__rhs.data(), __rhs_sz);
3702 return __r;
3703}
3704
3705template<class _CharT, class _Traits, class _Allocator>
3706basic_string<_CharT, _Traits, _Allocator>
3707operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
3708{
3709 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3710 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3711 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
3712 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3713 __r.append(__rhs, __rhs_sz);
3714 return __r;
3715}
3716
3717template<class _CharT, class _Traits, class _Allocator>
3718basic_string<_CharT, _Traits, _Allocator>
3719operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
3720{
3721 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3722 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3723 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
3724 __r.push_back(__rhs);
3725 return __r;
3726}
3727
Howard Hinnant73d21a42010-09-04 23:28:19 +00003728#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003729
3730template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003731inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003732basic_string<_CharT, _Traits, _Allocator>
3733operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3734{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003735 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003736}
3737
3738template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003739inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003740basic_string<_CharT, _Traits, _Allocator>
3741operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3742{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003743 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003744}
3745
3746template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003747inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003748basic_string<_CharT, _Traits, _Allocator>
3749operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3750{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003751 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003752}
3753
3754template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003755inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003756basic_string<_CharT, _Traits, _Allocator>
3757operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3758{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003759 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003760}
3761
3762template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003763inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003764basic_string<_CharT, _Traits, _Allocator>
3765operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3766{
3767 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003768 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003769}
3770
3771template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003772inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003773basic_string<_CharT, _Traits, _Allocator>
3774operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
3775{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003776 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003777}
3778
3779template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003780inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003781basic_string<_CharT, _Traits, _Allocator>
3782operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
3783{
3784 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003785 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003786}
3787
Howard Hinnant73d21a42010-09-04 23:28:19 +00003788#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003789
3790// swap
3791
3792template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003793inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003794void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003795swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00003796 basic_string<_CharT, _Traits, _Allocator>& __rhs)
3797 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003798{
3799 __lhs.swap(__rhs);
3800}
3801
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003802#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
3803
3804typedef basic_string<char16_t> u16string;
3805typedef basic_string<char32_t> u32string;
3806
Howard Hinnant324bb032010-08-22 00:02:43 +00003807#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003808
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003809_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
3810_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
3811_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
3812_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
3813_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003814
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003815_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
3816_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
3817_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003818
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003819_LIBCPP_FUNC_VIS string to_string(int __val);
3820_LIBCPP_FUNC_VIS string to_string(unsigned __val);
3821_LIBCPP_FUNC_VIS string to_string(long __val);
3822_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
3823_LIBCPP_FUNC_VIS string to_string(long long __val);
3824_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
3825_LIBCPP_FUNC_VIS string to_string(float __val);
3826_LIBCPP_FUNC_VIS string to_string(double __val);
3827_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003828
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003829_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
3830_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
3831_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
3832_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
3833_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003834
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003835_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
3836_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
3837_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003838
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003839_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
3840_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
3841_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
3842_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
3843_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
3844_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
3845_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
3846_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
3847_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003848
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003849template<class _CharT, class _Traits, class _Allocator>
3850 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
3851 basic_string<_CharT, _Traits, _Allocator>::npos;
3852
3853template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003854struct _LIBCPP_TYPE_VIS_ONLY hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003855 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
3856{
3857 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00003858 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003859};
3860
3861template<class _CharT, class _Traits, class _Allocator>
3862size_t
3863hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00003864 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003865{
Sean Huntaffd9e52011-07-29 23:31:56 +00003866 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003867}
3868
Howard Hinnant464aa5c2011-07-18 15:51:59 +00003869template<class _CharT, class _Traits, class _Allocator>
3870basic_ostream<_CharT, _Traits>&
3871operator<<(basic_ostream<_CharT, _Traits>& __os,
3872 const basic_string<_CharT, _Traits, _Allocator>& __str);
3873
3874template<class _CharT, class _Traits, class _Allocator>
3875basic_istream<_CharT, _Traits>&
3876operator>>(basic_istream<_CharT, _Traits>& __is,
3877 basic_string<_CharT, _Traits, _Allocator>& __str);
3878
3879template<class _CharT, class _Traits, class _Allocator>
3880basic_istream<_CharT, _Traits>&
3881getline(basic_istream<_CharT, _Traits>& __is,
3882 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3883
3884template<class _CharT, class _Traits, class _Allocator>
3885inline _LIBCPP_INLINE_VISIBILITY
3886basic_istream<_CharT, _Traits>&
3887getline(basic_istream<_CharT, _Traits>& __is,
3888 basic_string<_CharT, _Traits, _Allocator>& __str);
3889
3890#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3891
3892template<class _CharT, class _Traits, class _Allocator>
3893inline _LIBCPP_INLINE_VISIBILITY
3894basic_istream<_CharT, _Traits>&
3895getline(basic_istream<_CharT, _Traits>&& __is,
3896 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3897
3898template<class _CharT, class _Traits, class _Allocator>
3899inline _LIBCPP_INLINE_VISIBILITY
3900basic_istream<_CharT, _Traits>&
3901getline(basic_istream<_CharT, _Traits>&& __is,
3902 basic_string<_CharT, _Traits, _Allocator>& __str);
3903
3904#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3905
Howard Hinnant499cea12013-08-23 17:37:05 +00003906#if _LIBCPP_DEBUG_LEVEL >= 2
3907
3908template<class _CharT, class _Traits, class _Allocator>
3909bool
3910basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
3911{
3912 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
3913 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
3914}
3915
3916template<class _CharT, class _Traits, class _Allocator>
3917bool
3918basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
3919{
3920 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
3921 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
3922}
3923
3924template<class _CharT, class _Traits, class _Allocator>
3925bool
3926basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
3927{
3928 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
3929 return this->data() <= __p && __p <= this->data() + this->size();
3930}
3931
3932template<class _CharT, class _Traits, class _Allocator>
3933bool
3934basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
3935{
3936 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
3937 return this->data() <= __p && __p < this->data() + this->size();
3938}
3939
3940#endif // _LIBCPP_DEBUG_LEVEL >= 2
3941
Marshall Clow15234322013-07-23 17:05:24 +00003942#if _LIBCPP_STD_VER > 11
3943// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:32 +00003944inline namespace literals
Marshall Clow15234322013-07-23 17:05:24 +00003945{
3946 inline namespace string_literals
3947 {
Howard Hinnantab61b2c2013-08-07 19:39:48 +00003948 inline _LIBCPP_INLINE_VISIBILITY
3949 basic_string<char> operator "" s( const char *__str, size_t __len )
3950 {
3951 return basic_string<char> (__str, __len);
3952 }
Marshall Clow15234322013-07-23 17:05:24 +00003953
Howard Hinnantab61b2c2013-08-07 19:39:48 +00003954 inline _LIBCPP_INLINE_VISIBILITY
3955 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
3956 {
3957 return basic_string<wchar_t> (__str, __len);
3958 }
Marshall Clow15234322013-07-23 17:05:24 +00003959
Howard Hinnantab61b2c2013-08-07 19:39:48 +00003960 inline _LIBCPP_INLINE_VISIBILITY
3961 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
3962 {
3963 return basic_string<char16_t> (__str, __len);
3964 }
Marshall Clow15234322013-07-23 17:05:24 +00003965
Howard Hinnantab61b2c2013-08-07 19:39:48 +00003966 inline _LIBCPP_INLINE_VISIBILITY
3967 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
3968 {
3969 return basic_string<char32_t> (__str, __len);
3970 }
Marshall Clow15234322013-07-23 17:05:24 +00003971 }
3972}
3973#endif
3974
Eric Fiselier833d6442016-09-15 22:27:07 +00003975_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>)
3976_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>)
Howard Hinnant499cea12013-08-23 17:37:05 +00003977_LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003978
3979_LIBCPP_END_NAMESPACE_STD
3980
3981#endif // _LIBCPP_STRING