blob: 8d947c630695e65d1a56bc7557efb1048d799fc8 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- string -----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_STRING
12#define _LIBCPP_STRING
13
14/*
15 string synopsis
16
17namespace std
18{
19
20template <class stateT>
21class fpos
22{
23private:
24 stateT st;
25public:
26 fpos(streamoff = streamoff());
27
28 operator streamoff() const;
29
30 stateT state() const;
31 void state(stateT);
32
33 fpos& operator+=(streamoff);
34 fpos operator+ (streamoff) const;
35 fpos& operator-=(streamoff);
36 fpos operator- (streamoff) const;
37};
38
39template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y);
40
41template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y);
42template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y);
43
44template <class charT>
45struct char_traits
46{
47 typedef charT char_type;
48 typedef ... int_type;
49 typedef streamoff off_type;
50 typedef streampos pos_type;
51 typedef mbstate_t state_type;
52
Howard Hinnanta6119a82011-05-29 19:57:12 +000053 static void assign(char_type& c1, const char_type& c2) noexcept;
Howard Hinnant03d71812012-07-20 19:09:12 +000054 static constexpr bool eq(char_type c1, char_type c2) noexcept;
55 static constexpr bool lt(char_type c1, char_type c2) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056
57 static int compare(const char_type* s1, const char_type* s2, size_t n);
58 static size_t length(const char_type* s);
59 static const char_type* find(const char_type* s, size_t n, const char_type& a);
60 static char_type* move(char_type* s1, const char_type* s2, size_t n);
61 static char_type* copy(char_type* s1, const char_type* s2, size_t n);
62 static char_type* assign(char_type* s, size_t n, char_type a);
63
Howard Hinnant03d71812012-07-20 19:09:12 +000064 static constexpr int_type not_eof(int_type c) noexcept;
65 static constexpr char_type to_char_type(int_type c) noexcept;
66 static constexpr int_type to_int_type(char_type c) noexcept;
67 static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept;
68 static constexpr int_type eof() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000069};
70
71template <> struct char_traits<char>;
72template <> struct char_traits<wchar_t>;
73
Howard Hinnant324bb032010-08-22 00:02:43 +000074template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000075class basic_string
76{
Howard Hinnant324bb032010-08-22 00:02:43 +000077public:
78// types:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000079 typedef traits traits_type;
80 typedef typename traits_type::char_type value_type;
81 typedef Allocator allocator_type;
82 typedef typename allocator_type::size_type size_type;
83 typedef typename allocator_type::difference_type difference_type;
84 typedef typename allocator_type::reference reference;
85 typedef typename allocator_type::const_reference const_reference;
86 typedef typename allocator_type::pointer pointer;
87 typedef typename allocator_type::const_pointer const_pointer;
88 typedef implementation-defined iterator;
89 typedef implementation-defined const_iterator;
90 typedef std::reverse_iterator<iterator> reverse_iterator;
91 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
92
93 static const size_type npos = -1;
94
Howard Hinnant53f7d4c2011-06-03 18:40:47 +000095 basic_string()
96 noexcept(is_nothrow_default_constructible<allocator_type>::value);
97 explicit basic_string(const allocator_type& a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000098 basic_string(const basic_string& str);
Howard Hinnant53f7d4c2011-06-03 18:40:47 +000099 basic_string(basic_string&& str)
100 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000101 basic_string(const basic_string& str, size_type pos,
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000102 const allocator_type& a = allocator_type());
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000103 basic_string(const basic_string& str, size_type pos, size_type n,
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000104 const Allocator& a = Allocator());
105 explicit basic_string(const basic_string_view<charT, traits> sv, const Allocator& a = Allocator());
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000106 basic_string(const value_type* s, const allocator_type& a = allocator_type());
107 basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000108 basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
109 template<class InputIterator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000110 basic_string(InputIterator begin, InputIterator end,
111 const allocator_type& a = allocator_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000112 basic_string(initializer_list<value_type>, const Allocator& = Allocator());
113 basic_string(const basic_string&, const Allocator&);
114 basic_string(basic_string&&, const Allocator&);
115
116 ~basic_string();
117
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000118 operator basic_string_view<charT, traits>() const noexcept;
119
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000120 basic_string& operator=(const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000121 basic_string& operator=(basic_string_view<charT, traits> sv);
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000122 basic_string& operator=(basic_string&& str)
123 noexcept(
Marshall Clowaf961ed2015-08-18 18:57:00 +0000124 allocator_type::propagate_on_container_move_assignment::value ||
125 allocator_type::is_always_equal::value ); // C++17
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000126 basic_string& operator=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000127 basic_string& operator=(value_type c);
128 basic_string& operator=(initializer_list<value_type>);
129
Howard Hinnanta6119a82011-05-29 19:57:12 +0000130 iterator begin() noexcept;
131 const_iterator begin() const noexcept;
132 iterator end() noexcept;
133 const_iterator end() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000134
Howard Hinnanta6119a82011-05-29 19:57:12 +0000135 reverse_iterator rbegin() noexcept;
136 const_reverse_iterator rbegin() const noexcept;
137 reverse_iterator rend() noexcept;
138 const_reverse_iterator rend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000139
Howard Hinnanta6119a82011-05-29 19:57:12 +0000140 const_iterator cbegin() const noexcept;
141 const_iterator cend() const noexcept;
142 const_reverse_iterator crbegin() const noexcept;
143 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000144
Howard Hinnanta6119a82011-05-29 19:57:12 +0000145 size_type size() const noexcept;
146 size_type length() const noexcept;
147 size_type max_size() const noexcept;
148 size_type capacity() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000149
150 void resize(size_type n, value_type c);
151 void resize(size_type n);
152
153 void reserve(size_type res_arg = 0);
154 void shrink_to_fit();
Howard Hinnanta6119a82011-05-29 19:57:12 +0000155 void clear() noexcept;
156 bool empty() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000157
158 const_reference operator[](size_type pos) const;
159 reference operator[](size_type pos);
160
161 const_reference at(size_type n) const;
162 reference at(size_type n);
163
164 basic_string& operator+=(const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000165 basic_string& operator+=(basic_string_view<charT, traits> sv);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000166 basic_string& operator+=(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000167 basic_string& operator+=(value_type c);
168 basic_string& operator+=(initializer_list<value_type>);
169
170 basic_string& append(const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000171 basic_string& append(basic_string_view<charT, traits> sv);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000172 basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000173 basic_string& append(basic_string_view<charT, traits> sv, size_type pos, size_type n=npos); //C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000174 basic_string& append(const value_type* s, size_type n);
175 basic_string& append(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000176 basic_string& append(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000177 template<class InputIterator>
178 basic_string& append(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000179 basic_string& append(initializer_list<value_type>);
180
181 void push_back(value_type c);
182 void pop_back();
183 reference front();
184 const_reference front() const;
185 reference back();
186 const_reference back() const;
187
188 basic_string& assign(const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000189 basic_string& assign(basic_string_view<charT, traits> sv);
Howard Hinnanta6119a82011-05-29 19:57:12 +0000190 basic_string& assign(basic_string&& str);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000191 basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000192 basic_string& assign(basic_string_view<charT, traits> sv, size_type pos, size_type n=npos); // C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000193 basic_string& assign(const value_type* s, size_type n);
194 basic_string& assign(const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000195 basic_string& assign(size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000196 template<class InputIterator>
197 basic_string& assign(InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000198 basic_string& assign(initializer_list<value_type>);
199
200 basic_string& insert(size_type pos1, const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000201 basic_string& insert(size_type pos1, basic_string_view<charT, traits> sv);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000202 basic_string& insert(size_type pos1, const basic_string& str,
203 size_type pos2, size_type n);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000204 basic_string& insert(size_type pos1, basic_string_view<charT, traits> sv,
205 size_type pos2, size_type n);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000206 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000207 basic_string& insert(size_type pos, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000208 basic_string& insert(size_type pos, size_type n, value_type c);
209 iterator insert(const_iterator p, value_type c);
210 iterator insert(const_iterator p, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000211 template<class InputIterator>
212 iterator insert(const_iterator p, InputIterator first, InputIterator last);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000213 iterator insert(const_iterator p, initializer_list<value_type>);
214
215 basic_string& erase(size_type pos = 0, size_type n = npos);
216 iterator erase(const_iterator position);
217 iterator erase(const_iterator first, const_iterator last);
218
219 basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000220 basic_string& replace(size_type pos1, size_type n1, basic_string_view<charT, traits> sv);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000221 basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000222 size_type pos2, size_type n2=npos); // C++14
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000223 basic_string& replace(size_type pos1, size_type n1, basic_string_view<charT, traits> sv,
224 size_type pos2, size_type n2=npos); // C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000225 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
226 basic_string& replace(size_type pos, size_type n1, const value_type* s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000227 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000228 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000229 basic_string& replace(const_iterator i1, const_iterator i2, basic_string_view<charT, traits> sv);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000230 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
231 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000232 basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000233 template<class InputIterator>
Howard Hinnant7b2cb482010-11-17 21:11:40 +0000234 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
235 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000236
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000237 size_type copy(value_type* s, size_type n, size_type pos = 0) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000238 basic_string substr(size_type pos = 0, size_type n = npos) const;
239
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000240 void swap(basic_string& str)
Marshall Clow7d914d12015-07-13 20:04:56 +0000241 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
242 allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000243
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000244 const value_type* c_str() const noexcept;
245 const value_type* data() const noexcept;
Marshall Clowf532a702016-03-08 15:44:30 +0000246 value_type* data() noexcept; // C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000247
Howard Hinnanta6119a82011-05-29 19:57:12 +0000248 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000249
Howard Hinnanta6119a82011-05-29 19:57:12 +0000250 size_type find(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000251 size_type find(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000252 size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
253 size_type find(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000254 size_type find(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000255
Howard Hinnanta6119a82011-05-29 19:57:12 +0000256 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000257 size_type ffind(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000258 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
259 size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000260 size_type rfind(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000261
Howard Hinnanta6119a82011-05-29 19:57:12 +0000262 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000263 size_type find_first_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000264 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
265 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000266 size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000267
Howard Hinnanta6119a82011-05-29 19:57:12 +0000268 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000269 size_type find_last_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000270 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
271 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000272 size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000273
Howard Hinnanta6119a82011-05-29 19:57:12 +0000274 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000275 size_type find_first_not_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000276 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
277 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000278 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000279
Howard Hinnanta6119a82011-05-29 19:57:12 +0000280 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000281 size_type find_last_not_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000282 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
283 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
Howard Hinnanta6119a82011-05-29 19:57:12 +0000284 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000285
Howard Hinnanta6119a82011-05-29 19:57:12 +0000286 int compare(const basic_string& str) const noexcept;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000287 int compare(basic_string_view<charT, traits> sv) const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000288 int compare(size_type pos1, size_type n1, const basic_string& str) const;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000289 int compare(size_type pos1, size_type n1, basic_string_view<charT, traits> sv) const;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000290 int compare(size_type pos1, size_type n1, const basic_string& str,
Marshall Clowa93b5e22014-03-04 19:17:19 +0000291 size_type pos2, size_type n2=npos) const; // C++14
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000292 int compare(size_type pos1, size_type n1, basic_string_view<charT, traits> sv,
293 size_type pos2, size_type n2=npos) const; // C++14
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000294 int compare(const value_type* s) const noexcept;
295 int compare(size_type pos1, size_type n1, const value_type* s) const;
296 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000297
298 bool __invariants() const;
299};
300
301template<class charT, class traits, class Allocator>
302basic_string<charT, traits, Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000303operator+(const basic_string<charT, traits, Allocator>& lhs,
304 const basic_string<charT, traits, Allocator>& rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000305
306template<class charT, class traits, class Allocator>
307basic_string<charT, traits, Allocator>
308operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
309
310template<class charT, class traits, class Allocator>
311basic_string<charT, traits, Allocator>
312operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
313
314template<class charT, class traits, class Allocator>
315basic_string<charT, traits, Allocator>
316operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
317
318template<class charT, class traits, class Allocator>
319basic_string<charT, traits, Allocator>
320operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
321
322template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000323bool operator==(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000324 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000325
326template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000327bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000328
329template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000330bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000331
Howard Hinnant324bb032010-08-22 00:02:43 +0000332template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000333bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000334 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000335
336template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000337bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000338
339template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000340bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000341
342template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000343bool operator< (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000344 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000345
346template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000347bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000348
349template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000350bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000351
352template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000353bool operator> (const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000354 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000355
356template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000357bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000358
359template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000360bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000361
362template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000363bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000364 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000365
366template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000367bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000368
369template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000370bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000371
372template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000373bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +0000374 const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000375
376template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000377bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000378
379template<class charT, class traits, class Allocator>
Howard Hinnanta6119a82011-05-29 19:57:12 +0000380bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000381
382template<class charT, class traits, class Allocator>
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000383void swap(basic_string<charT, traits, Allocator>& lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000384 basic_string<charT, traits, Allocator>& rhs)
385 noexcept(noexcept(lhs.swap(rhs)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000386
387template<class charT, class traits, class Allocator>
388basic_istream<charT, traits>&
389operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
390
391template<class charT, class traits, class Allocator>
392basic_ostream<charT, traits>&
393operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
394
395template<class charT, class traits, class Allocator>
Howard Hinnant324bb032010-08-22 00:02:43 +0000396basic_istream<charT, traits>&
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000397getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
398 charT delim);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000399
400template<class charT, class traits, class Allocator>
401basic_istream<charT, traits>&
402getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
403
404typedef basic_string<char> string;
405typedef basic_string<wchar_t> wstring;
Howard Hinnanta6a062d2010-06-02 18:20:39 +0000406typedef basic_string<char16_t> u16string;
407typedef basic_string<char32_t> u32string;
408
409int stoi (const string& str, size_t* idx = 0, int base = 10);
410long stol (const string& str, size_t* idx = 0, int base = 10);
411unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
412long long stoll (const string& str, size_t* idx = 0, int base = 10);
413unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
414
415float stof (const string& str, size_t* idx = 0);
416double stod (const string& str, size_t* idx = 0);
417long double stold(const string& str, size_t* idx = 0);
418
419string to_string(int val);
420string to_string(unsigned val);
421string to_string(long val);
422string to_string(unsigned long val);
423string to_string(long long val);
424string to_string(unsigned long long val);
425string to_string(float val);
426string to_string(double val);
427string to_string(long double val);
428
429int stoi (const wstring& str, size_t* idx = 0, int base = 10);
430long stol (const wstring& str, size_t* idx = 0, int base = 10);
431unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
432long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
433unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
434
435float stof (const wstring& str, size_t* idx = 0);
436double stod (const wstring& str, size_t* idx = 0);
437long double stold(const wstring& str, size_t* idx = 0);
438
439wstring to_wstring(int val);
440wstring to_wstring(unsigned val);
441wstring to_wstring(long val);
442wstring to_wstring(unsigned long val);
443wstring to_wstring(long long val);
444wstring to_wstring(unsigned long long val);
445wstring to_wstring(float val);
446wstring to_wstring(double val);
447wstring to_wstring(long double val);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000448
449template <> struct hash<string>;
450template <> struct hash<u16string>;
451template <> struct hash<u32string>;
452template <> struct hash<wstring>;
453
Marshall Clow15234322013-07-23 17:05:24 +0000454basic_string<char> operator "" s( const char *str, size_t len ); // C++14
455basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
456basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
457basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
458
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000459} // std
460
461*/
462
463#include <__config>
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000464#include <string_view>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000465#include <iosfwd>
466#include <cstring>
Howard Hinnantadff4892010-05-24 17:49:41 +0000467#include <cstdio> // For EOF.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000468#include <cwchar>
469#include <algorithm>
470#include <iterator>
471#include <utility>
472#include <memory>
473#include <stdexcept>
474#include <type_traits>
475#include <initializer_list>
476#include <__functional_base>
477#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
478#include <cstdint>
479#endif
Howard Hinnant499cea12013-08-23 17:37:05 +0000480#if defined(_LIBCPP_NO_EXCEPTIONS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000481#include <cassert>
482#endif
483
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:
559 void __throw_length_error() const;
560 void __throw_out_of_range() const;
561};
562
563template <bool __b>
564void
565__basic_string_common<__b>::__throw_length_error() const
566{
567#ifndef _LIBCPP_NO_EXCEPTIONS
568 throw length_error("basic_string");
569#else
570 assert(!"basic_string length_error");
571#endif
572}
573
574template <bool __b>
575void
576__basic_string_common<__b>::__throw_out_of_range() const
577{
578#ifndef _LIBCPP_NO_EXCEPTIONS
579 throw out_of_range("basic_string");
580#else
581 assert(!"basic_string out_of_range");
582#endif
583}
584
Howard Hinnante9df0a52013-08-01 18:17:34 +0000585#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +0000586#pragma warning( push )
587#pragma warning( disable: 4231 )
Howard Hinnante9df0a52013-08-01 18:17:34 +0000588#endif // _LIBCPP_MSVC
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000589_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __basic_string_common<true>)
Howard Hinnante9df0a52013-08-01 18:17:34 +0000590#ifdef _LIBCPP_MSVC
Howard Hinnant78b68282011-10-22 20:59:45 +0000591#pragma warning( pop )
Howard Hinnante9df0a52013-08-01 18:17:34 +0000592#endif // _LIBCPP_MSVC
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000593
Marshall Clowdf9db312016-01-13 21:54:34 +0000594#ifdef _LIBCPP_NO_EXCEPTIONS
595template <class _Iter>
596struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
597#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
598template <class _Iter>
599struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
600#else
601template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
602struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
603 noexcept(++(declval<_Iter&>())) &&
604 is_nothrow_assignable<_Iter&, _Iter>::value &&
605 noexcept(declval<_Iter>() == declval<_Iter>()) &&
606 noexcept(*declval<_Iter>())
607)) {};
608
609template <class _Iter>
610struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
611#endif
612
613
614template <class _Iter>
615struct __libcpp_string_gets_noexcept_iterator
616 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
617
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000618#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000619
620template <class _CharT, size_t = sizeof(_CharT)>
621struct __padding
622{
623 unsigned char __xx[sizeof(_CharT)-1];
624};
625
626template <class _CharT>
627struct __padding<_CharT, 1>
628{
629};
630
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000631#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000632
Howard Hinnant324bb032010-08-22 00:02:43 +0000633template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000634class _LIBCPP_TYPE_VIS_ONLY basic_string
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000635 : private __basic_string_common<true>
636{
637public:
638 typedef basic_string __self;
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000639 typedef basic_string_view<_CharT, _Traits> __self_view;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000640 typedef _Traits traits_type;
641 typedef typename traits_type::char_type value_type;
642 typedef _Allocator allocator_type;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000643 typedef allocator_traits<allocator_type> __alloc_traits;
644 typedef typename __alloc_traits::size_type size_type;
645 typedef typename __alloc_traits::difference_type difference_type;
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000646 typedef value_type& reference;
647 typedef const value_type& const_reference;
Howard Hinnante32b5e22010-11-17 17:55:08 +0000648 typedef typename __alloc_traits::pointer pointer;
649 typedef typename __alloc_traits::const_pointer const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000650
Howard Hinnant499cea12013-08-23 17:37:05 +0000651 static_assert(is_pod<value_type>::value, "Character type of basic_string must be a POD");
652 static_assert((is_same<_CharT, value_type>::value),
653 "traits_type::char_type must be the same type as CharT");
654 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
655 "Allocator::value_type must be same type as value_type");
656#if defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000657 typedef pointer iterator;
658 typedef const_pointer const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000659#else // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000660 typedef __wrap_iter<pointer> iterator;
661 typedef __wrap_iter<const_pointer> const_iterator;
Howard Hinnant324bb032010-08-22 00:02:43 +0000662#endif // defined(_LIBCPP_RAW_ITERATORS)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000663 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
664 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000665
666private:
Howard Hinnant15467182013-04-30 21:44:48 +0000667
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000668#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000669
670 struct __long
671 {
672 pointer __data_;
673 size_type __size_;
674 size_type __cap_;
675 };
676
677#if _LIBCPP_BIG_ENDIAN
678 enum {__short_mask = 0x01};
679 enum {__long_mask = 0x1ul};
680#else // _LIBCPP_BIG_ENDIAN
681 enum {__short_mask = 0x80};
682 enum {__long_mask = ~(size_type(~0) >> 1)};
683#endif // _LIBCPP_BIG_ENDIAN
684
685 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
686 (sizeof(__long) - 1)/sizeof(value_type) : 2};
687
688 struct __short
689 {
690 value_type __data_[__min_cap];
691 struct
692 : __padding<value_type>
693 {
694 unsigned char __size_;
695 };
696 };
697
698#else
699
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000700 struct __long
701 {
702 size_type __cap_;
703 size_type __size_;
704 pointer __data_;
705 };
706
707#if _LIBCPP_BIG_ENDIAN
708 enum {__short_mask = 0x80};
709 enum {__long_mask = ~(size_type(~0) >> 1)};
Howard Hinnant324bb032010-08-22 00:02:43 +0000710#else // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000711 enum {__short_mask = 0x01};
Howard Hinnantec3773c2011-12-01 20:21:04 +0000712 enum {__long_mask = 0x1ul};
Howard Hinnant324bb032010-08-22 00:02:43 +0000713#endif // _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000714
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000715 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
716 (sizeof(__long) - 1)/sizeof(value_type) : 2};
717
718 struct __short
719 {
720 union
721 {
722 unsigned char __size_;
Howard Hinnant9c0df142012-10-30 19:06:59 +0000723 value_type __lx;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000724 };
725 value_type __data_[__min_cap];
726 };
727
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000728#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +0000729
Howard Hinnant499cea12013-08-23 17:37:05 +0000730 union __ulx{__long __lx; __short __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000731
Howard Hinnant499cea12013-08-23 17:37:05 +0000732 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000733
734 struct __raw
735 {
736 size_type __words[__n_words];
737 };
738
739 struct __rep
740 {
741 union
742 {
743 __long __l;
744 __short __s;
745 __raw __r;
746 };
747 };
748
749 __compressed_pair<__rep, allocator_type> __r_;
750
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000751public:
752 static const size_type npos = -1;
753
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000754 _LIBCPP_INLINE_VISIBILITY basic_string()
755 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000756
757 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
758#if _LIBCPP_STD_VER <= 14
759 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
760#else
761 _NOEXCEPT;
762#endif
763
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000764 basic_string(const basic_string& __str);
765 basic_string(const basic_string& __str, const allocator_type& __a);
Marshall Clow7b193f72015-06-03 19:56:43 +0000766
Howard Hinnant73d21a42010-09-04 23:28:19 +0000767#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9f193f22011-01-26 00:06:59 +0000768 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000769 basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +0000770#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000771 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
Marshall Clow7b193f72015-06-03 19:56:43 +0000772#else
773 _NOEXCEPT;
774#endif
775
Howard Hinnant9f193f22011-01-26 00:06:59 +0000776 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000777 basic_string(basic_string&& __str, const allocator_type& __a);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000778#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000779 _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000780 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000781 basic_string(const value_type* __s, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000782 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000783 basic_string(const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000784 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000785 basic_string(const value_type* __s, size_type __n, const allocator_type& __a);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000786 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000787 basic_string(size_type __n, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000788 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000789 basic_string(size_type __n, value_type __c, const allocator_type& __a);
Marshall Clowf4f7d8f2016-04-07 18:13:41 +0000790 basic_string(const basic_string& __str, size_type __pos, size_type __n,
791 const allocator_type& __a = allocator_type());
792 _LIBCPP_INLINE_VISIBILITY
793 basic_string(const basic_string& __str, size_type __pos,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000794 const allocator_type& __a = allocator_type());
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000795 _LIBCPP_INLINE_VISIBILITY explicit
796 basic_string(__self_view __sv);
797 _LIBCPP_INLINE_VISIBILITY
798 basic_string(__self_view __sv, const allocator_type& __a);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000799 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);
802 template<class _InputIterator>
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000803 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000804 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000805#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000806 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000807 basic_string(initializer_list<value_type> __il);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000808 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000809 basic_string(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000810#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000811
812 ~basic_string();
813
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000814 _LIBCPP_INLINE_VISIBILITY
815 operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
816
Howard Hinnante32b5e22010-11-17 17:55:08 +0000817 basic_string& operator=(const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000818 _LIBCPP_INLINE_VISIBILITY
819 basic_string& operator=(__self_view __sv) {return assign(__sv);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000820#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000821 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000822 basic_string& operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +0000823 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000824#endif
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000825 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000826 basic_string& operator=(value_type __c);
Howard Hinnante3e32912011-08-12 21:56:02 +0000827#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000828 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000829 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000830#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000831
Howard Hinnant499cea12013-08-23 17:37:05 +0000832#if _LIBCPP_DEBUG_LEVEL >= 2
833 _LIBCPP_INLINE_VISIBILITY
834 iterator begin() _NOEXCEPT
835 {return iterator(this, __get_pointer());}
836 _LIBCPP_INLINE_VISIBILITY
837 const_iterator begin() const _NOEXCEPT
838 {return const_iterator(this, __get_pointer());}
839 _LIBCPP_INLINE_VISIBILITY
840 iterator end() _NOEXCEPT
841 {return iterator(this, __get_pointer() + size());}
842 _LIBCPP_INLINE_VISIBILITY
843 const_iterator end() const _NOEXCEPT
844 {return const_iterator(this, __get_pointer() + size());}
845#else
Howard Hinnanta6119a82011-05-29 19:57:12 +0000846 _LIBCPP_INLINE_VISIBILITY
847 iterator begin() _NOEXCEPT
848 {return iterator(__get_pointer());}
849 _LIBCPP_INLINE_VISIBILITY
850 const_iterator begin() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000851 {return const_iterator(__get_pointer());}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000852 _LIBCPP_INLINE_VISIBILITY
853 iterator end() _NOEXCEPT
854 {return iterator(__get_pointer() + size());}
855 _LIBCPP_INLINE_VISIBILITY
856 const_iterator end() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000857 {return const_iterator(__get_pointer() + size());}
Howard Hinnant499cea12013-08-23 17:37:05 +0000858#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnanta6119a82011-05-29 19:57:12 +0000859 _LIBCPP_INLINE_VISIBILITY
860 reverse_iterator rbegin() _NOEXCEPT
861 {return reverse_iterator(end());}
862 _LIBCPP_INLINE_VISIBILITY
863 const_reverse_iterator rbegin() const _NOEXCEPT
864 {return const_reverse_iterator(end());}
865 _LIBCPP_INLINE_VISIBILITY
866 reverse_iterator rend() _NOEXCEPT
867 {return reverse_iterator(begin());}
868 _LIBCPP_INLINE_VISIBILITY
869 const_reverse_iterator rend() const _NOEXCEPT
870 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000871
Howard Hinnanta6119a82011-05-29 19:57:12 +0000872 _LIBCPP_INLINE_VISIBILITY
873 const_iterator cbegin() const _NOEXCEPT
874 {return begin();}
875 _LIBCPP_INLINE_VISIBILITY
876 const_iterator cend() const _NOEXCEPT
877 {return end();}
878 _LIBCPP_INLINE_VISIBILITY
879 const_reverse_iterator crbegin() const _NOEXCEPT
880 {return rbegin();}
881 _LIBCPP_INLINE_VISIBILITY
882 const_reverse_iterator crend() const _NOEXCEPT
883 {return rend();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000884
Howard Hinnanta6119a82011-05-29 19:57:12 +0000885 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000886 {return __is_long() ? __get_long_size() : __get_short_size();}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000887 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
888 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
889 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +0000890 {return (__is_long() ? __get_long_cap()
891 : static_cast<size_type>(__min_cap)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000892
893 void resize(size_type __n, value_type __c);
894 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
895
896 void reserve(size_type res_arg = 0);
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000897 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +0000898 void shrink_to_fit() _NOEXCEPT {reserve();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000899 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +0000900 void clear() _NOEXCEPT;
901 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000902
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000903 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
904 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000905
906 const_reference at(size_type __n) const;
907 reference at(size_type __n);
908
909 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000910 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(__self_view __sv) {return append(__sv);}
911 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000912 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +0000913#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000914 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
Howard Hinnante3e32912011-08-12 21:56:02 +0000915#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000916
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000917 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000918 basic_string& append(const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000919 _LIBCPP_INLINE_VISIBILITY
920 basic_string& append(__self_view __sv) { return append(__sv.data(), __sv.size()); }
Marshall Clowa93b5e22014-03-04 19:17:19 +0000921 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000922 _LIBCPP_INLINE_VISIBILITY
923 basic_string& append(__self_view __sv, size_type __pos, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000924 basic_string& append(const value_type* __s, size_type __n);
925 basic_string& append(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000926 basic_string& append(size_type __n, value_type __c);
927 template<class _InputIterator>
928 typename enable_if
929 <
Marshall Clowdf9db312016-01-13 21:54:34 +0000930 __is_exactly_input_iterator<_InputIterator>::value
931 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000932 basic_string&
933 >::type
934 append(_InputIterator __first, _InputIterator __last);
935 template<class _ForwardIterator>
936 typename enable_if
937 <
Marshall Clowdf9db312016-01-13 21:54:34 +0000938 __is_forward_iterator<_ForwardIterator>::value
939 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000940 basic_string&
941 >::type
942 append(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000943#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000944 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000945 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000946#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000947
948 void push_back(value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000949 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000950 void pop_back();
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000951 _LIBCPP_INLINE_VISIBILITY reference front();
952 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
953 _LIBCPP_INLINE_VISIBILITY reference back();
954 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000955
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000956 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000957 basic_string& assign(__self_view __sv) { return assign(__sv.data(), __sv.size()); }
958 _LIBCPP_INLINE_VISIBILITY
Marshall Clowf40ec902016-03-09 18:08:29 +0000959 basic_string& assign(const basic_string& __str) { return *this = __str; }
Howard Hinnanta6119a82011-05-29 19:57:12 +0000960#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
961 _LIBCPP_INLINE_VISIBILITY
962 basic_string& assign(basic_string&& str)
Marshall Clow7ed093b2015-10-05 16:17:34 +0000963 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnant0949eed2011-06-30 21:18:19 +0000964 {*this = _VSTD::move(str); return *this;}
Howard Hinnanta6119a82011-05-29 19:57:12 +0000965#endif
Marshall Clowa93b5e22014-03-04 19:17:19 +0000966 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000967 _LIBCPP_INLINE_VISIBILITY
968 basic_string& assign(__self_view __sv, size_type pos, size_type n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +0000969 basic_string& assign(const value_type* __s, size_type __n);
970 basic_string& assign(const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000971 basic_string& assign(size_type __n, value_type __c);
972 template<class _InputIterator>
973 typename enable_if
974 <
Marshall Clowdf9db312016-01-13 21:54:34 +0000975 __is_exactly_input_iterator<_InputIterator>::value
976 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000977 basic_string&
978 >::type
979 assign(_InputIterator __first, _InputIterator __last);
980 template<class _ForwardIterator>
981 typename enable_if
982 <
Marshall Clowdf9db312016-01-13 21:54:34 +0000983 __is_forward_iterator<_ForwardIterator>::value
984 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000985 basic_string&
986 >::type
987 assign(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +0000988#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +0000989 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000990 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000991#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000992
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000993 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000994 basic_string& insert(size_type __pos1, const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +0000995 _LIBCPP_INLINE_VISIBILITY
996 basic_string& insert(size_type __pos1, __self_view __sv) { return insert(__pos1, __sv.data(), __sv.size()); }
997 _LIBCPP_INLINE_VISIBILITY
998 basic_string& insert(size_type __pos1, __self_view __sv, size_type __pos2, size_type __n=npos);
Marshall Clowa93b5e22014-03-04 19:17:19 +0000999 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001000 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1001 basic_string& insert(size_type __pos, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001002 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1003 iterator insert(const_iterator __pos, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001004 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001005 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1006 template<class _InputIterator>
1007 typename enable_if
1008 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001009 __is_exactly_input_iterator<_InputIterator>::value
1010 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001011 iterator
1012 >::type
1013 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1014 template<class _ForwardIterator>
1015 typename enable_if
1016 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001017 __is_forward_iterator<_ForwardIterator>::value
1018 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001019 iterator
1020 >::type
1021 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
Howard Hinnante3e32912011-08-12 21:56:02 +00001022#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001023 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001024 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1025 {return insert(__pos, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001026#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001027
1028 basic_string& erase(size_type __pos = 0, size_type __n = npos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001029 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001030 iterator erase(const_iterator __pos);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001031 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001032 iterator erase(const_iterator __first, const_iterator __last);
1033
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001034 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001035 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001036 _LIBCPP_INLINE_VISIBILITY
1037 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 +00001038 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001039 _LIBCPP_INLINE_VISIBILITY
1040 basic_string& replace(size_type __pos1, size_type __n1, __self_view __sv, size_type __pos2, size_type __n2=npos);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001041 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1042 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001043 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001044 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001045 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001046 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001047 basic_string& replace(const_iterator __i1, const_iterator __i2, __self_view __sv) { return replace(__i1 - begin(), __i2 - __i1, __sv); }
1048 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001049 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001050 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001051 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001052 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001053 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001054 template<class _InputIterator>
1055 typename enable_if
1056 <
1057 __is_input_iterator<_InputIterator>::value,
1058 basic_string&
1059 >::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001060 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
Howard Hinnante3e32912011-08-12 21:56:02 +00001061#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8d7a9552010-09-23 17:31:07 +00001062 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7b2cb482010-11-17 21:11:40 +00001063 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001064 {return replace(__i1, __i2, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00001065#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001066
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001067 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001068 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001069 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1070
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001071 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001072 void swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00001073#if _LIBCPP_STD_VER >= 14
1074 _NOEXCEPT;
1075#else
1076 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1077 __is_nothrow_swappable<allocator_type>::value);
1078#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001079
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001080 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001081 const value_type* c_str() const _NOEXCEPT {return data();}
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001082 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001083 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
Marshall Clowf532a702016-03-08 15:44:30 +00001084#if _LIBCPP_STD_VER > 14
1085 _LIBCPP_INLINE_VISIBILITY
1086 value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1087#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001088
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001089 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001090 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001091
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001092 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001093 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001094 _LIBCPP_INLINE_VISIBILITY
1095 size_type find(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001096 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001097 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001098 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001099 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001100
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001101 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001102 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001103 _LIBCPP_INLINE_VISIBILITY
1104 size_type rfind(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001105 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001106 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001107 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001108 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001109
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001110 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001111 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001112 _LIBCPP_INLINE_VISIBILITY
1113 size_type find_first_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001114 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001115 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001116 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001117 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001118 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001119
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001120 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001121 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001122 _LIBCPP_INLINE_VISIBILITY
1123 size_type find_last_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001124 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001125 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001126 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001127 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001128 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001129
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001130 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001131 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001132 _LIBCPP_INLINE_VISIBILITY
1133 size_type find_first_not_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001134 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 +00001135 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001136 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001137 _LIBCPP_INLINE_VISIBILITY
1138 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1139
1140 _LIBCPP_INLINE_VISIBILITY
1141 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001142 _LIBCPP_INLINE_VISIBILITY
1143 size_type find_last_not_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001144 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 +00001145 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001146 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
Howard Hinnanta6119a82011-05-29 19:57:12 +00001147 _LIBCPP_INLINE_VISIBILITY
1148 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1149
1150 _LIBCPP_INLINE_VISIBILITY
1151 int compare(const basic_string& __str) const _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001152 _LIBCPP_INLINE_VISIBILITY
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001153 int compare(__self_view __sv) const _NOEXCEPT;
1154 _LIBCPP_INLINE_VISIBILITY
1155 int compare(size_type __pos1, size_type __n1, __self_view __sv) const;
1156 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001157 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
Marshall Clowa93b5e22014-03-04 19:17:19 +00001158 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001159 _LIBCPP_INLINE_VISIBILITY
1160 int compare(size_type __pos1, size_type __n1, __self_view __sv, size_type __pos2, size_type __n2=npos) const;
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001161 int compare(const value_type* __s) const _NOEXCEPT;
1162 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1163 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001164
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001165 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
Howard Hinnant08dd2532013-04-22 23:55:13 +00001166
1167 _LIBCPP_INLINE_VISIBILITY
1168 bool __is_long() const _NOEXCEPT
1169 {return bool(__r_.first().__s.__size_ & __short_mask);}
1170
Howard Hinnant499cea12013-08-23 17:37:05 +00001171#if _LIBCPP_DEBUG_LEVEL >= 2
1172
1173 bool __dereferenceable(const const_iterator* __i) const;
1174 bool __decrementable(const const_iterator* __i) const;
1175 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1176 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1177
1178#endif // _LIBCPP_DEBUG_LEVEL >= 2
1179
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001180private:
Howard Hinnanta6119a82011-05-29 19:57:12 +00001181 _LIBCPP_INLINE_VISIBILITY
1182 allocator_type& __alloc() _NOEXCEPT
1183 {return __r_.second();}
1184 _LIBCPP_INLINE_VISIBILITY
1185 const allocator_type& __alloc() const _NOEXCEPT
1186 {return __r_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001187
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001188#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001189
Howard Hinnanta6119a82011-05-29 19:57:12 +00001190 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta6119a82011-05-29 19:57:12 +00001191 void __set_short_size(size_type __s) _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001192# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001193 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
Howard Hinnant15467182013-04-30 21:44:48 +00001194# else
1195 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1196# endif
1197
Howard Hinnanta6119a82011-05-29 19:57:12 +00001198 _LIBCPP_INLINE_VISIBILITY
1199 size_type __get_short_size() const _NOEXCEPT
Howard Hinnant15467182013-04-30 21:44:48 +00001200# if _LIBCPP_BIG_ENDIAN
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001201 {return __r_.first().__s.__size_ >> 1;}
Howard Hinnant15467182013-04-30 21:44:48 +00001202# else
1203 {return __r_.first().__s.__size_;}
1204# endif
1205
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001206#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001207
1208 _LIBCPP_INLINE_VISIBILITY
1209 void __set_short_size(size_type __s) _NOEXCEPT
1210# if _LIBCPP_BIG_ENDIAN
1211 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1212# else
1213 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1214# endif
1215
1216 _LIBCPP_INLINE_VISIBILITY
1217 size_type __get_short_size() const _NOEXCEPT
1218# if _LIBCPP_BIG_ENDIAN
1219 {return __r_.first().__s.__size_;}
1220# else
1221 {return __r_.first().__s.__size_ >> 1;}
1222# endif
1223
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +00001224#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
Howard Hinnant15467182013-04-30 21:44:48 +00001225
Howard Hinnanta6119a82011-05-29 19:57:12 +00001226 _LIBCPP_INLINE_VISIBILITY
1227 void __set_long_size(size_type __s) _NOEXCEPT
1228 {__r_.first().__l.__size_ = __s;}
1229 _LIBCPP_INLINE_VISIBILITY
1230 size_type __get_long_size() const _NOEXCEPT
1231 {return __r_.first().__l.__size_;}
1232 _LIBCPP_INLINE_VISIBILITY
1233 void __set_size(size_type __s) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001234 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1235
Howard Hinnanta6119a82011-05-29 19:57:12 +00001236 _LIBCPP_INLINE_VISIBILITY
1237 void __set_long_cap(size_type __s) _NOEXCEPT
1238 {__r_.first().__l.__cap_ = __long_mask | __s;}
1239 _LIBCPP_INLINE_VISIBILITY
1240 size_type __get_long_cap() const _NOEXCEPT
Howard Hinnantec3773c2011-12-01 20:21:04 +00001241 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001242
Howard Hinnanta6119a82011-05-29 19:57:12 +00001243 _LIBCPP_INLINE_VISIBILITY
1244 void __set_long_pointer(pointer __p) _NOEXCEPT
1245 {__r_.first().__l.__data_ = __p;}
1246 _LIBCPP_INLINE_VISIBILITY
1247 pointer __get_long_pointer() _NOEXCEPT
1248 {return __r_.first().__l.__data_;}
1249 _LIBCPP_INLINE_VISIBILITY
1250 const_pointer __get_long_pointer() const _NOEXCEPT
1251 {return __r_.first().__l.__data_;}
1252 _LIBCPP_INLINE_VISIBILITY
1253 pointer __get_short_pointer() _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001254 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001255 _LIBCPP_INLINE_VISIBILITY
1256 const_pointer __get_short_pointer() const _NOEXCEPT
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001257 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001258 _LIBCPP_INLINE_VISIBILITY
1259 pointer __get_pointer() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001260 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
Howard Hinnanta6119a82011-05-29 19:57:12 +00001261 _LIBCPP_INLINE_VISIBILITY
1262 const_pointer __get_pointer() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001263 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1264
Howard Hinnanta6119a82011-05-29 19:57:12 +00001265 _LIBCPP_INLINE_VISIBILITY
1266 void __zero() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001267 {
1268 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1269 for (unsigned __i = 0; __i < __n_words; ++__i)
1270 __a[__i] = 0;
1271 }
1272
1273 template <size_type __a> static
Howard Hinnanta6119a82011-05-29 19:57:12 +00001274 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7f764502013-08-14 18:00:20 +00001275 size_type __align_it(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001276 {return (__s + (__a-1)) & ~(__a-1);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001277 enum {__alignment = 16};
Howard Hinnanta6119a82011-05-29 19:57:12 +00001278 static _LIBCPP_INLINE_VISIBILITY
1279 size_type __recommend(size_type __s) _NOEXCEPT
Eric Fiseliere2d48922015-08-28 07:02:42 +00001280 {return (__s < __min_cap ? static_cast<size_type>(__min_cap) :
Howard Hinnant7f764502013-08-14 18:00:20 +00001281 __align_it<sizeof(value_type) < __alignment ?
Howard Hinnanta6119a82011-05-29 19:57:12 +00001282 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001283
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001284 void __init(const value_type* __s, size_type __sz, size_type __reserve);
1285 void __init(const value_type* __s, size_type __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001286 void __init(size_type __n, value_type __c);
Howard Hinnant324bb032010-08-22 00:02:43 +00001287
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001288 template <class _InputIterator>
1289 typename enable_if
1290 <
Marshall Clowdf9db312016-01-13 21:54:34 +00001291 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001292 void
1293 >::type
1294 __init(_InputIterator __first, _InputIterator __last);
1295
1296 template <class _ForwardIterator>
1297 typename enable_if
1298 <
1299 __is_forward_iterator<_ForwardIterator>::value,
1300 void
1301 >::type
1302 __init(_ForwardIterator __first, _ForwardIterator __last);
1303
1304 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant324bb032010-08-22 00:02:43 +00001305 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001306 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1307 size_type __n_copy, size_type __n_del,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001308 size_type __n_add, const value_type* __p_new_stuff);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001309
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001310 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001311 void __erase_to_end(size_type __pos);
1312
Howard Hinnante32b5e22010-11-17 17:55:08 +00001313 _LIBCPP_INLINE_VISIBILITY
1314 void __copy_assign_alloc(const basic_string& __str)
1315 {__copy_assign_alloc(__str, integral_constant<bool,
1316 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1317
1318 _LIBCPP_INLINE_VISIBILITY
1319 void __copy_assign_alloc(const basic_string& __str, true_type)
1320 {
1321 if (__alloc() != __str.__alloc())
1322 {
1323 clear();
1324 shrink_to_fit();
1325 }
1326 __alloc() = __str.__alloc();
1327 }
1328
1329 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001330 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
Howard Hinnante32b5e22010-11-17 17:55:08 +00001331 {}
1332
1333#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001334 _LIBCPP_INLINE_VISIBILITY
Marshall Clowaf961ed2015-08-18 18:57:00 +00001335 void __move_assign(basic_string& __str, false_type)
1336 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001337 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001338 void __move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001339#if _LIBCPP_STD_VER > 14
1340 _NOEXCEPT;
1341#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001342 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001343#endif
Marshall Clowaf961ed2015-08-18 18:57:00 +00001344#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00001345
1346 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001347 void
Howard Hinnant9cbee432011-09-02 20:42:31 +00001348 __move_assign_alloc(basic_string& __str)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001349 _NOEXCEPT_(
1350 !__alloc_traits::propagate_on_container_move_assignment::value ||
1351 is_nothrow_move_assignable<allocator_type>::value)
1352 {__move_assign_alloc(__str, integral_constant<bool,
1353 __alloc_traits::propagate_on_container_move_assignment::value>());}
1354
1355 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +00001356 void __move_assign_alloc(basic_string& __c, true_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001357 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1358 {
1359 __alloc() = _VSTD::move(__c.__alloc());
1360 }
1361
1362 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantec3773c2011-12-01 20:21:04 +00001363 void __move_assign_alloc(basic_string&, false_type)
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001364 _NOEXCEPT
1365 {}
1366
Howard Hinnant2d72b1e2010-12-17 14:46:43 +00001367 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1368 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001369
1370 friend basic_string operator+<>(const basic_string&, const basic_string&);
1371 friend basic_string operator+<>(const value_type*, const basic_string&);
1372 friend basic_string operator+<>(value_type, const basic_string&);
1373 friend basic_string operator+<>(const basic_string&, const value_type*);
1374 friend basic_string operator+<>(const basic_string&, value_type);
1375};
1376
1377template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001378inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001379void
1380basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1381{
Howard Hinnant499cea12013-08-23 17:37:05 +00001382#if _LIBCPP_DEBUG_LEVEL >= 2
1383 __get_db()->__invalidate_all(this);
1384#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001385}
1386
1387template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001388inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001389void
Howard Hinnantec3773c2011-12-01 20:21:04 +00001390basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
Howard Hinnant499cea12013-08-23 17:37:05 +00001391#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantec3773c2011-12-01 20:21:04 +00001392 __pos
1393#endif
1394 )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001395{
Howard Hinnant499cea12013-08-23 17:37:05 +00001396#if _LIBCPP_DEBUG_LEVEL >= 2
1397 __c_node* __c = __get_db()->__find_c_and_lock(this);
1398 if (__c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001399 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001400 const_pointer __new_last = __get_pointer() + __pos;
1401 for (__i_node** __p = __c->end_; __p != __c->beg_; )
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001402 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001403 --__p;
1404 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1405 if (__i->base() > __new_last)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001406 {
Howard Hinnant499cea12013-08-23 17:37:05 +00001407 (*__p)->__c_ = nullptr;
1408 if (--__c->end_ != __p)
1409 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001410 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001411 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001412 __get_db()->unlock();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001413 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001414#endif // _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001415}
1416
1417template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001418inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001419basic_string<_CharT, _Traits, _Allocator>::basic_string()
Marshall Clowc912c0c2015-06-04 02:05:41 +00001420 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001421{
Howard Hinnant499cea12013-08-23 17:37:05 +00001422#if _LIBCPP_DEBUG_LEVEL >= 2
1423 __get_db()->__insert_c(this);
1424#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001425 __zero();
1426}
1427
1428template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001429inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001430basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
Eric Fiselier692177d2015-07-18 20:40:46 +00001431#if _LIBCPP_STD_VER <= 14
1432 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1433#else
1434 _NOEXCEPT
1435#endif
1436: __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001437{
Howard Hinnant499cea12013-08-23 17:37:05 +00001438#if _LIBCPP_DEBUG_LEVEL >= 2
1439 __get_db()->__insert_c(this);
1440#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001441 __zero();
1442}
1443
1444template <class _CharT, class _Traits, class _Allocator>
Sebastian Popbb11bc42016-08-11 16:51:48 +00001445inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001446void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001447basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001448{
1449 if (__reserve > max_size())
1450 this->__throw_length_error();
1451 pointer __p;
1452 if (__reserve < __min_cap)
1453 {
1454 __set_short_size(__sz);
1455 __p = __get_short_pointer();
1456 }
1457 else
1458 {
1459 size_type __cap = __recommend(__reserve);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001460 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001461 __set_long_pointer(__p);
1462 __set_long_cap(__cap+1);
1463 __set_long_size(__sz);
1464 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001465 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001466 traits_type::assign(__p[__sz], value_type());
1467}
1468
1469template <class _CharT, class _Traits, class _Allocator>
Sebastian Popbb11bc42016-08-11 16:51:48 +00001470inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001471void
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001472basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001473{
1474 if (__sz > max_size())
1475 this->__throw_length_error();
1476 pointer __p;
1477 if (__sz < __min_cap)
1478 {
1479 __set_short_size(__sz);
1480 __p = __get_short_pointer();
1481 }
1482 else
1483 {
1484 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001485 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001486 __set_long_pointer(__p);
1487 __set_long_cap(__cap+1);
1488 __set_long_size(__sz);
1489 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001490 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001491 traits_type::assign(__p[__sz], value_type());
1492}
1493
1494template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001495inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001496basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001497{
Howard Hinnant499cea12013-08-23 17:37:05 +00001498 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001499 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00001500#if _LIBCPP_DEBUG_LEVEL >= 2
1501 __get_db()->__insert_c(this);
1502#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001503}
1504
1505template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001506inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001507basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001508 : __r_(__a)
1509{
Howard Hinnant499cea12013-08-23 17:37:05 +00001510 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001511 __init(__s, traits_type::length(__s));
Howard Hinnant499cea12013-08-23 17:37:05 +00001512#if _LIBCPP_DEBUG_LEVEL >= 2
1513 __get_db()->__insert_c(this);
1514#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001515}
1516
1517template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001518inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001519basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001520{
Howard Hinnant499cea12013-08-23 17:37:05 +00001521 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001522 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001523#if _LIBCPP_DEBUG_LEVEL >= 2
1524 __get_db()->__insert_c(this);
1525#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001526}
1527
1528template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001529inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001530basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001531 : __r_(__a)
1532{
Howard Hinnant499cea12013-08-23 17:37:05 +00001533 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001534 __init(__s, __n);
Howard Hinnant499cea12013-08-23 17:37:05 +00001535#if _LIBCPP_DEBUG_LEVEL >= 2
1536 __get_db()->__insert_c(this);
1537#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001538}
1539
1540template <class _CharT, class _Traits, class _Allocator>
1541basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001542 : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc()))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001543{
1544 if (!__str.__is_long())
1545 __r_.first().__r = __str.__r_.first().__r;
1546 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001547 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Howard Hinnant499cea12013-08-23 17:37:05 +00001548#if _LIBCPP_DEBUG_LEVEL >= 2
1549 __get_db()->__insert_c(this);
1550#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001551}
1552
1553template <class _CharT, class _Traits, class _Allocator>
1554basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
1555 : __r_(__a)
1556{
1557 if (!__str.__is_long())
1558 __r_.first().__r = __str.__r_.first().__r;
1559 else
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001560 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
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
Howard Hinnant73d21a42010-09-04 23:28:19 +00001566#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001567
1568template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001569inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001570basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
Marshall Clow7b193f72015-06-03 19:56:43 +00001571#if _LIBCPP_STD_VER <= 14
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001572 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
Marshall Clow7b193f72015-06-03 19:56:43 +00001573#else
1574 _NOEXCEPT
1575#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00001576 : __r_(_VSTD::move(__str.__r_))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001577{
1578 __str.__zero();
Howard Hinnant499cea12013-08-23 17:37:05 +00001579#if _LIBCPP_DEBUG_LEVEL >= 2
1580 __get_db()->__insert_c(this);
1581 if (__is_long())
1582 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001583#endif
1584}
1585
1586template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001587inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001588basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001589 : __r_(__a)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001590{
Marshall Clowd5549cc2014-07-17 15:32:20 +00001591 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001592 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
Marshall Clowd5549cc2014-07-17 15:32:20 +00001593 else
1594 {
1595 __r_.first().__r = __str.__r_.first().__r;
1596 __str.__zero();
1597 }
Howard Hinnant499cea12013-08-23 17:37:05 +00001598#if _LIBCPP_DEBUG_LEVEL >= 2
1599 __get_db()->__insert_c(this);
1600 if (__is_long())
1601 __get_db()->swap(this, &__str);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001602#endif
1603}
1604
Howard Hinnant73d21a42010-09-04 23:28:19 +00001605#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001606
1607template <class _CharT, class _Traits, class _Allocator>
Sebastian Popbb11bc42016-08-11 16:51:48 +00001608inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001609void
1610basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1611{
1612 if (__n > max_size())
1613 this->__throw_length_error();
1614 pointer __p;
1615 if (__n < __min_cap)
1616 {
1617 __set_short_size(__n);
1618 __p = __get_short_pointer();
1619 }
1620 else
1621 {
1622 size_type __cap = __recommend(__n);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001623 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001624 __set_long_pointer(__p);
1625 __set_long_cap(__cap+1);
1626 __set_long_size(__n);
1627 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001628 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001629 traits_type::assign(__p[__n], value_type());
1630}
1631
1632template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001633inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001634basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
1635{
1636 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001637#if _LIBCPP_DEBUG_LEVEL >= 2
1638 __get_db()->__insert_c(this);
1639#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001640}
1641
1642template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001643inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001644basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
1645 : __r_(__a)
1646{
1647 __init(__n, __c);
Howard Hinnant499cea12013-08-23 17:37:05 +00001648#if _LIBCPP_DEBUG_LEVEL >= 2
1649 __get_db()->__insert_c(this);
1650#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001651}
1652
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001653template <class _CharT, class _Traits, class _Allocator>
1654basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
1655 const allocator_type& __a)
1656 : __r_(__a)
1657{
1658 size_type __str_sz = __str.size();
1659 if (__pos > __str_sz)
1660 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00001661 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
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>
Marshall Clowf4f7d8f2016-04-07 18:13:41 +00001668inline _LIBCPP_INLINE_VISIBILITY
1669basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
1670 const allocator_type& __a)
1671 : __r_(__a)
1672{
1673 size_type __str_sz = __str.size();
1674 if (__pos > __str_sz)
1675 this->__throw_out_of_range();
1676 __init(__str.data() + __pos, __str_sz - __pos);
1677#if _LIBCPP_DEBUG_LEVEL >= 2
1678 __get_db()->__insert_c(this);
1679#endif
1680}
1681
1682template <class _CharT, class _Traits, class _Allocator>
Marshall Clow1e00d6d2016-07-21 05:31:24 +00001683inline _LIBCPP_INLINE_VISIBILITY
1684basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv)
1685{
1686 __init(__sv.data(), __sv.size());
1687#if _LIBCPP_DEBUG_LEVEL >= 2
1688 __get_db()->__insert_c(this);
1689#endif
1690}
1691
1692template <class _CharT, class _Traits, class _Allocator>
1693inline _LIBCPP_INLINE_VISIBILITY
1694basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv, const allocator_type& __a)
1695 : __r_(__a)
1696{
1697 __init(__sv.data(), __sv.size());
1698#if _LIBCPP_DEBUG_LEVEL >= 2
1699 __get_db()->__insert_c(this);
1700#endif
1701}
1702
1703template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001704template <class _InputIterator>
Sebastian Popbb11bc42016-08-11 16:51:48 +00001705inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001706typename enable_if
1707<
Marshall Clowdf9db312016-01-13 21:54:34 +00001708 __is_exactly_input_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001709 void
1710>::type
1711basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
1712{
1713 __zero();
1714#ifndef _LIBCPP_NO_EXCEPTIONS
1715 try
1716 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001717#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001718 for (; __first != __last; ++__first)
1719 push_back(*__first);
1720#ifndef _LIBCPP_NO_EXCEPTIONS
1721 }
1722 catch (...)
1723 {
1724 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00001725 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001726 throw;
1727 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001728#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001729}
1730
1731template <class _CharT, class _Traits, class _Allocator>
1732template <class _ForwardIterator>
Sebastian Popbb11bc42016-08-11 16:51:48 +00001733inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001734typename enable_if
1735<
1736 __is_forward_iterator<_ForwardIterator>::value,
1737 void
1738>::type
1739basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
1740{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001741 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001742 if (__sz > max_size())
1743 this->__throw_length_error();
1744 pointer __p;
1745 if (__sz < __min_cap)
1746 {
1747 __set_short_size(__sz);
1748 __p = __get_short_pointer();
1749 }
1750 else
1751 {
1752 size_type __cap = __recommend(__sz);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001753 __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001754 __set_long_pointer(__p);
1755 __set_long_cap(__cap+1);
1756 __set_long_size(__sz);
1757 }
Eric Fiselierb9919752014-10-27 19:28:20 +00001758 for (; __first != __last; ++__first, (void) ++__p)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001759 traits_type::assign(*__p, *__first);
1760 traits_type::assign(*__p, value_type());
1761}
1762
1763template <class _CharT, class _Traits, class _Allocator>
1764template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001765inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001766basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
1767{
1768 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00001769#if _LIBCPP_DEBUG_LEVEL >= 2
1770 __get_db()->__insert_c(this);
1771#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001772}
1773
1774template <class _CharT, class _Traits, class _Allocator>
1775template<class _InputIterator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001776inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001777basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
1778 const allocator_type& __a)
1779 : __r_(__a)
1780{
1781 __init(__first, __last);
Howard Hinnant499cea12013-08-23 17:37:05 +00001782#if _LIBCPP_DEBUG_LEVEL >= 2
1783 __get_db()->__insert_c(this);
1784#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001785}
1786
Howard Hinnante3e32912011-08-12 21:56:02 +00001787#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1788
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001789template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001790inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001791basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
1792{
1793 __init(__il.begin(), __il.end());
Howard Hinnant499cea12013-08-23 17:37:05 +00001794#if _LIBCPP_DEBUG_LEVEL >= 2
1795 __get_db()->__insert_c(this);
1796#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001797}
1798
1799template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001800inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001801basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
1802 : __r_(__a)
1803{
1804 __init(__il.begin(), __il.end());
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#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1811
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001812template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001813basic_string<_CharT, _Traits, _Allocator>::~basic_string()
1814{
Howard Hinnant499cea12013-08-23 17:37:05 +00001815#if _LIBCPP_DEBUG_LEVEL >= 2
1816 __get_db()->__erase_c(this);
1817#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001818 if (__is_long())
Howard Hinnante32b5e22010-11-17 17:55:08 +00001819 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001820}
1821
1822template <class _CharT, class _Traits, class _Allocator>
1823void
1824basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
1825 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001826 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 +00001827{
1828 size_type __ms = max_size();
1829 if (__delta_cap > __ms - __old_cap - 1)
1830 this->__throw_length_error();
1831 pointer __old_p = __get_pointer();
1832 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00001833 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001834 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001835 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001836 __invalidate_all_iterators();
1837 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001838 traits_type::copy(_VSTD::__to_raw_pointer(__p),
1839 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001840 if (__n_add != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001841 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001842 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
1843 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001844 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
1845 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001846 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001847 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001848 __set_long_pointer(__p);
1849 __set_long_cap(__cap+1);
1850 __old_sz = __n_copy + __n_add + __sec_cp_sz;
1851 __set_long_size(__old_sz);
1852 traits_type::assign(__p[__old_sz], value_type());
1853}
1854
1855template <class _CharT, class _Traits, class _Allocator>
1856void
1857basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1858 size_type __n_copy, size_type __n_del, size_type __n_add)
1859{
1860 size_type __ms = max_size();
Marshall Clowecc8d7b2013-11-06 14:24:38 +00001861 if (__delta_cap > __ms - __old_cap)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001862 this->__throw_length_error();
1863 pointer __old_p = __get_pointer();
1864 size_type __cap = __old_cap < __ms / 2 - __alignment ?
Howard Hinnant0949eed2011-06-30 21:18:19 +00001865 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001866 __ms - 1;
Howard Hinnante32b5e22010-11-17 17:55:08 +00001867 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001868 __invalidate_all_iterators();
1869 if (__n_copy != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001870 traits_type::copy(_VSTD::__to_raw_pointer(__p),
1871 _VSTD::__to_raw_pointer(__old_p), __n_copy);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001872 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
1873 if (__sec_cp_sz != 0)
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001874 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
1875 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
1876 __sec_cp_sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001877 if (__old_cap+1 != __min_cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001878 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001879 __set_long_pointer(__p);
1880 __set_long_cap(__cap+1);
1881}
1882
1883// assign
1884
1885template <class _CharT, class _Traits, class _Allocator>
1886basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001887basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001888{
Alp Tokerec34c482014-05-15 11:27:39 +00001889 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001890 size_type __cap = capacity();
1891 if (__cap >= __n)
1892 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001893 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001894 traits_type::move(__p, __s, __n);
1895 traits_type::assign(__p[__n], value_type());
1896 __set_size(__n);
1897 __invalidate_iterators_past(__n);
1898 }
1899 else
1900 {
1901 size_type __sz = size();
1902 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
1903 }
1904 return *this;
1905}
1906
1907template <class _CharT, class _Traits, class _Allocator>
1908basic_string<_CharT, _Traits, _Allocator>&
1909basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
1910{
1911 size_type __cap = capacity();
1912 if (__cap < __n)
1913 {
1914 size_type __sz = size();
1915 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
1916 }
1917 else
1918 __invalidate_iterators_past(__n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00001919 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001920 traits_type::assign(__p, __n, __c);
1921 traits_type::assign(__p[__n], value_type());
1922 __set_size(__n);
1923 return *this;
1924}
1925
1926template <class _CharT, class _Traits, class _Allocator>
1927basic_string<_CharT, _Traits, _Allocator>&
1928basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
1929{
1930 pointer __p;
1931 if (__is_long())
1932 {
1933 __p = __get_long_pointer();
1934 __set_long_size(1);
1935 }
1936 else
1937 {
1938 __p = __get_short_pointer();
1939 __set_short_size(1);
1940 }
1941 traits_type::assign(*__p, __c);
1942 traits_type::assign(*++__p, value_type());
1943 __invalidate_iterators_past(1);
1944 return *this;
1945}
1946
1947template <class _CharT, class _Traits, class _Allocator>
Howard Hinnante32b5e22010-11-17 17:55:08 +00001948basic_string<_CharT, _Traits, _Allocator>&
1949basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
1950{
1951 if (this != &__str)
1952 {
1953 __copy_assign_alloc(__str);
Marshall Clowf40ec902016-03-09 18:08:29 +00001954 assign(__str.data(), __str.size());
Howard Hinnante32b5e22010-11-17 17:55:08 +00001955 }
1956 return *this;
1957}
1958
1959#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1960
1961template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001962inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00001963void
1964basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001965 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
Howard Hinnante32b5e22010-11-17 17:55:08 +00001966{
1967 if (__alloc() != __str.__alloc())
1968 assign(__str);
1969 else
1970 __move_assign(__str, true_type());
1971}
1972
1973template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001974inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00001975void
1976basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001977#if _LIBCPP_STD_VER > 14
1978 _NOEXCEPT
1979#else
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00001980 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001981#endif
Howard Hinnante32b5e22010-11-17 17:55:08 +00001982{
1983 clear();
1984 shrink_to_fit();
Howard Hinnant3fdbbd22011-08-17 20:36:18 +00001985 __r_.first() = __str.__r_.first();
1986 __move_assign_alloc(__str);
Howard Hinnante32b5e22010-11-17 17:55:08 +00001987 __str.__zero();
1988}
1989
1990template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00001991inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnante32b5e22010-11-17 17:55:08 +00001992basic_string<_CharT, _Traits, _Allocator>&
1993basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
Marshall Clowaf961ed2015-08-18 18:57:00 +00001994 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
Howard Hinnante32b5e22010-11-17 17:55:08 +00001995{
1996 __move_assign(__str, integral_constant<bool,
1997 __alloc_traits::propagate_on_container_move_assignment::value>());
1998 return *this;
1999}
2000
2001#endif
2002
2003template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002004template<class _InputIterator>
2005typename enable_if
2006<
Marshall Clowdf9db312016-01-13 21:54:34 +00002007 __is_exactly_input_iterator <_InputIterator>::value
2008 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002009 basic_string<_CharT, _Traits, _Allocator>&
2010>::type
2011basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2012{
Marshall Clowdf9db312016-01-13 21:54:34 +00002013 basic_string __temp(__first, __last, __alloc());
2014 assign(__temp.data(), __temp.size());
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00002015 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002016}
2017
2018template <class _CharT, class _Traits, class _Allocator>
2019template<class _ForwardIterator>
2020typename enable_if
2021<
Marshall Clowdf9db312016-01-13 21:54:34 +00002022 __is_forward_iterator<_ForwardIterator>::value
2023 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002024 basic_string<_CharT, _Traits, _Allocator>&
2025>::type
2026basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2027{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002028 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002029 size_type __cap = capacity();
2030 if (__cap < __n)
2031 {
2032 size_type __sz = size();
2033 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2034 }
2035 else
2036 __invalidate_iterators_past(__n);
2037 pointer __p = __get_pointer();
2038 for (; __first != __last; ++__first, ++__p)
2039 traits_type::assign(*__p, *__first);
2040 traits_type::assign(*__p, value_type());
2041 __set_size(__n);
2042 return *this;
2043}
2044
2045template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002046basic_string<_CharT, _Traits, _Allocator>&
2047basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2048{
2049 size_type __sz = __str.size();
2050 if (__pos > __sz)
2051 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002052 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002053}
2054
2055template <class _CharT, class _Traits, class _Allocator>
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002056inline _LIBCPP_INLINE_VISIBILITY
2057basic_string<_CharT, _Traits, _Allocator>&
2058basic_string<_CharT, _Traits, _Allocator>::assign(__self_view __sv, size_type __pos, size_type __n)
2059{
2060 size_type __sz = __sv.size();
2061 if (__pos > __sz)
2062 this->__throw_out_of_range();
2063 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2064}
2065
2066
2067template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002068basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002069basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002070{
Alp Tokerec34c482014-05-15 11:27:39 +00002071 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002072 return assign(__s, traits_type::length(__s));
2073}
2074
2075// append
2076
2077template <class _CharT, class _Traits, class _Allocator>
2078basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002079basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002080{
Alp Tokerec34c482014-05-15 11:27:39 +00002081 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002082 size_type __cap = capacity();
2083 size_type __sz = size();
2084 if (__cap - __sz >= __n)
2085 {
2086 if (__n)
2087 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002088 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002089 traits_type::copy(__p + __sz, __s, __n);
2090 __sz += __n;
2091 __set_size(__sz);
2092 traits_type::assign(__p[__sz], value_type());
2093 }
2094 }
2095 else
2096 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2097 return *this;
2098}
2099
2100template <class _CharT, class _Traits, class _Allocator>
2101basic_string<_CharT, _Traits, _Allocator>&
2102basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2103{
2104 if (__n)
2105 {
2106 size_type __cap = capacity();
2107 size_type __sz = size();
2108 if (__cap - __sz < __n)
2109 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2110 pointer __p = __get_pointer();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002111 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002112 __sz += __n;
2113 __set_size(__sz);
2114 traits_type::assign(__p[__sz], value_type());
2115 }
2116 return *this;
2117}
2118
2119template <class _CharT, class _Traits, class _Allocator>
2120void
2121basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2122{
Howard Hinnant15467182013-04-30 21:44:48 +00002123 bool __is_short = !__is_long();
2124 size_type __cap;
2125 size_type __sz;
2126 if (__is_short)
2127 {
2128 __cap = __min_cap - 1;
2129 __sz = __get_short_size();
2130 }
2131 else
2132 {
2133 __cap = __get_long_cap() - 1;
2134 __sz = __get_long_size();
2135 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002136 if (__sz == __cap)
Howard Hinnant15467182013-04-30 21:44:48 +00002137 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002138 __grow_by(__cap, 1, __sz, __sz, 0);
Howard Hinnant15467182013-04-30 21:44:48 +00002139 __is_short = !__is_long();
2140 }
2141 pointer __p;
2142 if (__is_short)
2143 {
2144 __p = __get_short_pointer() + __sz;
2145 __set_short_size(__sz+1);
2146 }
2147 else
2148 {
2149 __p = __get_long_pointer() + __sz;
2150 __set_long_size(__sz+1);
2151 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002152 traits_type::assign(*__p, __c);
2153 traits_type::assign(*++__p, value_type());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002154}
2155
2156template <class _CharT, class _Traits, class _Allocator>
2157template<class _InputIterator>
2158typename enable_if
2159<
Marshall Clowdf9db312016-01-13 21:54:34 +00002160 __is_exactly_input_iterator<_InputIterator>::value
2161 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002162 basic_string<_CharT, _Traits, _Allocator>&
2163>::type
2164basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
2165{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002166 basic_string __temp (__first, __last, __alloc());
2167 append(__temp.data(), __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002168 return *this;
2169}
2170
2171template <class _CharT, class _Traits, class _Allocator>
2172template<class _ForwardIterator>
2173typename enable_if
2174<
Marshall Clowdf9db312016-01-13 21:54:34 +00002175 __is_forward_iterator<_ForwardIterator>::value
2176 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002177 basic_string<_CharT, _Traits, _Allocator>&
2178>::type
2179basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
2180{
2181 size_type __sz = size();
2182 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002183 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002184 if (__n)
2185 {
2186 if (__cap - __sz < __n)
2187 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2188 pointer __p = __get_pointer() + __sz;
2189 for (; __first != __last; ++__p, ++__first)
2190 traits_type::assign(*__p, *__first);
2191 traits_type::assign(*__p, value_type());
2192 __set_size(__sz + __n);
2193 }
2194 return *this;
2195}
2196
2197template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002198inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002199basic_string<_CharT, _Traits, _Allocator>&
2200basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2201{
2202 return append(__str.data(), __str.size());
2203}
2204
2205template <class _CharT, class _Traits, class _Allocator>
2206basic_string<_CharT, _Traits, _Allocator>&
2207basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2208{
2209 size_type __sz = __str.size();
2210 if (__pos > __sz)
2211 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002212 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002213}
2214
2215template <class _CharT, class _Traits, class _Allocator>
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002216inline _LIBCPP_INLINE_VISIBILITY
2217basic_string<_CharT, _Traits, _Allocator>&
2218basic_string<_CharT, _Traits, _Allocator>::append(__self_view __sv, size_type __pos, size_type __n)
2219{
2220 size_type __sz = __sv.size();
2221 if (__pos > __sz)
2222 this->__throw_out_of_range();
2223 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2224}
2225
2226template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002227basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002228basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002229{
Alp Tokerec34c482014-05-15 11:27:39 +00002230 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002231 return append(__s, traits_type::length(__s));
2232}
2233
2234// insert
2235
2236template <class _CharT, class _Traits, class _Allocator>
2237basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002238basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002239{
Alp Tokerec34c482014-05-15 11:27:39 +00002240 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002241 size_type __sz = size();
2242 if (__pos > __sz)
2243 this->__throw_out_of_range();
2244 size_type __cap = capacity();
2245 if (__cap - __sz >= __n)
2246 {
2247 if (__n)
2248 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002249 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002250 size_type __n_move = __sz - __pos;
2251 if (__n_move != 0)
2252 {
2253 if (__p + __pos <= __s && __s < __p + __sz)
2254 __s += __n;
2255 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2256 }
2257 traits_type::move(__p + __pos, __s, __n);
2258 __sz += __n;
2259 __set_size(__sz);
2260 traits_type::assign(__p[__sz], value_type());
2261 }
2262 }
2263 else
2264 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2265 return *this;
2266}
2267
2268template <class _CharT, class _Traits, class _Allocator>
2269basic_string<_CharT, _Traits, _Allocator>&
2270basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2271{
2272 size_type __sz = size();
2273 if (__pos > __sz)
2274 this->__throw_out_of_range();
2275 if (__n)
2276 {
2277 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002278 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002279 if (__cap - __sz >= __n)
2280 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002281 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002282 size_type __n_move = __sz - __pos;
2283 if (__n_move != 0)
2284 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2285 }
2286 else
2287 {
2288 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002289 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002290 }
2291 traits_type::assign(__p + __pos, __n, __c);
2292 __sz += __n;
2293 __set_size(__sz);
2294 traits_type::assign(__p[__sz], value_type());
2295 }
2296 return *this;
2297}
2298
2299template <class _CharT, class _Traits, class _Allocator>
2300template<class _InputIterator>
2301typename enable_if
2302<
Marshall Clowdf9db312016-01-13 21:54:34 +00002303 __is_exactly_input_iterator<_InputIterator>::value
2304 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2305 typename basic_string<_CharT, _Traits, _Allocator>::iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002306>::type
2307basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2308{
Howard Hinnant499cea12013-08-23 17:37:05 +00002309#if _LIBCPP_DEBUG_LEVEL >= 2
2310 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2311 "string::insert(iterator, range) called with an iterator not"
2312 " referring to this string");
2313#endif
Marshall Clowdf9db312016-01-13 21:54:34 +00002314 basic_string __temp(__first, __last, __alloc());
2315 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002316}
2317
2318template <class _CharT, class _Traits, class _Allocator>
2319template<class _ForwardIterator>
2320typename enable_if
2321<
Marshall Clowdf9db312016-01-13 21:54:34 +00002322 __is_forward_iterator<_ForwardIterator>::value
2323 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002324 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2325>::type
2326basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2327{
Howard Hinnant499cea12013-08-23 17:37:05 +00002328#if _LIBCPP_DEBUG_LEVEL >= 2
2329 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2330 "string::insert(iterator, range) called with an iterator not"
2331 " referring to this string");
2332#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002333 size_type __ip = static_cast<size_type>(__pos - begin());
2334 size_type __sz = size();
2335 size_type __cap = capacity();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002336 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002337 if (__n)
2338 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002339 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002340 if (__cap - __sz >= __n)
2341 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002342 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002343 size_type __n_move = __sz - __ip;
2344 if (__n_move != 0)
2345 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2346 }
2347 else
2348 {
2349 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002350 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002351 }
2352 __sz += __n;
2353 __set_size(__sz);
2354 traits_type::assign(__p[__sz], value_type());
2355 for (__p += __ip; __first != __last; ++__p, ++__first)
2356 traits_type::assign(*__p, *__first);
2357 }
2358 return begin() + __ip;
2359}
2360
2361template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002362inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002363basic_string<_CharT, _Traits, _Allocator>&
2364basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2365{
2366 return insert(__pos1, __str.data(), __str.size());
2367}
2368
2369template <class _CharT, class _Traits, class _Allocator>
2370basic_string<_CharT, _Traits, _Allocator>&
2371basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2372 size_type __pos2, size_type __n)
2373{
2374 size_type __str_sz = __str.size();
2375 if (__pos2 > __str_sz)
2376 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002377 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002378}
2379
2380template <class _CharT, class _Traits, class _Allocator>
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002381inline _LIBCPP_INLINE_VISIBILITY
2382basic_string<_CharT, _Traits, _Allocator>&
2383basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, __self_view __sv,
2384 size_type __pos2, size_type __n)
2385{
2386 size_type __str_sz = __sv.size();
2387 if (__pos2 > __str_sz)
2388 this->__throw_out_of_range();
2389 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2390}
2391
2392template <class _CharT, class _Traits, class _Allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002393basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002394basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002395{
Alp Tokerec34c482014-05-15 11:27:39 +00002396 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002397 return insert(__pos, __s, traits_type::length(__s));
2398}
2399
2400template <class _CharT, class _Traits, class _Allocator>
2401typename basic_string<_CharT, _Traits, _Allocator>::iterator
2402basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2403{
2404 size_type __ip = static_cast<size_type>(__pos - begin());
2405 size_type __sz = size();
2406 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002407 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002408 if (__cap == __sz)
2409 {
2410 __grow_by(__cap, 1, __sz, __ip, 0, 1);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002411 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002412 }
2413 else
2414 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002415 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002416 size_type __n_move = __sz - __ip;
2417 if (__n_move != 0)
2418 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2419 }
2420 traits_type::assign(__p[__ip], __c);
2421 traits_type::assign(__p[++__sz], value_type());
2422 __set_size(__sz);
2423 return begin() + static_cast<difference_type>(__ip);
2424}
2425
2426template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002427inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002428typename basic_string<_CharT, _Traits, _Allocator>::iterator
2429basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2430{
Howard Hinnant499cea12013-08-23 17:37:05 +00002431#if _LIBCPP_DEBUG_LEVEL >= 2
2432 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2433 "string::insert(iterator, n, value) called with an iterator not"
2434 " referring to this string");
2435#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002436 difference_type __p = __pos - begin();
2437 insert(static_cast<size_type>(__p), __n, __c);
2438 return begin() + __p;
2439}
2440
2441// replace
2442
2443template <class _CharT, class _Traits, class _Allocator>
2444basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002445basic_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 +00002446{
Alp Tokerec34c482014-05-15 11:27:39 +00002447 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002448 size_type __sz = size();
2449 if (__pos > __sz)
2450 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002451 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002452 size_type __cap = capacity();
2453 if (__cap - __sz + __n1 >= __n2)
2454 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002455 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002456 if (__n1 != __n2)
2457 {
2458 size_type __n_move = __sz - __pos - __n1;
2459 if (__n_move != 0)
2460 {
2461 if (__n1 > __n2)
2462 {
2463 traits_type::move(__p + __pos, __s, __n2);
2464 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2465 goto __finish;
2466 }
2467 if (__p + __pos < __s && __s < __p + __sz)
2468 {
2469 if (__p + __pos + __n1 <= __s)
2470 __s += __n2 - __n1;
2471 else // __p + __pos < __s < __p + __pos + __n1
2472 {
2473 traits_type::move(__p + __pos, __s, __n1);
2474 __pos += __n1;
2475 __s += __n2;
2476 __n2 -= __n1;
2477 __n1 = 0;
2478 }
2479 }
2480 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2481 }
2482 }
2483 traits_type::move(__p + __pos, __s, __n2);
2484__finish:
2485 __sz += __n2 - __n1;
2486 __set_size(__sz);
2487 __invalidate_iterators_past(__sz);
2488 traits_type::assign(__p[__sz], value_type());
2489 }
2490 else
2491 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2492 return *this;
2493}
2494
2495template <class _CharT, class _Traits, class _Allocator>
2496basic_string<_CharT, _Traits, _Allocator>&
2497basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
2498{
2499 size_type __sz = size();
2500 if (__pos > __sz)
2501 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002502 __n1 = _VSTD::min(__n1, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002503 size_type __cap = capacity();
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002504 value_type* __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002505 if (__cap - __sz + __n1 >= __n2)
2506 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002507 __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002508 if (__n1 != __n2)
2509 {
2510 size_type __n_move = __sz - __pos - __n1;
2511 if (__n_move != 0)
2512 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2513 }
2514 }
2515 else
2516 {
2517 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002518 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002519 }
2520 traits_type::assign(__p + __pos, __n2, __c);
2521 __sz += __n2 - __n1;
2522 __set_size(__sz);
2523 __invalidate_iterators_past(__sz);
2524 traits_type::assign(__p[__sz], value_type());
2525 return *this;
2526}
2527
2528template <class _CharT, class _Traits, class _Allocator>
2529template<class _InputIterator>
2530typename enable_if
2531<
2532 __is_input_iterator<_InputIterator>::value,
2533 basic_string<_CharT, _Traits, _Allocator>&
2534>::type
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002535basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002536 _InputIterator __j1, _InputIterator __j2)
2537{
Marshall Clowdf9db312016-01-13 21:54:34 +00002538 basic_string __temp(__j1, __j2, __alloc());
2539 return this->replace(__i1, __i2, __temp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002540}
2541
2542template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002543inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002544basic_string<_CharT, _Traits, _Allocator>&
2545basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2546{
2547 return replace(__pos1, __n1, __str.data(), __str.size());
2548}
2549
2550template <class _CharT, class _Traits, class _Allocator>
2551basic_string<_CharT, _Traits, _Allocator>&
2552basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2553 size_type __pos2, size_type __n2)
2554{
2555 size_type __str_sz = __str.size();
2556 if (__pos2 > __str_sz)
2557 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002558 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002559}
2560
2561template <class _CharT, class _Traits, class _Allocator>
2562basic_string<_CharT, _Traits, _Allocator>&
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002563basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, __self_view __sv,
2564 size_type __pos2, size_type __n2)
2565{
2566 size_type __str_sz = __sv.size();
2567 if (__pos2 > __str_sz)
2568 this->__throw_out_of_range();
2569 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2570}
2571
2572template <class _CharT, class _Traits, class _Allocator>
2573basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002574basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002575{
Alp Tokerec34c482014-05-15 11:27:39 +00002576 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002577 return replace(__pos, __n1, __s, traits_type::length(__s));
2578}
2579
2580template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002581inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002582basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002583basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002584{
2585 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2586 __str.data(), __str.size());
2587}
2588
2589template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002590inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002591basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002592basic_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 +00002593{
2594 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2595}
2596
2597template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002598inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002599basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002600basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002601{
2602 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2603}
2604
2605template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002606inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002607basic_string<_CharT, _Traits, _Allocator>&
Howard Hinnant7b2cb482010-11-17 21:11:40 +00002608basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002609{
2610 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2611}
2612
2613// erase
2614
2615template <class _CharT, class _Traits, class _Allocator>
2616basic_string<_CharT, _Traits, _Allocator>&
2617basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2618{
2619 size_type __sz = size();
2620 if (__pos > __sz)
2621 this->__throw_out_of_range();
2622 if (__n)
2623 {
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002624 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
Howard Hinnant0949eed2011-06-30 21:18:19 +00002625 __n = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002626 size_type __n_move = __sz - __pos - __n;
2627 if (__n_move != 0)
2628 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2629 __sz -= __n;
2630 __set_size(__sz);
2631 __invalidate_iterators_past(__sz);
2632 traits_type::assign(__p[__sz], value_type());
2633 }
2634 return *this;
2635}
2636
2637template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002638inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002639typename basic_string<_CharT, _Traits, _Allocator>::iterator
2640basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2641{
Howard Hinnant499cea12013-08-23 17:37:05 +00002642#if _LIBCPP_DEBUG_LEVEL >= 2
2643 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2644 "string::erase(iterator) called with an iterator not"
2645 " referring to this string");
2646#endif
2647 _LIBCPP_ASSERT(__pos != end(),
2648 "string::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002649 iterator __b = begin();
2650 size_type __r = static_cast<size_type>(__pos - __b);
2651 erase(__r, 1);
Howard Hinnantec3773c2011-12-01 20:21:04 +00002652 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002653}
2654
2655template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002656inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002657typename basic_string<_CharT, _Traits, _Allocator>::iterator
2658basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
2659{
Howard Hinnant499cea12013-08-23 17:37:05 +00002660#if _LIBCPP_DEBUG_LEVEL >= 2
2661 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
2662 "string::erase(iterator, iterator) called with an iterator not"
2663 " referring to this string");
2664#endif
2665 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002666 iterator __b = begin();
2667 size_type __r = static_cast<size_type>(__first - __b);
2668 erase(__r, static_cast<size_type>(__last - __first));
Howard Hinnantec3773c2011-12-01 20:21:04 +00002669 return __b + static_cast<difference_type>(__r);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002670}
2671
2672template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002673inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002674void
2675basic_string<_CharT, _Traits, _Allocator>::pop_back()
2676{
Howard Hinnant499cea12013-08-23 17:37:05 +00002677 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002678 size_type __sz;
2679 if (__is_long())
2680 {
2681 __sz = __get_long_size() - 1;
2682 __set_long_size(__sz);
2683 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
2684 }
2685 else
2686 {
2687 __sz = __get_short_size() - 1;
2688 __set_short_size(__sz);
2689 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
2690 }
2691 __invalidate_iterators_past(__sz);
2692}
2693
2694template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002695inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002696void
Howard Hinnanta6119a82011-05-29 19:57:12 +00002697basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002698{
2699 __invalidate_all_iterators();
2700 if (__is_long())
2701 {
2702 traits_type::assign(*__get_long_pointer(), value_type());
2703 __set_long_size(0);
2704 }
2705 else
2706 {
2707 traits_type::assign(*__get_short_pointer(), value_type());
2708 __set_short_size(0);
2709 }
2710}
2711
2712template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002713inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002714void
2715basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
2716{
2717 if (__is_long())
2718 {
2719 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
2720 __set_long_size(__pos);
2721 }
2722 else
2723 {
2724 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
2725 __set_short_size(__pos);
2726 }
2727 __invalidate_iterators_past(__pos);
2728}
2729
2730template <class _CharT, class _Traits, class _Allocator>
2731void
2732basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
2733{
2734 size_type __sz = size();
2735 if (__n > __sz)
2736 append(__n - __sz, __c);
2737 else
2738 __erase_to_end(__n);
2739}
2740
2741template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002742inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002743typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00002744basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002745{
Howard Hinnante32b5e22010-11-17 17:55:08 +00002746 size_type __m = __alloc_traits::max_size(__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002747#if _LIBCPP_BIG_ENDIAN
Marshall Clow09f85502013-10-31 17:23:08 +00002748 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002749#else
Marshall Clow09f85502013-10-31 17:23:08 +00002750 return __m - __alignment;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002751#endif
2752}
2753
2754template <class _CharT, class _Traits, class _Allocator>
2755void
2756basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
2757{
2758 if (__res_arg > max_size())
2759 this->__throw_length_error();
2760 size_type __cap = capacity();
2761 size_type __sz = size();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002762 __res_arg = _VSTD::max(__res_arg, __sz);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002763 __res_arg = __recommend(__res_arg);
2764 if (__res_arg != __cap)
2765 {
2766 pointer __new_data, __p;
2767 bool __was_long, __now_long;
2768 if (__res_arg == __min_cap - 1)
2769 {
2770 __was_long = true;
2771 __now_long = false;
2772 __new_data = __get_short_pointer();
2773 __p = __get_long_pointer();
2774 }
2775 else
2776 {
2777 if (__res_arg > __cap)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002778 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002779 else
2780 {
2781 #ifndef _LIBCPP_NO_EXCEPTIONS
2782 try
2783 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002784 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante32b5e22010-11-17 17:55:08 +00002785 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002786 #ifndef _LIBCPP_NO_EXCEPTIONS
2787 }
2788 catch (...)
2789 {
2790 return;
2791 }
Howard Hinnant324bb032010-08-22 00:02:43 +00002792 #else // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002793 if (__new_data == nullptr)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002794 return;
Howard Hinnant324bb032010-08-22 00:02:43 +00002795 #endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002796 }
2797 __now_long = true;
2798 __was_long = __is_long();
2799 __p = __get_pointer();
2800 }
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002801 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
2802 _VSTD::__to_raw_pointer(__p), size()+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002803 if (__was_long)
Howard Hinnante32b5e22010-11-17 17:55:08 +00002804 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002805 if (__now_long)
2806 {
2807 __set_long_cap(__res_arg+1);
2808 __set_long_size(__sz);
2809 __set_long_pointer(__new_data);
2810 }
2811 else
2812 __set_short_size(__sz);
2813 __invalidate_all_iterators();
2814 }
2815}
2816
2817template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002818inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002819typename basic_string<_CharT, _Traits, _Allocator>::const_reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002820basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002821{
Howard Hinnant499cea12013-08-23 17:37:05 +00002822 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002823 return *(data() + __pos);
2824}
2825
2826template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002827inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002828typename basic_string<_CharT, _Traits, _Allocator>::reference
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002829basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002830{
Howard Hinnant499cea12013-08-23 17:37:05 +00002831 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002832 return *(__get_pointer() + __pos);
2833}
2834
2835template <class _CharT, class _Traits, class _Allocator>
2836typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2837basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
2838{
2839 if (__n >= size())
2840 this->__throw_out_of_range();
2841 return (*this)[__n];
2842}
2843
2844template <class _CharT, class _Traits, class _Allocator>
2845typename basic_string<_CharT, _Traits, _Allocator>::reference
2846basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
2847{
2848 if (__n >= size())
2849 this->__throw_out_of_range();
2850 return (*this)[__n];
2851}
2852
2853template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002854inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002855typename basic_string<_CharT, _Traits, _Allocator>::reference
2856basic_string<_CharT, _Traits, _Allocator>::front()
2857{
Howard Hinnant499cea12013-08-23 17:37:05 +00002858 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002859 return *__get_pointer();
2860}
2861
2862template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002863inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002864typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2865basic_string<_CharT, _Traits, _Allocator>::front() const
2866{
Howard Hinnant499cea12013-08-23 17:37:05 +00002867 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002868 return *data();
2869}
2870
2871template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002872inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002873typename basic_string<_CharT, _Traits, _Allocator>::reference
2874basic_string<_CharT, _Traits, _Allocator>::back()
2875{
Howard Hinnant499cea12013-08-23 17:37:05 +00002876 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002877 return *(__get_pointer() + size() - 1);
2878}
2879
2880template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002881inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002882typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2883basic_string<_CharT, _Traits, _Allocator>::back() const
2884{
Howard Hinnant499cea12013-08-23 17:37:05 +00002885 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002886 return *(data() + size() - 1);
2887}
2888
2889template <class _CharT, class _Traits, class _Allocator>
2890typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002891basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002892{
2893 size_type __sz = size();
2894 if (__pos > __sz)
2895 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00002896 size_type __rlen = _VSTD::min(__n, __sz - __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002897 traits_type::copy(__s, data() + __pos, __rlen);
2898 return __rlen;
2899}
2900
2901template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002902inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002903basic_string<_CharT, _Traits, _Allocator>
2904basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
2905{
2906 return basic_string(*this, __pos, __n, __alloc());
2907}
2908
2909template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002910inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002911void
2912basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
Marshall Clow7d914d12015-07-13 20:04:56 +00002913#if _LIBCPP_STD_VER >= 14
2914 _NOEXCEPT
2915#else
2916 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2917 __is_nothrow_swappable<allocator_type>::value)
2918#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002919{
Howard Hinnant499cea12013-08-23 17:37:05 +00002920#if _LIBCPP_DEBUG_LEVEL >= 2
2921 if (!__is_long())
2922 __get_db()->__invalidate_all(this);
2923 if (!__str.__is_long())
2924 __get_db()->__invalidate_all(&__str);
2925 __get_db()->swap(this, &__str);
2926#endif
Howard Hinnant0949eed2011-06-30 21:18:19 +00002927 _VSTD::swap(__r_.first(), __str.__r_.first());
Marshall Clow7d914d12015-07-13 20:04:56 +00002928 __swap_allocator(__alloc(), __str.__alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002929}
2930
2931// find
2932
2933template <class _Traits>
2934struct _LIBCPP_HIDDEN __traits_eq
2935{
2936 typedef typename _Traits::char_type char_type;
Howard Hinnanta6119a82011-05-29 19:57:12 +00002937 _LIBCPP_INLINE_VISIBILITY
2938 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
2939 {return _Traits::eq(__x, __y);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002940};
2941
2942template<class _CharT, class _Traits, class _Allocator>
2943typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002944basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00002945 size_type __pos,
2946 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002947{
Alp Tokerec34c482014-05-15 11:27:39 +00002948 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002949 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00002950 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002951}
2952
2953template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002954inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002955typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00002956basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
2957 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002958{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002959 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00002960 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002961}
2962
2963template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00002964inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002965typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002966basic_string<_CharT, _Traits, _Allocator>::find(__self_view __sv,
2967 size_type __pos) const _NOEXCEPT
2968{
2969 return __str_find<value_type, size_type, traits_type, npos>
2970 (data(), size(), __sv.data(), __pos, __sv.size());
2971}
2972
2973template<class _CharT, class _Traits, class _Allocator>
2974inline _LIBCPP_INLINE_VISIBILITY
2975typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002976basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00002977 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002978{
Alp Tokerec34c482014-05-15 11:27:39 +00002979 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002980 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00002981 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002982}
2983
2984template<class _CharT, class _Traits, class _Allocator>
2985typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00002986basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
2987 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002988{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00002989 return __str_find<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00002990 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002991}
2992
2993// rfind
2994
2995template<class _CharT, class _Traits, class _Allocator>
2996typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00002997basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00002998 size_type __pos,
2999 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003000{
Alp Tokerec34c482014-05-15 11:27:39 +00003001 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003002 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003003 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003004}
3005
3006template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003007inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003008typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003009basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3010 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003011{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003012 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003013 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003014}
3015
3016template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003017inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003018typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003019basic_string<_CharT, _Traits, _Allocator>::rfind(__self_view __sv,
3020 size_type __pos) const _NOEXCEPT
3021{
3022 return __str_rfind<value_type, size_type, traits_type, npos>
3023 (data(), size(), __sv.data(), __pos, __sv.size());
3024}
3025
3026template<class _CharT, class _Traits, class _Allocator>
3027inline _LIBCPP_INLINE_VISIBILITY
3028typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003029basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003030 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003031{
Alp Tokerec34c482014-05-15 11:27:39 +00003032 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003033 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003034 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003035}
3036
3037template<class _CharT, class _Traits, class _Allocator>
3038typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003039basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3040 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003041{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003042 return __str_rfind<value_type, size_type, traits_type, npos>
Marshall Clow360f3192014-06-02 02:22:49 +00003043 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003044}
3045
3046// find_first_of
3047
3048template<class _CharT, class _Traits, class _Allocator>
3049typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003050basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003051 size_type __pos,
3052 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003053{
Alp Tokerec34c482014-05-15 11:27:39 +00003054 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003055 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003056 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003057}
3058
3059template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003060inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003061typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003062basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3063 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003064{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003065 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003066 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003067}
3068
3069template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003070inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003071typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003072basic_string<_CharT, _Traits, _Allocator>::find_first_of(__self_view __sv,
3073 size_type __pos) const _NOEXCEPT
3074{
3075 return __str_find_first_of<value_type, size_type, traits_type, npos>
3076 (data(), size(), __sv.data(), __pos, __sv.size());
3077}
3078
3079template<class _CharT, class _Traits, class _Allocator>
3080inline _LIBCPP_INLINE_VISIBILITY
3081typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003082basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003083 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003084{
Alp Tokerec34c482014-05-15 11:27:39 +00003085 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003086 return __str_find_first_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003087 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003088}
3089
3090template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003091inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003092typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003093basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3094 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003095{
3096 return find(__c, __pos);
3097}
3098
3099// find_last_of
3100
3101template<class _CharT, class _Traits, class _Allocator>
3102typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003103basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003104 size_type __pos,
3105 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003106{
Alp Tokerec34c482014-05-15 11:27:39 +00003107 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003108 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003109 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003110}
3111
3112template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003113inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003114typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003115basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3116 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003117{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003118 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003119 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003120}
3121
3122template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003123inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003124typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003125basic_string<_CharT, _Traits, _Allocator>::find_last_of(__self_view __sv,
3126 size_type __pos) const _NOEXCEPT
3127{
3128 return __str_find_last_of<value_type, size_type, traits_type, npos>
3129 (data(), size(), __sv.data(), __pos, __sv.size());
3130}
3131
3132template<class _CharT, class _Traits, class _Allocator>
3133inline _LIBCPP_INLINE_VISIBILITY
3134typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003135basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003136 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003137{
Alp Tokerec34c482014-05-15 11:27:39 +00003138 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003139 return __str_find_last_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003140 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003141}
3142
3143template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003144inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003145typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003146basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3147 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003148{
3149 return rfind(__c, __pos);
3150}
3151
3152// find_first_not_of
3153
3154template<class _CharT, class _Traits, class _Allocator>
3155typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003156basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003157 size_type __pos,
3158 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003159{
Alp Tokerec34c482014-05-15 11:27:39 +00003160 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003161 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003162 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003163}
3164
3165template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003166inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003167typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003168basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3169 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003170{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003171 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003172 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003173}
3174
3175template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003176inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003177typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003178basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(__self_view __sv,
3179 size_type __pos) const _NOEXCEPT
3180{
3181 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3182 (data(), size(), __sv.data(), __pos, __sv.size());
3183}
3184
3185template<class _CharT, class _Traits, class _Allocator>
3186inline _LIBCPP_INLINE_VISIBILITY
3187typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003188basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003189 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003190{
Alp Tokerec34c482014-05-15 11:27:39 +00003191 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003192 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003193 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003194}
3195
3196template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003197inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003198typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003199basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3200 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003201{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003202 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003203 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003204}
3205
3206// find_last_not_of
3207
3208template<class _CharT, class _Traits, class _Allocator>
3209typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003210basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003211 size_type __pos,
3212 size_type __n) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003213{
Alp Tokerec34c482014-05-15 11:27:39 +00003214 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003215 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003216 (data(), size(), __s, __pos, __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003217}
3218
3219template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003220inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003221typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003222basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3223 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003224{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003225 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003226 (data(), size(), __str.data(), __pos, __str.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003227}
3228
3229template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003230inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003231typename basic_string<_CharT, _Traits, _Allocator>::size_type
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003232basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(__self_view __sv,
3233 size_type __pos) const _NOEXCEPT
3234{
3235 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3236 (data(), size(), __sv.data(), __pos, __sv.size());
3237}
3238
3239template<class _CharT, class _Traits, class _Allocator>
3240inline _LIBCPP_INLINE_VISIBILITY
3241typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003242basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003243 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003244{
Alp Tokerec34c482014-05-15 11:27:39 +00003245 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003246 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003247 (data(), size(), __s, __pos, traits_type::length(__s));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003248}
3249
3250template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003251inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003252typename basic_string<_CharT, _Traits, _Allocator>::size_type
Howard Hinnanta6119a82011-05-29 19:57:12 +00003253basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3254 size_type __pos) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003255{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003256 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
Marshall Clow8eb5acc2014-02-16 01:57:26 +00003257 (data(), size(), __c, __pos);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003258}
3259
3260// compare
3261
3262template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003263inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003264int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003265basic_string<_CharT, _Traits, _Allocator>::compare(__self_view __sv) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003266{
Howard Hinnantfa06d752011-07-24 21:45:06 +00003267 size_t __lhs_sz = size();
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003268 size_t __rhs_sz = __sv.size();
3269 int __result = traits_type::compare(data(), __sv.data(),
Howard Hinnantfa06d752011-07-24 21:45:06 +00003270 _VSTD::min(__lhs_sz, __rhs_sz));
3271 if (__result != 0)
3272 return __result;
3273 if (__lhs_sz < __rhs_sz)
3274 return -1;
3275 if (__lhs_sz > __rhs_sz)
3276 return 1;
3277 return 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003278}
3279
3280template <class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003281inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003282int
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003283basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003284{
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003285 return compare(__self_view(__str));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003286}
3287
3288template <class _CharT, class _Traits, class _Allocator>
3289int
Howard Hinnanta6119a82011-05-29 19:57:12 +00003290basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3291 size_type __n1,
Howard Hinnant9dcdcde2013-06-28 16:59:19 +00003292 const value_type* __s,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003293 size_type __n2) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003294{
Alp Tokerec34c482014-05-15 11:27:39 +00003295 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003296 size_type __sz = size();
3297 if (__pos1 > __sz || __n2 == npos)
3298 this->__throw_out_of_range();
Howard Hinnant0949eed2011-06-30 21:18:19 +00003299 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3300 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003301 if (__r == 0)
3302 {
3303 if (__rlen < __n2)
3304 __r = -1;
3305 else if (__rlen > __n2)
3306 __r = 1;
3307 }
3308 return __r;
3309}
3310
Marshall Clow1e00d6d2016-07-21 05:31:24 +00003311template <class _CharT, class _Traits, class _Allocator>
3312inline _LIBCPP_INLINE_VISIBILITY
3313int
3314basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3315 size_type __n1,
3316 __self_view __sv) const
3317{
3318 return compare(__pos1, __n1, __sv.data(), __sv.size());
3319}
3320
3321template <class _CharT, class _Traits, class _Allocator>
3322inline _LIBCPP_INLINE_VISIBILITY
3323int
3324basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3325 size_type __n1,
3326 const basic_string& __str) const
3327{
3328 return compare(__pos1, __n1, __str.data(), __str.size());
3329}
3330
3331template <class _CharT, class _Traits, class _Allocator>
3332int inline _LIBCPP_INLINE_VISIBILITY
3333basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3334 size_type __n1,
3335 __self_view __sv,
3336 size_type __pos2,
3337 size_type __n2) const
3338{
3339 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3340}
3341
3342template <class _CharT, class _Traits, class _Allocator>
3343int
3344basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3345 size_type __n1,
3346 const basic_string& __str,
3347 size_type __pos2,
3348 size_type __n2) const
3349{
3350 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3351}
3352
3353template <class _CharT, class _Traits, class _Allocator>
3354int
3355basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3356{
3357 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3358 return compare(0, npos, __s, traits_type::length(__s));
3359}
3360
3361template <class _CharT, class _Traits, class _Allocator>
3362int
3363basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3364 size_type __n1,
3365 const value_type* __s) const
3366{
3367 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3368 return compare(__pos1, __n1, __s, traits_type::length(__s));
3369}
3370
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003371// __invariants
3372
3373template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003374inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003375bool
3376basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3377{
3378 if (size() > capacity())
3379 return false;
3380 if (capacity() < __min_cap - 1)
3381 return false;
3382 if (data() == 0)
3383 return false;
3384 if (data()[size()] != value_type(0))
3385 return false;
3386 return true;
3387}
3388
3389// operator==
3390
3391template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003392inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003393bool
3394operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003395 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003396{
Howard Hinnant08dd2532013-04-22 23:55:13 +00003397 size_t __lhs_sz = __lhs.size();
3398 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3399 __rhs.data(),
3400 __lhs_sz) == 0;
3401}
3402
3403template<class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003404inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant08dd2532013-04-22 23:55:13 +00003405bool
3406operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3407 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3408{
3409 size_t __lhs_sz = __lhs.size();
3410 if (__lhs_sz != __rhs.size())
3411 return false;
3412 const char* __lp = __lhs.data();
3413 const char* __rp = __rhs.data();
3414 if (__lhs.__is_long())
3415 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3416 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3417 if (*__lp != *__rp)
3418 return false;
3419 return true;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003420}
3421
3422template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003423inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003424bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003425operator==(const _CharT* __lhs,
3426 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003427{
Eric Fiselier4f241822015-08-28 03:02:37 +00003428 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3429 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3430 size_t __lhs_len = _Traits::length(__lhs);
3431 if (__lhs_len != __rhs.size()) return false;
3432 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003433}
3434
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003435template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003436inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003437bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003438operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3439 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003440{
Eric Fiselier4f241822015-08-28 03:02:37 +00003441 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3442 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3443 size_t __rhs_len = _Traits::length(__rhs);
3444 if (__rhs_len != __lhs.size()) return false;
3445 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003446}
3447
Howard Hinnant324bb032010-08-22 00:02:43 +00003448template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003449inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003450bool
3451operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003452 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003453{
3454 return !(__lhs == __rhs);
3455}
3456
3457template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003458inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003459bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003460operator!=(const _CharT* __lhs,
3461 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003462{
3463 return !(__lhs == __rhs);
3464}
3465
3466template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003467inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003468bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003469operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3470 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003471{
3472 return !(__lhs == __rhs);
3473}
3474
3475// operator<
3476
3477template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003478inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003479bool
3480operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003481 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003482{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003483 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003484}
3485
3486template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003487inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003488bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003489operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3490 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003491{
Howard Hinnant2644a7b2011-07-24 15:07:21 +00003492 return __lhs.compare(__rhs) < 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003493}
3494
3495template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003496inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003497bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003498operator< (const _CharT* __lhs,
3499 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003500{
3501 return __rhs.compare(__lhs) > 0;
3502}
3503
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003504// operator>
3505
3506template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003507inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003508bool
3509operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003510 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003511{
3512 return __rhs < __lhs;
3513}
3514
3515template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003516inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003517bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003518operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3519 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003520{
3521 return __rhs < __lhs;
3522}
3523
3524template<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
Howard Hinnanta6119a82011-05-29 19:57:12 +00003527operator> (const _CharT* __lhs,
3528 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003529{
3530 return __rhs < __lhs;
3531}
3532
3533// operator<=
3534
3535template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003536inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003537bool
3538operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003539 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003540{
3541 return !(__rhs < __lhs);
3542}
3543
3544template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003545inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003546bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003547operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3548 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003549{
3550 return !(__rhs < __lhs);
3551}
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
Howard Hinnanta6119a82011-05-29 19:57:12 +00003556operator<=(const _CharT* __lhs,
3557 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003558{
3559 return !(__rhs < __lhs);
3560}
3561
3562// operator>=
3563
3564template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003565inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003566bool
3567operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnanta6119a82011-05-29 19:57:12 +00003568 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003569{
3570 return !(__lhs < __rhs);
3571}
3572
3573template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003574inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003575bool
Howard Hinnanta6119a82011-05-29 19:57:12 +00003576operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3577 const _CharT* __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003578{
3579 return !(__lhs < __rhs);
3580}
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
Howard Hinnanta6119a82011-05-29 19:57:12 +00003585operator>=(const _CharT* __lhs,
3586 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003587{
3588 return !(__lhs < __rhs);
3589}
3590
3591// operator +
3592
3593template<class _CharT, class _Traits, class _Allocator>
3594basic_string<_CharT, _Traits, _Allocator>
3595operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3596 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3597{
3598 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3599 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3600 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3601 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3602 __r.append(__rhs.data(), __rhs_sz);
3603 return __r;
3604}
3605
3606template<class _CharT, class _Traits, class _Allocator>
3607basic_string<_CharT, _Traits, _Allocator>
3608operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3609{
3610 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3611 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
3612 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3613 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
3614 __r.append(__rhs.data(), __rhs_sz);
3615 return __r;
3616}
3617
3618template<class _CharT, class _Traits, class _Allocator>
3619basic_string<_CharT, _Traits, _Allocator>
3620operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3621{
3622 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3623 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3624 __r.__init(&__lhs, 1, 1 + __rhs_sz);
3625 __r.append(__rhs.data(), __rhs_sz);
3626 return __r;
3627}
3628
3629template<class _CharT, class _Traits, class _Allocator>
3630basic_string<_CharT, _Traits, _Allocator>
3631operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
3632{
3633 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3634 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3635 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
3636 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3637 __r.append(__rhs, __rhs_sz);
3638 return __r;
3639}
3640
3641template<class _CharT, class _Traits, class _Allocator>
3642basic_string<_CharT, _Traits, _Allocator>
3643operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
3644{
3645 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3646 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3647 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
3648 __r.push_back(__rhs);
3649 return __r;
3650}
3651
Howard Hinnant73d21a42010-09-04 23:28:19 +00003652#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003653
3654template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003655inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003656basic_string<_CharT, _Traits, _Allocator>
3657operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3658{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003659 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003660}
3661
3662template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003663inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003664basic_string<_CharT, _Traits, _Allocator>
3665operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3666{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003667 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003668}
3669
3670template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003671inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003672basic_string<_CharT, _Traits, _Allocator>
3673operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3674{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003675 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003676}
3677
3678template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003679inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003680basic_string<_CharT, _Traits, _Allocator>
3681operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3682{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003683 return _VSTD::move(__rhs.insert(0, __lhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003684}
3685
3686template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003687inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003688basic_string<_CharT, _Traits, _Allocator>
3689operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3690{
3691 __rhs.insert(__rhs.begin(), __lhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003692 return _VSTD::move(__rhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003693}
3694
3695template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003696inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003697basic_string<_CharT, _Traits, _Allocator>
3698operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
3699{
Howard Hinnant0949eed2011-06-30 21:18:19 +00003700 return _VSTD::move(__lhs.append(__rhs));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003701}
3702
3703template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003704inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003705basic_string<_CharT, _Traits, _Allocator>
3706operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
3707{
3708 __lhs.push_back(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +00003709 return _VSTD::move(__lhs);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003710}
3711
Howard Hinnant73d21a42010-09-04 23:28:19 +00003712#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003713
3714// swap
3715
3716template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant1e564242013-10-04 22:09:00 +00003717inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003718void
Howard Hinnanta6119a82011-05-29 19:57:12 +00003719swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
Howard Hinnant53f7d4c2011-06-03 18:40:47 +00003720 basic_string<_CharT, _Traits, _Allocator>& __rhs)
3721 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003722{
3723 __lhs.swap(__rhs);
3724}
3725
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003726#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
3727
3728typedef basic_string<char16_t> u16string;
3729typedef basic_string<char32_t> u32string;
3730
Howard Hinnant324bb032010-08-22 00:02:43 +00003731#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003732
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003733_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
3734_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
3735_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
3736_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
3737_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003738
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003739_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
3740_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
3741_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003742
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003743_LIBCPP_FUNC_VIS string to_string(int __val);
3744_LIBCPP_FUNC_VIS string to_string(unsigned __val);
3745_LIBCPP_FUNC_VIS string to_string(long __val);
3746_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
3747_LIBCPP_FUNC_VIS string to_string(long long __val);
3748_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
3749_LIBCPP_FUNC_VIS string to_string(float __val);
3750_LIBCPP_FUNC_VIS string to_string(double __val);
3751_LIBCPP_FUNC_VIS string to_string(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003752
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003753_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
3754_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
3755_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
3756_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
3757_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003758
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003759_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
3760_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
3761_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003762
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003763_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
3764_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
3765_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
3766_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
3767_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
3768_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
3769_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
3770_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
3771_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
Howard Hinnanta6a062d2010-06-02 18:20:39 +00003772
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003773template<class _CharT, class _Traits, class _Allocator>
3774 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
3775 basic_string<_CharT, _Traits, _Allocator>::npos;
3776
3777template<class _CharT, class _Traits, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003778struct _LIBCPP_TYPE_VIS_ONLY hash<basic_string<_CharT, _Traits, _Allocator> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003779 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
3780{
3781 size_t
Howard Hinnanta6119a82011-05-29 19:57:12 +00003782 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003783};
3784
3785template<class _CharT, class _Traits, class _Allocator>
3786size_t
3787hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
Howard Hinnanta6119a82011-05-29 19:57:12 +00003788 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003789{
Sean Huntaffd9e52011-07-29 23:31:56 +00003790 return __do_string_hash(__val.data(), __val.data() + __val.size());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003791}
3792
Howard Hinnant464aa5c2011-07-18 15:51:59 +00003793template<class _CharT, class _Traits, class _Allocator>
3794basic_ostream<_CharT, _Traits>&
3795operator<<(basic_ostream<_CharT, _Traits>& __os,
3796 const basic_string<_CharT, _Traits, _Allocator>& __str);
3797
3798template<class _CharT, class _Traits, class _Allocator>
3799basic_istream<_CharT, _Traits>&
3800operator>>(basic_istream<_CharT, _Traits>& __is,
3801 basic_string<_CharT, _Traits, _Allocator>& __str);
3802
3803template<class _CharT, class _Traits, class _Allocator>
3804basic_istream<_CharT, _Traits>&
3805getline(basic_istream<_CharT, _Traits>& __is,
3806 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3807
3808template<class _CharT, class _Traits, class _Allocator>
3809inline _LIBCPP_INLINE_VISIBILITY
3810basic_istream<_CharT, _Traits>&
3811getline(basic_istream<_CharT, _Traits>& __is,
3812 basic_string<_CharT, _Traits, _Allocator>& __str);
3813
3814#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3815
3816template<class _CharT, class _Traits, class _Allocator>
3817inline _LIBCPP_INLINE_VISIBILITY
3818basic_istream<_CharT, _Traits>&
3819getline(basic_istream<_CharT, _Traits>&& __is,
3820 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3821
3822template<class _CharT, class _Traits, class _Allocator>
3823inline _LIBCPP_INLINE_VISIBILITY
3824basic_istream<_CharT, _Traits>&
3825getline(basic_istream<_CharT, _Traits>&& __is,
3826 basic_string<_CharT, _Traits, _Allocator>& __str);
3827
3828#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3829
Howard Hinnant499cea12013-08-23 17:37:05 +00003830#if _LIBCPP_DEBUG_LEVEL >= 2
3831
3832template<class _CharT, class _Traits, class _Allocator>
3833bool
3834basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
3835{
3836 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
3837 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
3838}
3839
3840template<class _CharT, class _Traits, class _Allocator>
3841bool
3842basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
3843{
3844 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
3845 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
3846}
3847
3848template<class _CharT, class _Traits, class _Allocator>
3849bool
3850basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
3851{
3852 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
3853 return this->data() <= __p && __p <= this->data() + this->size();
3854}
3855
3856template<class _CharT, class _Traits, class _Allocator>
3857bool
3858basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
3859{
3860 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
3861 return this->data() <= __p && __p < this->data() + this->size();
3862}
3863
3864#endif // _LIBCPP_DEBUG_LEVEL >= 2
3865
Marshall Clow15234322013-07-23 17:05:24 +00003866#if _LIBCPP_STD_VER > 11
3867// Literal suffixes for basic_string [basic.string.literals]
Marshall Clow8d9dd7a2013-10-05 21:18:32 +00003868inline namespace literals
Marshall Clow15234322013-07-23 17:05:24 +00003869{
3870 inline namespace string_literals
3871 {
Howard Hinnantab61b2c2013-08-07 19:39:48 +00003872 inline _LIBCPP_INLINE_VISIBILITY
3873 basic_string<char> operator "" s( const char *__str, size_t __len )
3874 {
3875 return basic_string<char> (__str, __len);
3876 }
Marshall Clow15234322013-07-23 17:05:24 +00003877
Howard Hinnantab61b2c2013-08-07 19:39:48 +00003878 inline _LIBCPP_INLINE_VISIBILITY
3879 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
3880 {
3881 return basic_string<wchar_t> (__str, __len);
3882 }
Marshall Clow15234322013-07-23 17:05:24 +00003883
Howard Hinnantab61b2c2013-08-07 19:39:48 +00003884 inline _LIBCPP_INLINE_VISIBILITY
3885 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
3886 {
3887 return basic_string<char16_t> (__str, __len);
3888 }
Marshall Clow15234322013-07-23 17:05:24 +00003889
Howard Hinnantab61b2c2013-08-07 19:39:48 +00003890 inline _LIBCPP_INLINE_VISIBILITY
3891 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
3892 {
3893 return basic_string<char32_t> (__str, __len);
3894 }
Marshall Clow15234322013-07-23 17:05:24 +00003895 }
3896}
3897#endif
3898
Howard Hinnant0f678bd2013-08-12 18:38:34 +00003899_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<char>)
3900_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<wchar_t>)
Howard Hinnant499cea12013-08-23 17:37:05 +00003901_LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00003902
3903_LIBCPP_END_NAMESPACE_STD
3904
3905#endif // _LIBCPP_STRING