Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===--------------------------- string -----------------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
| 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 | |
| 17 | namespace std |
| 18 | { |
| 19 | |
| 20 | template <class stateT> |
| 21 | class fpos |
| 22 | { |
| 23 | private: |
| 24 | stateT st; |
| 25 | public: |
| 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 | |
| 39 | template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y); |
| 40 | |
| 41 | template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y); |
| 42 | template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y); |
| 43 | |
| 44 | template <class charT> |
| 45 | struct 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 Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 53 | static void assign(char_type& c1, const char_type& c2) noexcept; |
Howard Hinnant | 03d7181 | 2012-07-20 19:09:12 +0000 | [diff] [blame] | 54 | static constexpr bool eq(char_type c1, char_type c2) noexcept; |
| 55 | static constexpr bool lt(char_type c1, char_type c2) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 56 | |
| 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 Hinnant | 03d7181 | 2012-07-20 19:09:12 +0000 | [diff] [blame] | 64 | 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 Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | template <> struct char_traits<char>; |
| 72 | template <> struct char_traits<wchar_t>; |
| 73 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 74 | template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 75 | class basic_string |
| 76 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 77 | public: |
| 78 | // types: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 79 | 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 Hinnant | 53f7d4c | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 95 | basic_string() |
| 96 | noexcept(is_nothrow_default_constructible<allocator_type>::value); |
| 97 | explicit basic_string(const allocator_type& a); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 98 | basic_string(const basic_string& str); |
Howard Hinnant | 53f7d4c | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 99 | basic_string(basic_string&& str) |
| 100 | noexcept(is_nothrow_move_constructible<allocator_type>::value); |
Marshall Clow | f4f7d8f | 2016-04-07 18:13:41 +0000 | [diff] [blame] | 101 | basic_string(const basic_string& str, size_type pos, |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 102 | const allocator_type& a = allocator_type()); |
Marshall Clow | f4f7d8f | 2016-04-07 18:13:41 +0000 | [diff] [blame] | 103 | basic_string(const basic_string& str, size_type pos, size_type n, |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 104 | const Allocator& a = Allocator()); |
| 105 | explicit basic_string(const basic_string_view<charT, traits> sv, const Allocator& a = Allocator()); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 106 | 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 Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 108 | basic_string(size_type n, value_type c, const allocator_type& a = allocator_type()); |
| 109 | template<class InputIterator> |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 110 | basic_string(InputIterator begin, InputIterator end, |
| 111 | const allocator_type& a = allocator_type()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 112 | 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 Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 118 | operator basic_string_view<charT, traits>() const noexcept; |
| 119 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 120 | basic_string& operator=(const basic_string& str); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 121 | basic_string& operator=(basic_string_view<charT, traits> sv); |
Howard Hinnant | 53f7d4c | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 122 | basic_string& operator=(basic_string&& str) |
| 123 | noexcept( |
Marshall Clow | af961ed | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 124 | allocator_type::propagate_on_container_move_assignment::value || |
| 125 | allocator_type::is_always_equal::value ); // C++17 |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 126 | basic_string& operator=(const value_type* s); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 127 | basic_string& operator=(value_type c); |
| 128 | basic_string& operator=(initializer_list<value_type>); |
| 129 | |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 130 | iterator begin() noexcept; |
| 131 | const_iterator begin() const noexcept; |
| 132 | iterator end() noexcept; |
| 133 | const_iterator end() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 134 | |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 135 | reverse_iterator rbegin() noexcept; |
| 136 | const_reverse_iterator rbegin() const noexcept; |
| 137 | reverse_iterator rend() noexcept; |
| 138 | const_reverse_iterator rend() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 139 | |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 140 | 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 Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 144 | |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 145 | 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 Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 149 | |
| 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 Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 155 | void clear() noexcept; |
| 156 | bool empty() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 157 | |
| 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 Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 165 | basic_string& operator+=(basic_string_view<charT, traits> sv); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 166 | basic_string& operator+=(const value_type* s); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 167 | basic_string& operator+=(value_type c); |
| 168 | basic_string& operator+=(initializer_list<value_type>); |
| 169 | |
| 170 | basic_string& append(const basic_string& str); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 171 | basic_string& append(basic_string_view<charT, traits> sv); |
Marshall Clow | a93b5e2 | 2014-03-04 19:17:19 +0000 | [diff] [blame] | 172 | basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14 |
Marshall Clow | 6ac8de0 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 173 | template <class T> |
| 174 | basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17 |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 175 | basic_string& append(const value_type* s, size_type n); |
| 176 | basic_string& append(const value_type* s); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 177 | basic_string& append(size_type n, value_type c); |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 178 | template<class InputIterator> |
| 179 | basic_string& append(InputIterator first, InputIterator last); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 180 | basic_string& append(initializer_list<value_type>); |
| 181 | |
| 182 | void push_back(value_type c); |
| 183 | void pop_back(); |
| 184 | reference front(); |
| 185 | const_reference front() const; |
| 186 | reference back(); |
| 187 | const_reference back() const; |
| 188 | |
| 189 | basic_string& assign(const basic_string& str); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 190 | basic_string& assign(basic_string_view<charT, traits> sv); |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 191 | basic_string& assign(basic_string&& str); |
Marshall Clow | a93b5e2 | 2014-03-04 19:17:19 +0000 | [diff] [blame] | 192 | basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14 |
Marshall Clow | 6ac8de0 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 193 | template <class T> |
| 194 | basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17 |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 195 | basic_string& assign(const value_type* s, size_type n); |
| 196 | basic_string& assign(const value_type* s); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 197 | basic_string& assign(size_type n, value_type c); |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 198 | template<class InputIterator> |
| 199 | basic_string& assign(InputIterator first, InputIterator last); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 200 | basic_string& assign(initializer_list<value_type>); |
| 201 | |
| 202 | basic_string& insert(size_type pos1, const basic_string& str); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 203 | basic_string& insert(size_type pos1, basic_string_view<charT, traits> sv); |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 204 | basic_string& insert(size_type pos1, const basic_string& str, |
| 205 | size_type pos2, size_type n); |
Marshall Clow | 6ac8de0 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 206 | template <class T> |
| 207 | basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17 |
Marshall Clow | a93b5e2 | 2014-03-04 19:17:19 +0000 | [diff] [blame] | 208 | basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14 |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 209 | basic_string& insert(size_type pos, const value_type* s); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 210 | basic_string& insert(size_type pos, size_type n, value_type c); |
| 211 | iterator insert(const_iterator p, value_type c); |
| 212 | iterator insert(const_iterator p, size_type n, value_type c); |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 213 | template<class InputIterator> |
| 214 | iterator insert(const_iterator p, InputIterator first, InputIterator last); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 215 | iterator insert(const_iterator p, initializer_list<value_type>); |
| 216 | |
| 217 | basic_string& erase(size_type pos = 0, size_type n = npos); |
| 218 | iterator erase(const_iterator position); |
| 219 | iterator erase(const_iterator first, const_iterator last); |
| 220 | |
| 221 | basic_string& replace(size_type pos1, size_type n1, const basic_string& str); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 222 | basic_string& replace(size_type pos1, size_type n1, basic_string_view<charT, traits> sv); |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 223 | basic_string& replace(size_type pos1, size_type n1, const basic_string& str, |
Marshall Clow | a93b5e2 | 2014-03-04 19:17:19 +0000 | [diff] [blame] | 224 | size_type pos2, size_type n2=npos); // C++14 |
Marshall Clow | 6ac8de0 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 225 | template <class T> |
| 226 | basic_string& replace(size_type pos1, size_type n1, const T& t, |
| 227 | size_type pos2, size_type n); // C++17 |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 228 | basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2); |
| 229 | basic_string& replace(size_type pos, size_type n1, const value_type* s); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 230 | basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c); |
Howard Hinnant | 7b2cb48 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 231 | basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 232 | basic_string& replace(const_iterator i1, const_iterator i2, basic_string_view<charT, traits> sv); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 233 | basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n); |
| 234 | basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s); |
Howard Hinnant | 7b2cb48 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 235 | basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c); |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 236 | template<class InputIterator> |
Howard Hinnant | 7b2cb48 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 237 | basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2); |
| 238 | basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 239 | |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 240 | size_type copy(value_type* s, size_type n, size_type pos = 0) const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 241 | basic_string substr(size_type pos = 0, size_type n = npos) const; |
| 242 | |
Howard Hinnant | 53f7d4c | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 243 | void swap(basic_string& str) |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 244 | noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || |
| 245 | allocator_traits<allocator_type>::is_always_equal::value); // C++17 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 246 | |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 247 | const value_type* c_str() const noexcept; |
| 248 | const value_type* data() const noexcept; |
Marshall Clow | f532a70 | 2016-03-08 15:44:30 +0000 | [diff] [blame] | 249 | value_type* data() noexcept; // C++17 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 250 | |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 251 | allocator_type get_allocator() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 252 | |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 253 | size_type find(const basic_string& str, size_type pos = 0) const noexcept; |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 254 | size_type find(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept; |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 255 | size_type find(const value_type* s, size_type pos, size_type n) const noexcept; |
| 256 | size_type find(const value_type* s, size_type pos = 0) const noexcept; |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 257 | size_type find(value_type c, size_type pos = 0) const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 258 | |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 259 | size_type rfind(const basic_string& str, size_type pos = npos) const noexcept; |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 260 | size_type ffind(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept; |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 261 | size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept; |
| 262 | size_type rfind(const value_type* s, size_type pos = npos) const noexcept; |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 263 | size_type rfind(value_type c, size_type pos = npos) const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 264 | |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 265 | size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept; |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 266 | size_type find_first_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept; |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 267 | size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept; |
| 268 | size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept; |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 269 | size_type find_first_of(value_type c, size_type pos = 0) const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 270 | |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 271 | size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept; |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 272 | size_type find_last_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept; |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 273 | size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept; |
| 274 | size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept; |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 275 | size_type find_last_of(value_type c, size_type pos = npos) const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 276 | |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 277 | size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept; |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 278 | size_type find_first_not_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept; |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 279 | size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept; |
| 280 | size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept; |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 281 | size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 282 | |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 283 | size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept; |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 284 | size_type find_last_not_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept; |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 285 | size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept; |
| 286 | size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept; |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 287 | size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 288 | |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 289 | int compare(const basic_string& str) const noexcept; |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 290 | int compare(basic_string_view<charT, traits> sv) const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 291 | int compare(size_type pos1, size_type n1, const basic_string& str) const; |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 292 | int compare(size_type pos1, size_type n1, basic_string_view<charT, traits> sv) const; |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 293 | int compare(size_type pos1, size_type n1, const basic_string& str, |
Marshall Clow | a93b5e2 | 2014-03-04 19:17:19 +0000 | [diff] [blame] | 294 | size_type pos2, size_type n2=npos) const; // C++14 |
Marshall Clow | 6ac8de0 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 295 | template <class T> |
| 296 | int compare(size_type pos1, size_type n1, const T& t, |
| 297 | size_type pos2, size_type n2=npos) const; // C++17 |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 298 | int compare(const value_type* s) const noexcept; |
| 299 | int compare(size_type pos1, size_type n1, const value_type* s) const; |
| 300 | int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 301 | |
| 302 | bool __invariants() const; |
| 303 | }; |
| 304 | |
| 305 | template<class charT, class traits, class Allocator> |
| 306 | basic_string<charT, traits, Allocator> |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 307 | operator+(const basic_string<charT, traits, Allocator>& lhs, |
| 308 | const basic_string<charT, traits, Allocator>& rhs); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 309 | |
| 310 | template<class charT, class traits, class Allocator> |
| 311 | basic_string<charT, traits, Allocator> |
| 312 | operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs); |
| 313 | |
| 314 | template<class charT, class traits, class Allocator> |
| 315 | basic_string<charT, traits, Allocator> |
| 316 | operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs); |
| 317 | |
| 318 | template<class charT, class traits, class Allocator> |
| 319 | basic_string<charT, traits, Allocator> |
| 320 | operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs); |
| 321 | |
| 322 | template<class charT, class traits, class Allocator> |
| 323 | basic_string<charT, traits, Allocator> |
| 324 | operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs); |
| 325 | |
| 326 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 327 | bool operator==(const basic_string<charT, traits, Allocator>& lhs, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 328 | const basic_string<charT, traits, Allocator>& rhs) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 329 | |
| 330 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 331 | bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 332 | |
| 333 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 334 | bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 335 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 336 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 337 | bool operator!=(const basic_string<charT,traits,Allocator>& lhs, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 338 | const basic_string<charT, traits, Allocator>& rhs) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 339 | |
| 340 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 341 | bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 342 | |
| 343 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 344 | bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 345 | |
| 346 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 347 | bool operator< (const basic_string<charT, traits, Allocator>& lhs, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 348 | const basic_string<charT, traits, Allocator>& rhs) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 349 | |
| 350 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 351 | bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 352 | |
| 353 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 354 | bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 355 | |
| 356 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 357 | bool operator> (const basic_string<charT, traits, Allocator>& lhs, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 358 | const basic_string<charT, traits, Allocator>& rhs) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 359 | |
| 360 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 361 | bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 362 | |
| 363 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 364 | bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 365 | |
| 366 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 367 | bool operator<=(const basic_string<charT, traits, Allocator>& lhs, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 368 | const basic_string<charT, traits, Allocator>& rhs) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 369 | |
| 370 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 371 | bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 372 | |
| 373 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 374 | bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 375 | |
| 376 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 377 | bool operator>=(const basic_string<charT, traits, Allocator>& lhs, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 378 | const basic_string<charT, traits, Allocator>& rhs) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 379 | |
| 380 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 381 | bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 382 | |
| 383 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 384 | bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 385 | |
| 386 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 387 | void swap(basic_string<charT, traits, Allocator>& lhs, |
Howard Hinnant | 53f7d4c | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 388 | basic_string<charT, traits, Allocator>& rhs) |
| 389 | noexcept(noexcept(lhs.swap(rhs))); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 390 | |
| 391 | template<class charT, class traits, class Allocator> |
| 392 | basic_istream<charT, traits>& |
| 393 | operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str); |
| 394 | |
| 395 | template<class charT, class traits, class Allocator> |
| 396 | basic_ostream<charT, traits>& |
| 397 | operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str); |
| 398 | |
| 399 | template<class charT, class traits, class Allocator> |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 400 | basic_istream<charT, traits>& |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 401 | getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str, |
| 402 | charT delim); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 403 | |
| 404 | template<class charT, class traits, class Allocator> |
| 405 | basic_istream<charT, traits>& |
| 406 | getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str); |
| 407 | |
| 408 | typedef basic_string<char> string; |
| 409 | typedef basic_string<wchar_t> wstring; |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 410 | typedef basic_string<char16_t> u16string; |
| 411 | typedef basic_string<char32_t> u32string; |
| 412 | |
| 413 | int stoi (const string& str, size_t* idx = 0, int base = 10); |
| 414 | long stol (const string& str, size_t* idx = 0, int base = 10); |
| 415 | unsigned long stoul (const string& str, size_t* idx = 0, int base = 10); |
| 416 | long long stoll (const string& str, size_t* idx = 0, int base = 10); |
| 417 | unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10); |
| 418 | |
| 419 | float stof (const string& str, size_t* idx = 0); |
| 420 | double stod (const string& str, size_t* idx = 0); |
| 421 | long double stold(const string& str, size_t* idx = 0); |
| 422 | |
| 423 | string to_string(int val); |
| 424 | string to_string(unsigned val); |
| 425 | string to_string(long val); |
| 426 | string to_string(unsigned long val); |
| 427 | string to_string(long long val); |
| 428 | string to_string(unsigned long long val); |
| 429 | string to_string(float val); |
| 430 | string to_string(double val); |
| 431 | string to_string(long double val); |
| 432 | |
| 433 | int stoi (const wstring& str, size_t* idx = 0, int base = 10); |
| 434 | long stol (const wstring& str, size_t* idx = 0, int base = 10); |
| 435 | unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10); |
| 436 | long long stoll (const wstring& str, size_t* idx = 0, int base = 10); |
| 437 | unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10); |
| 438 | |
| 439 | float stof (const wstring& str, size_t* idx = 0); |
| 440 | double stod (const wstring& str, size_t* idx = 0); |
| 441 | long double stold(const wstring& str, size_t* idx = 0); |
| 442 | |
| 443 | wstring to_wstring(int val); |
| 444 | wstring to_wstring(unsigned val); |
| 445 | wstring to_wstring(long val); |
| 446 | wstring to_wstring(unsigned long val); |
| 447 | wstring to_wstring(long long val); |
| 448 | wstring to_wstring(unsigned long long val); |
| 449 | wstring to_wstring(float val); |
| 450 | wstring to_wstring(double val); |
| 451 | wstring to_wstring(long double val); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 452 | |
| 453 | template <> struct hash<string>; |
| 454 | template <> struct hash<u16string>; |
| 455 | template <> struct hash<u32string>; |
| 456 | template <> struct hash<wstring>; |
| 457 | |
Marshall Clow | 1523432 | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 458 | basic_string<char> operator "" s( const char *str, size_t len ); // C++14 |
| 459 | basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14 |
| 460 | basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14 |
| 461 | basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14 |
| 462 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 463 | } // std |
| 464 | |
| 465 | */ |
| 466 | |
| 467 | #include <__config> |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 468 | #include <string_view> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 469 | #include <iosfwd> |
| 470 | #include <cstring> |
Howard Hinnant | adff489 | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 471 | #include <cstdio> // For EOF. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 472 | #include <cwchar> |
| 473 | #include <algorithm> |
| 474 | #include <iterator> |
| 475 | #include <utility> |
| 476 | #include <memory> |
| 477 | #include <stdexcept> |
| 478 | #include <type_traits> |
| 479 | #include <initializer_list> |
| 480 | #include <__functional_base> |
| 481 | #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS |
| 482 | #include <cstdint> |
| 483 | #endif |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 484 | |
Howard Hinnant | 66c6f97 | 2011-11-29 16:45:27 +0000 | [diff] [blame] | 485 | #include <__undef_min_max> |
| 486 | |
Eric Fiselier | b953610 | 2014-08-10 23:53:08 +0000 | [diff] [blame] | 487 | #include <__debug> |
| 488 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 489 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 490 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 491 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 492 | |
| 493 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 494 | |
| 495 | // fpos |
| 496 | |
| 497 | template <class _StateT> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 498 | class _LIBCPP_TYPE_VIS_ONLY fpos |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 499 | { |
| 500 | private: |
| 501 | _StateT __st_; |
| 502 | streamoff __off_; |
| 503 | public: |
| 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 | |
| 517 | template <class _StateT> |
| 518 | inline _LIBCPP_INLINE_VISIBILITY |
| 519 | streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y) |
| 520 | {return streamoff(__x) - streamoff(__y);} |
| 521 | |
| 522 | template <class _StateT> |
| 523 | inline _LIBCPP_INLINE_VISIBILITY |
| 524 | bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y) |
| 525 | {return streamoff(__x) == streamoff(__y);} |
| 526 | |
| 527 | template <class _StateT> |
| 528 | inline _LIBCPP_INLINE_VISIBILITY |
| 529 | bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y) |
| 530 | {return streamoff(__x) != streamoff(__y);} |
| 531 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 532 | // basic_string |
| 533 | |
| 534 | template<class _CharT, class _Traits, class _Allocator> |
| 535 | basic_string<_CharT, _Traits, _Allocator> |
Howard Hinnant | 2b1b2d4 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 536 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, |
| 537 | const basic_string<_CharT, _Traits, _Allocator>& __y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 538 | |
| 539 | template<class _CharT, class _Traits, class _Allocator> |
| 540 | basic_string<_CharT, _Traits, _Allocator> |
Howard Hinnant | 2b1b2d4 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 541 | operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 542 | |
| 543 | template<class _CharT, class _Traits, class _Allocator> |
| 544 | basic_string<_CharT, _Traits, _Allocator> |
Howard Hinnant | 2b1b2d4 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 545 | operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 546 | |
| 547 | template<class _CharT, class _Traits, class _Allocator> |
| 548 | basic_string<_CharT, _Traits, _Allocator> |
Howard Hinnant | 2b1b2d4 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 549 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 550 | |
| 551 | template<class _CharT, class _Traits, class _Allocator> |
| 552 | basic_string<_CharT, _Traits, _Allocator> |
Howard Hinnant | 2b1b2d4 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 553 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 554 | |
| 555 | template <bool> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 556 | class _LIBCPP_TYPE_VIS_ONLY __basic_string_common |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 557 | { |
| 558 | protected: |
Marshall Clow | 14c09a2 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 559 | _LIBCPP_NORETURN void __throw_length_error() const; |
| 560 | _LIBCPP_NORETURN void __throw_out_of_range() const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 561 | }; |
| 562 | |
| 563 | template <bool __b> |
| 564 | void |
| 565 | __basic_string_common<__b>::__throw_length_error() const |
| 566 | { |
Marshall Clow | 14c09a2 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 567 | _VSTD::__throw_length_error("basic_string"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | template <bool __b> |
| 571 | void |
| 572 | __basic_string_common<__b>::__throw_out_of_range() const |
| 573 | { |
Marshall Clow | 14c09a2 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 574 | _VSTD::__throw_out_of_range("basic_string"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Howard Hinnant | e9df0a5 | 2013-08-01 18:17:34 +0000 | [diff] [blame] | 577 | #ifdef _LIBCPP_MSVC |
Howard Hinnant | 78b6828 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 578 | #pragma warning( push ) |
| 579 | #pragma warning( disable: 4231 ) |
Howard Hinnant | e9df0a5 | 2013-08-01 18:17:34 +0000 | [diff] [blame] | 580 | #endif // _LIBCPP_MSVC |
Eric Fiselier | 833d644 | 2016-09-15 22:27:07 +0000 | [diff] [blame] | 581 | _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>) |
Howard Hinnant | e9df0a5 | 2013-08-01 18:17:34 +0000 | [diff] [blame] | 582 | #ifdef _LIBCPP_MSVC |
Howard Hinnant | 78b6828 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 583 | #pragma warning( pop ) |
Howard Hinnant | e9df0a5 | 2013-08-01 18:17:34 +0000 | [diff] [blame] | 584 | #endif // _LIBCPP_MSVC |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 585 | |
Marshall Clow | df9db31 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 586 | #ifdef _LIBCPP_NO_EXCEPTIONS |
| 587 | template <class _Iter> |
| 588 | struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {}; |
| 589 | #elif defined(_LIBCPP_HAS_NO_NOEXCEPT) |
| 590 | template <class _Iter> |
| 591 | struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {}; |
| 592 | #else |
| 593 | template <class _Iter, bool = __is_forward_iterator<_Iter>::value> |
| 594 | struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT(( |
| 595 | noexcept(++(declval<_Iter&>())) && |
| 596 | is_nothrow_assignable<_Iter&, _Iter>::value && |
| 597 | noexcept(declval<_Iter>() == declval<_Iter>()) && |
| 598 | noexcept(*declval<_Iter>()) |
| 599 | )) {}; |
| 600 | |
| 601 | template <class _Iter> |
| 602 | struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {}; |
| 603 | #endif |
| 604 | |
| 605 | |
| 606 | template <class _Iter> |
| 607 | struct __libcpp_string_gets_noexcept_iterator |
| 608 | : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {}; |
| 609 | |
Marshall Clow | 6ac8de0 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 610 | template <class _CharT, class _Traits, class _Tp> |
| 611 | struct __can_be_converted_to_string_view : public _LIBCPP_BOOL_CONSTANT( |
| 612 | ( is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value && |
| 613 | !is_convertible<const _Tp&, const _CharT*>::value)) {}; |
| 614 | |
Evgeniy Stepanov | 4f01aa8 | 2015-10-13 23:48:28 +0000 | [diff] [blame] | 615 | #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
Howard Hinnant | 1546718 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 616 | |
| 617 | template <class _CharT, size_t = sizeof(_CharT)> |
| 618 | struct __padding |
| 619 | { |
| 620 | unsigned char __xx[sizeof(_CharT)-1]; |
| 621 | }; |
| 622 | |
| 623 | template <class _CharT> |
| 624 | struct __padding<_CharT, 1> |
| 625 | { |
| 626 | }; |
| 627 | |
Evgeniy Stepanov | 4f01aa8 | 2015-10-13 23:48:28 +0000 | [diff] [blame] | 628 | #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
Howard Hinnant | 1546718 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 629 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 630 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 631 | class _LIBCPP_TYPE_VIS_ONLY basic_string |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 632 | : private __basic_string_common<true> |
| 633 | { |
| 634 | public: |
| 635 | typedef basic_string __self; |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 636 | typedef basic_string_view<_CharT, _Traits> __self_view; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 637 | typedef _Traits traits_type; |
| 638 | typedef typename traits_type::char_type value_type; |
| 639 | typedef _Allocator allocator_type; |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 640 | typedef allocator_traits<allocator_type> __alloc_traits; |
| 641 | typedef typename __alloc_traits::size_type size_type; |
| 642 | typedef typename __alloc_traits::difference_type difference_type; |
Howard Hinnant | 53f7d4c | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 643 | typedef value_type& reference; |
| 644 | typedef const value_type& const_reference; |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 645 | typedef typename __alloc_traits::pointer pointer; |
| 646 | typedef typename __alloc_traits::const_pointer const_pointer; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 647 | |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 648 | static_assert(is_pod<value_type>::value, "Character type of basic_string must be a POD"); |
| 649 | static_assert((is_same<_CharT, value_type>::value), |
| 650 | "traits_type::char_type must be the same type as CharT"); |
| 651 | static_assert((is_same<typename allocator_type::value_type, value_type>::value), |
| 652 | "Allocator::value_type must be same type as value_type"); |
| 653 | #if defined(_LIBCPP_RAW_ITERATORS) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 654 | typedef pointer iterator; |
| 655 | typedef const_pointer const_iterator; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 656 | #else // defined(_LIBCPP_RAW_ITERATORS) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 657 | typedef __wrap_iter<pointer> iterator; |
| 658 | typedef __wrap_iter<const_pointer> const_iterator; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 659 | #endif // defined(_LIBCPP_RAW_ITERATORS) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 660 | typedef _VSTD::reverse_iterator<iterator> reverse_iterator; |
| 661 | typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 662 | |
| 663 | private: |
Howard Hinnant | 1546718 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 664 | |
Evgeniy Stepanov | 4f01aa8 | 2015-10-13 23:48:28 +0000 | [diff] [blame] | 665 | #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
Howard Hinnant | 1546718 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 666 | |
| 667 | struct __long |
| 668 | { |
| 669 | pointer __data_; |
| 670 | size_type __size_; |
| 671 | size_type __cap_; |
| 672 | }; |
| 673 | |
| 674 | #if _LIBCPP_BIG_ENDIAN |
| 675 | enum {__short_mask = 0x01}; |
| 676 | enum {__long_mask = 0x1ul}; |
| 677 | #else // _LIBCPP_BIG_ENDIAN |
| 678 | enum {__short_mask = 0x80}; |
| 679 | enum {__long_mask = ~(size_type(~0) >> 1)}; |
| 680 | #endif // _LIBCPP_BIG_ENDIAN |
| 681 | |
| 682 | enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? |
| 683 | (sizeof(__long) - 1)/sizeof(value_type) : 2}; |
| 684 | |
| 685 | struct __short |
| 686 | { |
| 687 | value_type __data_[__min_cap]; |
| 688 | struct |
| 689 | : __padding<value_type> |
| 690 | { |
| 691 | unsigned char __size_; |
| 692 | }; |
| 693 | }; |
| 694 | |
| 695 | #else |
| 696 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 697 | struct __long |
| 698 | { |
| 699 | size_type __cap_; |
| 700 | size_type __size_; |
| 701 | pointer __data_; |
| 702 | }; |
| 703 | |
| 704 | #if _LIBCPP_BIG_ENDIAN |
| 705 | enum {__short_mask = 0x80}; |
| 706 | enum {__long_mask = ~(size_type(~0) >> 1)}; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 707 | #else // _LIBCPP_BIG_ENDIAN |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 708 | enum {__short_mask = 0x01}; |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 709 | enum {__long_mask = 0x1ul}; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 710 | #endif // _LIBCPP_BIG_ENDIAN |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 711 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 712 | enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? |
| 713 | (sizeof(__long) - 1)/sizeof(value_type) : 2}; |
| 714 | |
| 715 | struct __short |
| 716 | { |
| 717 | union |
| 718 | { |
| 719 | unsigned char __size_; |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 720 | value_type __lx; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 721 | }; |
| 722 | value_type __data_[__min_cap]; |
| 723 | }; |
| 724 | |
Evgeniy Stepanov | 4f01aa8 | 2015-10-13 23:48:28 +0000 | [diff] [blame] | 725 | #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
Howard Hinnant | 1546718 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 726 | |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 727 | union __ulx{__long __lx; __short __lxx;}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 728 | |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 729 | enum {__n_words = sizeof(__ulx) / sizeof(size_type)}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 730 | |
| 731 | struct __raw |
| 732 | { |
| 733 | size_type __words[__n_words]; |
| 734 | }; |
| 735 | |
| 736 | struct __rep |
| 737 | { |
| 738 | union |
| 739 | { |
| 740 | __long __l; |
| 741 | __short __s; |
| 742 | __raw __r; |
| 743 | }; |
| 744 | }; |
| 745 | |
| 746 | __compressed_pair<__rep, allocator_type> __r_; |
| 747 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 748 | public: |
| 749 | static const size_type npos = -1; |
| 750 | |
Howard Hinnant | 53f7d4c | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 751 | _LIBCPP_INLINE_VISIBILITY basic_string() |
| 752 | _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); |
Marshall Clow | 7b193f7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 753 | |
| 754 | _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a) |
| 755 | #if _LIBCPP_STD_VER <= 14 |
| 756 | _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value); |
| 757 | #else |
| 758 | _NOEXCEPT; |
| 759 | #endif |
| 760 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 761 | basic_string(const basic_string& __str); |
| 762 | basic_string(const basic_string& __str, const allocator_type& __a); |
Marshall Clow | 7b193f7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 763 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 764 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 9f193f2 | 2011-01-26 00:06:59 +0000 | [diff] [blame] | 765 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f7d4c | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 766 | basic_string(basic_string&& __str) |
Marshall Clow | 7b193f7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 767 | #if _LIBCPP_STD_VER <= 14 |
Howard Hinnant | 53f7d4c | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 768 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); |
Marshall Clow | 7b193f7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 769 | #else |
| 770 | _NOEXCEPT; |
| 771 | #endif |
| 772 | |
Howard Hinnant | 9f193f2 | 2011-01-26 00:06:59 +0000 | [diff] [blame] | 773 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 774 | basic_string(basic_string&& __str, const allocator_type& __a); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 775 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 776 | _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 777 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 778 | basic_string(const value_type* __s, const allocator_type& __a); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 779 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 780 | basic_string(const value_type* __s, size_type __n); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 781 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 782 | basic_string(const value_type* __s, size_type __n, const allocator_type& __a); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 783 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 784 | basic_string(size_type __n, value_type __c); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 785 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 786 | basic_string(size_type __n, value_type __c, const allocator_type& __a); |
Marshall Clow | f4f7d8f | 2016-04-07 18:13:41 +0000 | [diff] [blame] | 787 | basic_string(const basic_string& __str, size_type __pos, size_type __n, |
| 788 | const allocator_type& __a = allocator_type()); |
| 789 | _LIBCPP_INLINE_VISIBILITY |
| 790 | basic_string(const basic_string& __str, size_type __pos, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 791 | const allocator_type& __a = allocator_type()); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 792 | _LIBCPP_INLINE_VISIBILITY explicit |
| 793 | basic_string(__self_view __sv); |
| 794 | _LIBCPP_INLINE_VISIBILITY |
| 795 | basic_string(__self_view __sv, const allocator_type& __a); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 796 | template<class _InputIterator> |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 797 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 798 | basic_string(_InputIterator __first, _InputIterator __last); |
| 799 | template<class _InputIterator> |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 800 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 801 | basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 802 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 803 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 804 | basic_string(initializer_list<value_type> __il); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 805 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 806 | basic_string(initializer_list<value_type> __il, const allocator_type& __a); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 807 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 808 | |
| 809 | ~basic_string(); |
| 810 | |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 811 | _LIBCPP_INLINE_VISIBILITY |
| 812 | operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); } |
| 813 | |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 814 | basic_string& operator=(const basic_string& __str); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 815 | _LIBCPP_INLINE_VISIBILITY |
| 816 | basic_string& operator=(__self_view __sv) {return assign(__sv);} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 817 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 818 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f7d4c | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 819 | basic_string& operator=(basic_string&& __str) |
Marshall Clow | af961ed | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 820 | _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 821 | #endif |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 822 | _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 823 | basic_string& operator=(value_type __c); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 824 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 825 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 826 | basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 827 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 828 | |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 829 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 830 | _LIBCPP_INLINE_VISIBILITY |
| 831 | iterator begin() _NOEXCEPT |
| 832 | {return iterator(this, __get_pointer());} |
| 833 | _LIBCPP_INLINE_VISIBILITY |
| 834 | const_iterator begin() const _NOEXCEPT |
| 835 | {return const_iterator(this, __get_pointer());} |
| 836 | _LIBCPP_INLINE_VISIBILITY |
| 837 | iterator end() _NOEXCEPT |
| 838 | {return iterator(this, __get_pointer() + size());} |
| 839 | _LIBCPP_INLINE_VISIBILITY |
| 840 | const_iterator end() const _NOEXCEPT |
| 841 | {return const_iterator(this, __get_pointer() + size());} |
| 842 | #else |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 843 | _LIBCPP_INLINE_VISIBILITY |
| 844 | iterator begin() _NOEXCEPT |
| 845 | {return iterator(__get_pointer());} |
| 846 | _LIBCPP_INLINE_VISIBILITY |
| 847 | const_iterator begin() const _NOEXCEPT |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 848 | {return const_iterator(__get_pointer());} |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 849 | _LIBCPP_INLINE_VISIBILITY |
| 850 | iterator end() _NOEXCEPT |
| 851 | {return iterator(__get_pointer() + size());} |
| 852 | _LIBCPP_INLINE_VISIBILITY |
| 853 | const_iterator end() const _NOEXCEPT |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 854 | {return const_iterator(__get_pointer() + size());} |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 855 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 856 | _LIBCPP_INLINE_VISIBILITY |
| 857 | reverse_iterator rbegin() _NOEXCEPT |
| 858 | {return reverse_iterator(end());} |
| 859 | _LIBCPP_INLINE_VISIBILITY |
| 860 | const_reverse_iterator rbegin() const _NOEXCEPT |
| 861 | {return const_reverse_iterator(end());} |
| 862 | _LIBCPP_INLINE_VISIBILITY |
| 863 | reverse_iterator rend() _NOEXCEPT |
| 864 | {return reverse_iterator(begin());} |
| 865 | _LIBCPP_INLINE_VISIBILITY |
| 866 | const_reverse_iterator rend() const _NOEXCEPT |
| 867 | {return const_reverse_iterator(begin());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 868 | |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 869 | _LIBCPP_INLINE_VISIBILITY |
| 870 | const_iterator cbegin() const _NOEXCEPT |
| 871 | {return begin();} |
| 872 | _LIBCPP_INLINE_VISIBILITY |
| 873 | const_iterator cend() const _NOEXCEPT |
| 874 | {return end();} |
| 875 | _LIBCPP_INLINE_VISIBILITY |
| 876 | const_reverse_iterator crbegin() const _NOEXCEPT |
| 877 | {return rbegin();} |
| 878 | _LIBCPP_INLINE_VISIBILITY |
| 879 | const_reverse_iterator crend() const _NOEXCEPT |
| 880 | {return rend();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 881 | |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 882 | _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 883 | {return __is_long() ? __get_long_size() : __get_short_size();} |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 884 | _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();} |
| 885 | _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT; |
| 886 | _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT |
Eric Fiselier | e2d4892 | 2015-08-28 07:02:42 +0000 | [diff] [blame] | 887 | {return (__is_long() ? __get_long_cap() |
| 888 | : static_cast<size_type>(__min_cap)) - 1;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 889 | |
| 890 | void resize(size_type __n, value_type __c); |
| 891 | _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());} |
| 892 | |
| 893 | void reserve(size_type res_arg = 0); |
Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 894 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f7d4c | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 895 | void shrink_to_fit() _NOEXCEPT {reserve();} |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 896 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 897 | void clear() _NOEXCEPT; |
| 898 | _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 899 | |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 900 | _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT; |
| 901 | _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 902 | |
| 903 | const_reference at(size_type __n) const; |
| 904 | reference at(size_type __n); |
| 905 | |
| 906 | _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);} |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 907 | _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(__self_view __sv) {return append(__sv);} |
| 908 | _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 909 | _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 910 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 911 | _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 912 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 913 | |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 914 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 915 | basic_string& append(const basic_string& __str); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 916 | _LIBCPP_INLINE_VISIBILITY |
| 917 | basic_string& append(__self_view __sv) { return append(__sv.data(), __sv.size()); } |
Marshall Clow | a93b5e2 | 2014-03-04 19:17:19 +0000 | [diff] [blame] | 918 | basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos); |
Marshall Clow | 42a87db | 2016-10-03 23:40:48 +0000 | [diff] [blame^] | 919 | template <class _Tp> |
Marshall Clow | 6ac8de0 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 920 | typename enable_if |
| 921 | < |
| 922 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 923 | basic_string& |
| 924 | >::type |
| 925 | append(const _Tp& __t, size_type __pos, size_type __n=npos); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 926 | basic_string& append(const value_type* __s, size_type __n); |
| 927 | basic_string& append(const value_type* __s); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 928 | basic_string& append(size_type __n, value_type __c); |
| 929 | template<class _InputIterator> |
| 930 | typename enable_if |
| 931 | < |
Marshall Clow | df9db31 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 932 | __is_exactly_input_iterator<_InputIterator>::value |
| 933 | || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 934 | basic_string& |
| 935 | >::type |
| 936 | append(_InputIterator __first, _InputIterator __last); |
| 937 | template<class _ForwardIterator> |
| 938 | typename enable_if |
| 939 | < |
Marshall Clow | df9db31 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 940 | __is_forward_iterator<_ForwardIterator>::value |
| 941 | && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 942 | basic_string& |
| 943 | >::type |
| 944 | append(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 945 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 946 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 947 | basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 948 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 949 | |
| 950 | void push_back(value_type __c); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 951 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 952 | void pop_back(); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 953 | _LIBCPP_INLINE_VISIBILITY reference front(); |
| 954 | _LIBCPP_INLINE_VISIBILITY const_reference front() const; |
| 955 | _LIBCPP_INLINE_VISIBILITY reference back(); |
| 956 | _LIBCPP_INLINE_VISIBILITY const_reference back() const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 957 | |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 958 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 959 | basic_string& assign(__self_view __sv) { return assign(__sv.data(), __sv.size()); } |
| 960 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | f40ec90 | 2016-03-09 18:08:29 +0000 | [diff] [blame] | 961 | basic_string& assign(const basic_string& __str) { return *this = __str; } |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 962 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 963 | _LIBCPP_INLINE_VISIBILITY |
| 964 | basic_string& assign(basic_string&& str) |
Marshall Clow | 7ed093b | 2015-10-05 16:17:34 +0000 | [diff] [blame] | 965 | _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 966 | {*this = _VSTD::move(str); return *this;} |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 967 | #endif |
Marshall Clow | a93b5e2 | 2014-03-04 19:17:19 +0000 | [diff] [blame] | 968 | basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos); |
Marshall Clow | 42a87db | 2016-10-03 23:40:48 +0000 | [diff] [blame^] | 969 | template <class _Tp> |
Marshall Clow | 6ac8de0 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 970 | typename enable_if |
| 971 | < |
| 972 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 973 | basic_string& |
| 974 | >::type |
| 975 | assign(const _Tp & __t, size_type pos, size_type n=npos); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 976 | basic_string& assign(const value_type* __s, size_type __n); |
| 977 | basic_string& assign(const value_type* __s); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 978 | basic_string& assign(size_type __n, value_type __c); |
| 979 | template<class _InputIterator> |
| 980 | typename enable_if |
| 981 | < |
Marshall Clow | df9db31 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 982 | __is_exactly_input_iterator<_InputIterator>::value |
| 983 | || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 984 | basic_string& |
| 985 | >::type |
| 986 | assign(_InputIterator __first, _InputIterator __last); |
| 987 | template<class _ForwardIterator> |
| 988 | typename enable_if |
| 989 | < |
Marshall Clow | df9db31 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 990 | __is_forward_iterator<_ForwardIterator>::value |
| 991 | && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 992 | basic_string& |
| 993 | >::type |
| 994 | assign(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 995 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 996 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 997 | basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 998 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 999 | |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1000 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1001 | basic_string& insert(size_type __pos1, const basic_string& __str); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1002 | _LIBCPP_INLINE_VISIBILITY |
| 1003 | basic_string& insert(size_type __pos1, __self_view __sv) { return insert(__pos1, __sv.data(), __sv.size()); } |
Marshall Clow | 6ac8de0 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1004 | template <class _Tp> |
| 1005 | typename enable_if |
| 1006 | < |
| 1007 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1008 | basic_string& |
| 1009 | >::type |
| 1010 | insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos); |
Marshall Clow | a93b5e2 | 2014-03-04 19:17:19 +0000 | [diff] [blame] | 1011 | basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1012 | basic_string& insert(size_type __pos, const value_type* __s, size_type __n); |
| 1013 | basic_string& insert(size_type __pos, const value_type* __s); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1014 | basic_string& insert(size_type __pos, size_type __n, value_type __c); |
| 1015 | iterator insert(const_iterator __pos, value_type __c); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1016 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1017 | iterator insert(const_iterator __pos, size_type __n, value_type __c); |
| 1018 | template<class _InputIterator> |
| 1019 | typename enable_if |
| 1020 | < |
Marshall Clow | df9db31 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 1021 | __is_exactly_input_iterator<_InputIterator>::value |
| 1022 | || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1023 | iterator |
| 1024 | >::type |
| 1025 | insert(const_iterator __pos, _InputIterator __first, _InputIterator __last); |
| 1026 | template<class _ForwardIterator> |
| 1027 | typename enable_if |
| 1028 | < |
Marshall Clow | df9db31 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 1029 | __is_forward_iterator<_ForwardIterator>::value |
| 1030 | && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1031 | iterator |
| 1032 | >::type |
| 1033 | insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1034 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 1035 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1036 | iterator insert(const_iterator __pos, initializer_list<value_type> __il) |
| 1037 | {return insert(__pos, __il.begin(), __il.end());} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1038 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1039 | |
| 1040 | basic_string& erase(size_type __pos = 0, size_type __n = npos); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1041 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1042 | iterator erase(const_iterator __pos); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1043 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1044 | iterator erase(const_iterator __first, const_iterator __last); |
| 1045 | |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1046 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1047 | basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1048 | _LIBCPP_INLINE_VISIBILITY |
| 1049 | basic_string& replace(size_type __pos1, size_type __n1, __self_view __sv) { return replace(__pos1, __n1, __sv.data(), __sv.size()); } |
Marshall Clow | a93b5e2 | 2014-03-04 19:17:19 +0000 | [diff] [blame] | 1050 | basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos); |
Marshall Clow | 6ac8de0 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1051 | template <class _Tp> |
| 1052 | typename enable_if |
| 1053 | < |
| 1054 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1055 | basic_string& |
| 1056 | >::type |
| 1057 | replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1058 | basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2); |
| 1059 | basic_string& replace(size_type __pos, size_type __n1, const value_type* __s); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1060 | basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1061 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7b2cb48 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 1062 | basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1063 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1064 | basic_string& replace(const_iterator __i1, const_iterator __i2, __self_view __sv) { return replace(__i1 - begin(), __i2 - __i1, __sv); } |
| 1065 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1066 | basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1067 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1068 | basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1069 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7b2cb48 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 1070 | basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1071 | template<class _InputIterator> |
| 1072 | typename enable_if |
| 1073 | < |
| 1074 | __is_input_iterator<_InputIterator>::value, |
| 1075 | basic_string& |
| 1076 | >::type |
Howard Hinnant | 7b2cb48 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 1077 | replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1078 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 8d7a955 | 2010-09-23 17:31:07 +0000 | [diff] [blame] | 1079 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7b2cb48 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 1080 | basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1081 | {return replace(__i1, __i2, __il.begin(), __il.end());} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1082 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1083 | |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1084 | size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const; |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1085 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1086 | basic_string substr(size_type __pos = 0, size_type __n = npos) const; |
| 1087 | |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1088 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f7d4c | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1089 | void swap(basic_string& __str) |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1090 | #if _LIBCPP_STD_VER >= 14 |
| 1091 | _NOEXCEPT; |
| 1092 | #else |
| 1093 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
| 1094 | __is_nothrow_swappable<allocator_type>::value); |
| 1095 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1096 | |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1097 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1098 | const value_type* c_str() const _NOEXCEPT {return data();} |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1099 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1100 | const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());} |
Marshall Clow | f532a70 | 2016-03-08 15:44:30 +0000 | [diff] [blame] | 1101 | #if _LIBCPP_STD_VER > 14 |
| 1102 | _LIBCPP_INLINE_VISIBILITY |
| 1103 | value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());} |
| 1104 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1105 | |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1106 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1107 | allocator_type get_allocator() const _NOEXCEPT {return __alloc();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1108 | |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1109 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1110 | size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1111 | _LIBCPP_INLINE_VISIBILITY |
| 1112 | size_type find(__self_view __sv, size_type __pos = 0) const _NOEXCEPT; |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1113 | size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1114 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1115 | size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1116 | size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1117 | |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1118 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1119 | size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1120 | _LIBCPP_INLINE_VISIBILITY |
| 1121 | size_type rfind(__self_view __sv, size_type __pos = 0) const _NOEXCEPT; |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1122 | size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1123 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1124 | size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1125 | size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1126 | |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1127 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1128 | size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1129 | _LIBCPP_INLINE_VISIBILITY |
| 1130 | size_type find_first_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT; |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1131 | size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1132 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1133 | size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1134 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1135 | size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1136 | |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1137 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1138 | size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1139 | _LIBCPP_INLINE_VISIBILITY |
| 1140 | size_type find_last_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT; |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1141 | size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1142 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1143 | size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1144 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1145 | size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1146 | |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1147 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1148 | size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1149 | _LIBCPP_INLINE_VISIBILITY |
| 1150 | size_type find_first_not_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT; |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1151 | size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1152 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1153 | size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1154 | _LIBCPP_INLINE_VISIBILITY |
| 1155 | size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT; |
| 1156 | |
| 1157 | _LIBCPP_INLINE_VISIBILITY |
| 1158 | size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1159 | _LIBCPP_INLINE_VISIBILITY |
| 1160 | size_type find_last_not_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT; |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1161 | size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1162 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1163 | size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1164 | _LIBCPP_INLINE_VISIBILITY |
| 1165 | size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT; |
| 1166 | |
| 1167 | _LIBCPP_INLINE_VISIBILITY |
| 1168 | int compare(const basic_string& __str) const _NOEXCEPT; |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1169 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1170 | int compare(__self_view __sv) const _NOEXCEPT; |
| 1171 | _LIBCPP_INLINE_VISIBILITY |
| 1172 | int compare(size_type __pos1, size_type __n1, __self_view __sv) const; |
| 1173 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1174 | int compare(size_type __pos1, size_type __n1, const basic_string& __str) const; |
Marshall Clow | a93b5e2 | 2014-03-04 19:17:19 +0000 | [diff] [blame] | 1175 | int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const; |
Marshall Clow | 6ac8de0 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1176 | template <class _Tp> |
| 1177 | typename enable_if |
| 1178 | < |
| 1179 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1180 | int |
| 1181 | >::type |
| 1182 | compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const; |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1183 | int compare(const value_type* __s) const _NOEXCEPT; |
| 1184 | int compare(size_type __pos1, size_type __n1, const value_type* __s) const; |
| 1185 | int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1186 | |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1187 | _LIBCPP_INLINE_VISIBILITY bool __invariants() const; |
Howard Hinnant | 08dd253 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 1188 | |
| 1189 | _LIBCPP_INLINE_VISIBILITY |
| 1190 | bool __is_long() const _NOEXCEPT |
| 1191 | {return bool(__r_.first().__s.__size_ & __short_mask);} |
| 1192 | |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1193 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1194 | |
| 1195 | bool __dereferenceable(const const_iterator* __i) const; |
| 1196 | bool __decrementable(const const_iterator* __i) const; |
| 1197 | bool __addable(const const_iterator* __i, ptrdiff_t __n) const; |
| 1198 | bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; |
| 1199 | |
| 1200 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
| 1201 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1202 | private: |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1203 | _LIBCPP_INLINE_VISIBILITY |
| 1204 | allocator_type& __alloc() _NOEXCEPT |
| 1205 | {return __r_.second();} |
| 1206 | _LIBCPP_INLINE_VISIBILITY |
| 1207 | const allocator_type& __alloc() const _NOEXCEPT |
| 1208 | {return __r_.second();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1209 | |
Evgeniy Stepanov | 4f01aa8 | 2015-10-13 23:48:28 +0000 | [diff] [blame] | 1210 | #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
Howard Hinnant | 1546718 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 1211 | |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1212 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1213 | void __set_short_size(size_type __s) _NOEXCEPT |
Howard Hinnant | 1546718 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 1214 | # if _LIBCPP_BIG_ENDIAN |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1215 | {__r_.first().__s.__size_ = (unsigned char)(__s << 1);} |
Howard Hinnant | 1546718 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 1216 | # else |
| 1217 | {__r_.first().__s.__size_ = (unsigned char)(__s);} |
| 1218 | # endif |
| 1219 | |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1220 | _LIBCPP_INLINE_VISIBILITY |
| 1221 | size_type __get_short_size() const _NOEXCEPT |
Howard Hinnant | 1546718 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 1222 | # if _LIBCPP_BIG_ENDIAN |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1223 | {return __r_.first().__s.__size_ >> 1;} |
Howard Hinnant | 1546718 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 1224 | # else |
| 1225 | {return __r_.first().__s.__size_;} |
| 1226 | # endif |
| 1227 | |
Evgeniy Stepanov | 4f01aa8 | 2015-10-13 23:48:28 +0000 | [diff] [blame] | 1228 | #else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
Howard Hinnant | 1546718 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 1229 | |
| 1230 | _LIBCPP_INLINE_VISIBILITY |
| 1231 | void __set_short_size(size_type __s) _NOEXCEPT |
| 1232 | # if _LIBCPP_BIG_ENDIAN |
| 1233 | {__r_.first().__s.__size_ = (unsigned char)(__s);} |
| 1234 | # else |
| 1235 | {__r_.first().__s.__size_ = (unsigned char)(__s << 1);} |
| 1236 | # endif |
| 1237 | |
| 1238 | _LIBCPP_INLINE_VISIBILITY |
| 1239 | size_type __get_short_size() const _NOEXCEPT |
| 1240 | # if _LIBCPP_BIG_ENDIAN |
| 1241 | {return __r_.first().__s.__size_;} |
| 1242 | # else |
| 1243 | {return __r_.first().__s.__size_ >> 1;} |
| 1244 | # endif |
| 1245 | |
Evgeniy Stepanov | 4f01aa8 | 2015-10-13 23:48:28 +0000 | [diff] [blame] | 1246 | #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
Howard Hinnant | 1546718 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 1247 | |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1248 | _LIBCPP_INLINE_VISIBILITY |
| 1249 | void __set_long_size(size_type __s) _NOEXCEPT |
| 1250 | {__r_.first().__l.__size_ = __s;} |
| 1251 | _LIBCPP_INLINE_VISIBILITY |
| 1252 | size_type __get_long_size() const _NOEXCEPT |
| 1253 | {return __r_.first().__l.__size_;} |
| 1254 | _LIBCPP_INLINE_VISIBILITY |
| 1255 | void __set_size(size_type __s) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1256 | {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);} |
| 1257 | |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1258 | _LIBCPP_INLINE_VISIBILITY |
| 1259 | void __set_long_cap(size_type __s) _NOEXCEPT |
| 1260 | {__r_.first().__l.__cap_ = __long_mask | __s;} |
| 1261 | _LIBCPP_INLINE_VISIBILITY |
| 1262 | size_type __get_long_cap() const _NOEXCEPT |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1263 | {return __r_.first().__l.__cap_ & size_type(~__long_mask);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1264 | |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1265 | _LIBCPP_INLINE_VISIBILITY |
| 1266 | void __set_long_pointer(pointer __p) _NOEXCEPT |
| 1267 | {__r_.first().__l.__data_ = __p;} |
| 1268 | _LIBCPP_INLINE_VISIBILITY |
| 1269 | pointer __get_long_pointer() _NOEXCEPT |
| 1270 | {return __r_.first().__l.__data_;} |
| 1271 | _LIBCPP_INLINE_VISIBILITY |
| 1272 | const_pointer __get_long_pointer() const _NOEXCEPT |
| 1273 | {return __r_.first().__l.__data_;} |
| 1274 | _LIBCPP_INLINE_VISIBILITY |
| 1275 | pointer __get_short_pointer() _NOEXCEPT |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1276 | {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);} |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1277 | _LIBCPP_INLINE_VISIBILITY |
| 1278 | const_pointer __get_short_pointer() const _NOEXCEPT |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1279 | {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);} |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1280 | _LIBCPP_INLINE_VISIBILITY |
| 1281 | pointer __get_pointer() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1282 | {return __is_long() ? __get_long_pointer() : __get_short_pointer();} |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1283 | _LIBCPP_INLINE_VISIBILITY |
| 1284 | const_pointer __get_pointer() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1285 | {return __is_long() ? __get_long_pointer() : __get_short_pointer();} |
| 1286 | |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1287 | _LIBCPP_INLINE_VISIBILITY |
| 1288 | void __zero() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1289 | { |
| 1290 | size_type (&__a)[__n_words] = __r_.first().__r.__words; |
| 1291 | for (unsigned __i = 0; __i < __n_words; ++__i) |
| 1292 | __a[__i] = 0; |
| 1293 | } |
| 1294 | |
| 1295 | template <size_type __a> static |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1296 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7f76450 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 1297 | size_type __align_it(size_type __s) _NOEXCEPT |
Eric Fiselier | e2d4892 | 2015-08-28 07:02:42 +0000 | [diff] [blame] | 1298 | {return (__s + (__a-1)) & ~(__a-1);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1299 | enum {__alignment = 16}; |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1300 | static _LIBCPP_INLINE_VISIBILITY |
| 1301 | size_type __recommend(size_type __s) _NOEXCEPT |
Eric Fiselier | e2d4892 | 2015-08-28 07:02:42 +0000 | [diff] [blame] | 1302 | {return (__s < __min_cap ? static_cast<size_type>(__min_cap) : |
Howard Hinnant | 7f76450 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 1303 | __align_it<sizeof(value_type) < __alignment ? |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1304 | __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1305 | |
Eric Fiselier | 6dbed46 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 1306 | inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1307 | void __init(const value_type* __s, size_type __sz, size_type __reserve); |
Eric Fiselier | 6dbed46 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 1308 | inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1309 | void __init(const value_type* __s, size_type __sz); |
Eric Fiselier | 6dbed46 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 1310 | inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1311 | void __init(size_type __n, value_type __c); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1312 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1313 | template <class _InputIterator> |
Eric Fiselier | 6dbed46 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 1314 | inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1315 | typename enable_if |
| 1316 | < |
Marshall Clow | df9db31 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 1317 | __is_exactly_input_iterator<_InputIterator>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1318 | void |
| 1319 | >::type |
| 1320 | __init(_InputIterator __first, _InputIterator __last); |
| 1321 | |
| 1322 | template <class _ForwardIterator> |
Eric Fiselier | 6dbed46 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 1323 | inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1324 | typename enable_if |
| 1325 | < |
| 1326 | __is_forward_iterator<_ForwardIterator>::value, |
| 1327 | void |
| 1328 | >::type |
| 1329 | __init(_ForwardIterator __first, _ForwardIterator __last); |
| 1330 | |
| 1331 | void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz, |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1332 | size_type __n_copy, size_type __n_del, size_type __n_add = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1333 | void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz, |
| 1334 | size_type __n_copy, size_type __n_del, |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1335 | size_type __n_add, const value_type* __p_new_stuff); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1336 | |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1337 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1338 | void __erase_to_end(size_type __pos); |
| 1339 | |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1340 | _LIBCPP_INLINE_VISIBILITY |
| 1341 | void __copy_assign_alloc(const basic_string& __str) |
| 1342 | {__copy_assign_alloc(__str, integral_constant<bool, |
| 1343 | __alloc_traits::propagate_on_container_copy_assignment::value>());} |
| 1344 | |
| 1345 | _LIBCPP_INLINE_VISIBILITY |
| 1346 | void __copy_assign_alloc(const basic_string& __str, true_type) |
| 1347 | { |
| 1348 | if (__alloc() != __str.__alloc()) |
| 1349 | { |
| 1350 | clear(); |
| 1351 | shrink_to_fit(); |
| 1352 | } |
| 1353 | __alloc() = __str.__alloc(); |
| 1354 | } |
| 1355 | |
| 1356 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1357 | void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1358 | {} |
| 1359 | |
| 1360 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1361 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | af961ed | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 1362 | void __move_assign(basic_string& __str, false_type) |
| 1363 | _NOEXCEPT_(__alloc_traits::is_always_equal::value); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1364 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f7d4c | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1365 | void __move_assign(basic_string& __str, true_type) |
Marshall Clow | af961ed | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 1366 | #if _LIBCPP_STD_VER > 14 |
| 1367 | _NOEXCEPT; |
| 1368 | #else |
Howard Hinnant | 53f7d4c | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1369 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1370 | #endif |
Marshall Clow | af961ed | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 1371 | #endif |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1372 | |
| 1373 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3fdbbd2 | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1374 | void |
Howard Hinnant | 9cbee43 | 2011-09-02 20:42:31 +0000 | [diff] [blame] | 1375 | __move_assign_alloc(basic_string& __str) |
Howard Hinnant | 3fdbbd2 | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1376 | _NOEXCEPT_( |
| 1377 | !__alloc_traits::propagate_on_container_move_assignment::value || |
| 1378 | is_nothrow_move_assignable<allocator_type>::value) |
| 1379 | {__move_assign_alloc(__str, integral_constant<bool, |
| 1380 | __alloc_traits::propagate_on_container_move_assignment::value>());} |
| 1381 | |
| 1382 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9cbee43 | 2011-09-02 20:42:31 +0000 | [diff] [blame] | 1383 | void __move_assign_alloc(basic_string& __c, true_type) |
Howard Hinnant | 3fdbbd2 | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1384 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
| 1385 | { |
| 1386 | __alloc() = _VSTD::move(__c.__alloc()); |
| 1387 | } |
| 1388 | |
| 1389 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1390 | void __move_assign_alloc(basic_string&, false_type) |
Howard Hinnant | 3fdbbd2 | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1391 | _NOEXCEPT |
| 1392 | {} |
| 1393 | |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1394 | _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); |
| 1395 | _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1396 | |
| 1397 | friend basic_string operator+<>(const basic_string&, const basic_string&); |
| 1398 | friend basic_string operator+<>(const value_type*, const basic_string&); |
| 1399 | friend basic_string operator+<>(value_type, const basic_string&); |
| 1400 | friend basic_string operator+<>(const basic_string&, const value_type*); |
| 1401 | friend basic_string operator+<>(const basic_string&, value_type); |
| 1402 | }; |
| 1403 | |
| 1404 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1405 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1406 | void |
| 1407 | basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators() |
| 1408 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1409 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1410 | __get_db()->__invalidate_all(this); |
| 1411 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1412 | } |
| 1413 | |
| 1414 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1415 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1416 | void |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1417 | basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1418 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1419 | __pos |
| 1420 | #endif |
| 1421 | ) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1422 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1423 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1424 | __c_node* __c = __get_db()->__find_c_and_lock(this); |
| 1425 | if (__c) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1426 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1427 | const_pointer __new_last = __get_pointer() + __pos; |
| 1428 | for (__i_node** __p = __c->end_; __p != __c->beg_; ) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1429 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1430 | --__p; |
| 1431 | const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); |
| 1432 | if (__i->base() > __new_last) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1433 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1434 | (*__p)->__c_ = nullptr; |
| 1435 | if (--__c->end_ != __p) |
| 1436 | memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1437 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1438 | } |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1439 | __get_db()->unlock(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1440 | } |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1441 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1445 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f7d4c | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1446 | basic_string<_CharT, _Traits, _Allocator>::basic_string() |
Marshall Clow | c912c0c | 2015-06-04 02:05:41 +0000 | [diff] [blame] | 1447 | _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1448 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1449 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1450 | __get_db()->__insert_c(this); |
| 1451 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1452 | __zero(); |
| 1453 | } |
| 1454 | |
| 1455 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1456 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1457 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a) |
Eric Fiselier | 692177d | 2015-07-18 20:40:46 +0000 | [diff] [blame] | 1458 | #if _LIBCPP_STD_VER <= 14 |
| 1459 | _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) |
| 1460 | #else |
| 1461 | _NOEXCEPT |
| 1462 | #endif |
| 1463 | : __r_(__a) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1464 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1465 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1466 | __get_db()->__insert_c(this); |
| 1467 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1468 | __zero(); |
| 1469 | } |
| 1470 | |
| 1471 | template <class _CharT, class _Traits, class _Allocator> |
Eric Fiselier | 6dbed46 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 1472 | void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, |
| 1473 | size_type __sz, |
| 1474 | size_type __reserve) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1475 | { |
| 1476 | if (__reserve > max_size()) |
| 1477 | this->__throw_length_error(); |
| 1478 | pointer __p; |
| 1479 | if (__reserve < __min_cap) |
| 1480 | { |
| 1481 | __set_short_size(__sz); |
| 1482 | __p = __get_short_pointer(); |
| 1483 | } |
| 1484 | else |
| 1485 | { |
| 1486 | size_type __cap = __recommend(__reserve); |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1487 | __p = __alloc_traits::allocate(__alloc(), __cap+1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1488 | __set_long_pointer(__p); |
| 1489 | __set_long_cap(__cap+1); |
| 1490 | __set_long_size(__sz); |
| 1491 | } |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1492 | traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1493 | traits_type::assign(__p[__sz], value_type()); |
| 1494 | } |
| 1495 | |
| 1496 | template <class _CharT, class _Traits, class _Allocator> |
| 1497 | void |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1498 | basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1499 | { |
| 1500 | if (__sz > max_size()) |
| 1501 | this->__throw_length_error(); |
| 1502 | pointer __p; |
| 1503 | if (__sz < __min_cap) |
| 1504 | { |
| 1505 | __set_short_size(__sz); |
| 1506 | __p = __get_short_pointer(); |
| 1507 | } |
| 1508 | else |
| 1509 | { |
| 1510 | size_type __cap = __recommend(__sz); |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1511 | __p = __alloc_traits::allocate(__alloc(), __cap+1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1512 | __set_long_pointer(__p); |
| 1513 | __set_long_cap(__cap+1); |
| 1514 | __set_long_size(__sz); |
| 1515 | } |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1516 | traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1517 | traits_type::assign(__p[__sz], value_type()); |
| 1518 | } |
| 1519 | |
| 1520 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1521 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1522 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1523 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1524 | _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1525 | __init(__s, traits_type::length(__s)); |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1526 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1527 | __get_db()->__insert_c(this); |
| 1528 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1532 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1533 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1534 | : __r_(__a) |
| 1535 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1536 | _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1537 | __init(__s, traits_type::length(__s)); |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1538 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1539 | __get_db()->__insert_c(this); |
| 1540 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1544 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1545 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1546 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1547 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1548 | __init(__s, __n); |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1549 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1550 | __get_db()->__insert_c(this); |
| 1551 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1555 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1556 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1557 | : __r_(__a) |
| 1558 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1559 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1560 | __init(__s, __n); |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1561 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1562 | __get_db()->__insert_c(this); |
| 1563 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | template <class _CharT, class _Traits, class _Allocator> |
| 1567 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str) |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1568 | : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc())) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1569 | { |
| 1570 | if (!__str.__is_long()) |
| 1571 | __r_.first().__r = __str.__r_.first().__r; |
| 1572 | else |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1573 | __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size()); |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1574 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1575 | __get_db()->__insert_c(this); |
| 1576 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | template <class _CharT, class _Traits, class _Allocator> |
| 1580 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a) |
| 1581 | : __r_(__a) |
| 1582 | { |
| 1583 | if (!__str.__is_long()) |
| 1584 | __r_.first().__r = __str.__r_.first().__r; |
| 1585 | else |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1586 | __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size()); |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1587 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1588 | __get_db()->__insert_c(this); |
| 1589 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1590 | } |
| 1591 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1592 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1593 | |
| 1594 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1595 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f7d4c | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1596 | basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str) |
Marshall Clow | 7b193f7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 1597 | #if _LIBCPP_STD_VER <= 14 |
Howard Hinnant | 53f7d4c | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1598 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) |
Marshall Clow | 7b193f7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 1599 | #else |
| 1600 | _NOEXCEPT |
| 1601 | #endif |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1602 | : __r_(_VSTD::move(__str.__r_)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1603 | { |
| 1604 | __str.__zero(); |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1605 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1606 | __get_db()->__insert_c(this); |
| 1607 | if (__is_long()) |
| 1608 | __get_db()->swap(this, &__str); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1609 | #endif |
| 1610 | } |
| 1611 | |
| 1612 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1613 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1614 | basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a) |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1615 | : __r_(__a) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1616 | { |
Marshall Clow | d5549cc | 2014-07-17 15:32:20 +0000 | [diff] [blame] | 1617 | if (__str.__is_long() && __a != __str.__alloc()) // copy, not move |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1618 | __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size()); |
Marshall Clow | d5549cc | 2014-07-17 15:32:20 +0000 | [diff] [blame] | 1619 | else |
| 1620 | { |
| 1621 | __r_.first().__r = __str.__r_.first().__r; |
| 1622 | __str.__zero(); |
| 1623 | } |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1624 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1625 | __get_db()->__insert_c(this); |
| 1626 | if (__is_long()) |
| 1627 | __get_db()->swap(this, &__str); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1628 | #endif |
| 1629 | } |
| 1630 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1631 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1632 | |
| 1633 | template <class _CharT, class _Traits, class _Allocator> |
| 1634 | void |
| 1635 | basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c) |
| 1636 | { |
| 1637 | if (__n > max_size()) |
| 1638 | this->__throw_length_error(); |
| 1639 | pointer __p; |
| 1640 | if (__n < __min_cap) |
| 1641 | { |
| 1642 | __set_short_size(__n); |
| 1643 | __p = __get_short_pointer(); |
| 1644 | } |
| 1645 | else |
| 1646 | { |
| 1647 | size_type __cap = __recommend(__n); |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1648 | __p = __alloc_traits::allocate(__alloc(), __cap+1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1649 | __set_long_pointer(__p); |
| 1650 | __set_long_cap(__cap+1); |
| 1651 | __set_long_size(__n); |
| 1652 | } |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1653 | traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1654 | traits_type::assign(__p[__n], value_type()); |
| 1655 | } |
| 1656 | |
| 1657 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1658 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1659 | basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c) |
| 1660 | { |
| 1661 | __init(__n, __c); |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1662 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1663 | __get_db()->__insert_c(this); |
| 1664 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1668 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1669 | basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a) |
| 1670 | : __r_(__a) |
| 1671 | { |
| 1672 | __init(__n, __c); |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1673 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1674 | __get_db()->__insert_c(this); |
| 1675 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1676 | } |
| 1677 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1678 | template <class _CharT, class _Traits, class _Allocator> |
| 1679 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n, |
| 1680 | const allocator_type& __a) |
| 1681 | : __r_(__a) |
| 1682 | { |
| 1683 | size_type __str_sz = __str.size(); |
| 1684 | if (__pos > __str_sz) |
| 1685 | this->__throw_out_of_range(); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1686 | __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos)); |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1687 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1688 | __get_db()->__insert_c(this); |
| 1689 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1690 | } |
| 1691 | |
| 1692 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | f4f7d8f | 2016-04-07 18:13:41 +0000 | [diff] [blame] | 1693 | inline _LIBCPP_INLINE_VISIBILITY |
| 1694 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, |
| 1695 | const allocator_type& __a) |
| 1696 | : __r_(__a) |
| 1697 | { |
| 1698 | size_type __str_sz = __str.size(); |
| 1699 | if (__pos > __str_sz) |
| 1700 | this->__throw_out_of_range(); |
| 1701 | __init(__str.data() + __pos, __str_sz - __pos); |
| 1702 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1703 | __get_db()->__insert_c(this); |
| 1704 | #endif |
| 1705 | } |
| 1706 | |
| 1707 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1708 | inline _LIBCPP_INLINE_VISIBILITY |
| 1709 | basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv) |
| 1710 | { |
| 1711 | __init(__sv.data(), __sv.size()); |
| 1712 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1713 | __get_db()->__insert_c(this); |
| 1714 | #endif |
| 1715 | } |
| 1716 | |
| 1717 | template <class _CharT, class _Traits, class _Allocator> |
| 1718 | inline _LIBCPP_INLINE_VISIBILITY |
| 1719 | basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv, const allocator_type& __a) |
| 1720 | : __r_(__a) |
| 1721 | { |
| 1722 | __init(__sv.data(), __sv.size()); |
| 1723 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1724 | __get_db()->__insert_c(this); |
| 1725 | #endif |
| 1726 | } |
| 1727 | |
| 1728 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1729 | template <class _InputIterator> |
| 1730 | typename enable_if |
| 1731 | < |
Marshall Clow | df9db31 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 1732 | __is_exactly_input_iterator<_InputIterator>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1733 | void |
| 1734 | >::type |
| 1735 | basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last) |
| 1736 | { |
| 1737 | __zero(); |
| 1738 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1739 | try |
| 1740 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1741 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1742 | for (; __first != __last; ++__first) |
| 1743 | push_back(*__first); |
| 1744 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1745 | } |
| 1746 | catch (...) |
| 1747 | { |
| 1748 | if (__is_long()) |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1749 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1750 | throw; |
| 1751 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1752 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1753 | } |
| 1754 | |
| 1755 | template <class _CharT, class _Traits, class _Allocator> |
| 1756 | template <class _ForwardIterator> |
| 1757 | typename enable_if |
| 1758 | < |
| 1759 | __is_forward_iterator<_ForwardIterator>::value, |
| 1760 | void |
| 1761 | >::type |
| 1762 | basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last) |
| 1763 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1764 | size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1765 | if (__sz > max_size()) |
| 1766 | this->__throw_length_error(); |
| 1767 | pointer __p; |
| 1768 | if (__sz < __min_cap) |
| 1769 | { |
| 1770 | __set_short_size(__sz); |
| 1771 | __p = __get_short_pointer(); |
| 1772 | } |
| 1773 | else |
| 1774 | { |
| 1775 | size_type __cap = __recommend(__sz); |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1776 | __p = __alloc_traits::allocate(__alloc(), __cap+1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1777 | __set_long_pointer(__p); |
| 1778 | __set_long_cap(__cap+1); |
| 1779 | __set_long_size(__sz); |
| 1780 | } |
Eric Fiselier | b991975 | 2014-10-27 19:28:20 +0000 | [diff] [blame] | 1781 | for (; __first != __last; ++__first, (void) ++__p) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1782 | traits_type::assign(*__p, *__first); |
| 1783 | traits_type::assign(*__p, value_type()); |
| 1784 | } |
| 1785 | |
| 1786 | template <class _CharT, class _Traits, class _Allocator> |
| 1787 | template<class _InputIterator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1788 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1789 | basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last) |
| 1790 | { |
| 1791 | __init(__first, __last); |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1792 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1793 | __get_db()->__insert_c(this); |
| 1794 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | template <class _CharT, class _Traits, class _Allocator> |
| 1798 | template<class _InputIterator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1799 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1800 | basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last, |
| 1801 | const allocator_type& __a) |
| 1802 | : __r_(__a) |
| 1803 | { |
| 1804 | __init(__first, __last); |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1805 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1806 | __get_db()->__insert_c(this); |
| 1807 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1808 | } |
| 1809 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1810 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 1811 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1812 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1813 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1814 | basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il) |
| 1815 | { |
| 1816 | __init(__il.begin(), __il.end()); |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1817 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1818 | __get_db()->__insert_c(this); |
| 1819 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1823 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1824 | basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a) |
| 1825 | : __r_(__a) |
| 1826 | { |
| 1827 | __init(__il.begin(), __il.end()); |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1828 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1829 | __get_db()->__insert_c(this); |
| 1830 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1831 | } |
| 1832 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1833 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 1834 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1835 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1836 | basic_string<_CharT, _Traits, _Allocator>::~basic_string() |
| 1837 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1838 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1839 | __get_db()->__erase_c(this); |
| 1840 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1841 | if (__is_long()) |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1842 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | template <class _CharT, class _Traits, class _Allocator> |
| 1846 | void |
| 1847 | basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace |
| 1848 | (size_type __old_cap, size_type __delta_cap, size_type __old_sz, |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1849 | size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1850 | { |
| 1851 | size_type __ms = max_size(); |
| 1852 | if (__delta_cap > __ms - __old_cap - 1) |
| 1853 | this->__throw_length_error(); |
| 1854 | pointer __old_p = __get_pointer(); |
| 1855 | size_type __cap = __old_cap < __ms / 2 - __alignment ? |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1856 | __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) : |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1857 | __ms - 1; |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1858 | pointer __p = __alloc_traits::allocate(__alloc(), __cap+1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1859 | __invalidate_all_iterators(); |
| 1860 | if (__n_copy != 0) |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1861 | traits_type::copy(_VSTD::__to_raw_pointer(__p), |
| 1862 | _VSTD::__to_raw_pointer(__old_p), __n_copy); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1863 | if (__n_add != 0) |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1864 | traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1865 | size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; |
| 1866 | if (__sec_cp_sz != 0) |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1867 | traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add, |
| 1868 | _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1869 | if (__old_cap+1 != __min_cap) |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1870 | __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1871 | __set_long_pointer(__p); |
| 1872 | __set_long_cap(__cap+1); |
| 1873 | __old_sz = __n_copy + __n_add + __sec_cp_sz; |
| 1874 | __set_long_size(__old_sz); |
| 1875 | traits_type::assign(__p[__old_sz], value_type()); |
| 1876 | } |
| 1877 | |
| 1878 | template <class _CharT, class _Traits, class _Allocator> |
| 1879 | void |
| 1880 | basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz, |
| 1881 | size_type __n_copy, size_type __n_del, size_type __n_add) |
| 1882 | { |
| 1883 | size_type __ms = max_size(); |
Marshall Clow | ecc8d7b | 2013-11-06 14:24:38 +0000 | [diff] [blame] | 1884 | if (__delta_cap > __ms - __old_cap) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1885 | this->__throw_length_error(); |
| 1886 | pointer __old_p = __get_pointer(); |
| 1887 | size_type __cap = __old_cap < __ms / 2 - __alignment ? |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1888 | __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) : |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1889 | __ms - 1; |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1890 | pointer __p = __alloc_traits::allocate(__alloc(), __cap+1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1891 | __invalidate_all_iterators(); |
| 1892 | if (__n_copy != 0) |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1893 | traits_type::copy(_VSTD::__to_raw_pointer(__p), |
| 1894 | _VSTD::__to_raw_pointer(__old_p), __n_copy); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1895 | size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; |
| 1896 | if (__sec_cp_sz != 0) |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1897 | traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add, |
| 1898 | _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, |
| 1899 | __sec_cp_sz); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1900 | if (__old_cap+1 != __min_cap) |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1901 | __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1902 | __set_long_pointer(__p); |
| 1903 | __set_long_cap(__cap+1); |
| 1904 | } |
| 1905 | |
| 1906 | // assign |
| 1907 | |
| 1908 | template <class _CharT, class _Traits, class _Allocator> |
| 1909 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1910 | basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1911 | { |
Alp Toker | ec34c48 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 1912 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1913 | size_type __cap = capacity(); |
| 1914 | if (__cap >= __n) |
| 1915 | { |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1916 | value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1917 | traits_type::move(__p, __s, __n); |
| 1918 | traits_type::assign(__p[__n], value_type()); |
| 1919 | __set_size(__n); |
| 1920 | __invalidate_iterators_past(__n); |
| 1921 | } |
| 1922 | else |
| 1923 | { |
| 1924 | size_type __sz = size(); |
| 1925 | __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s); |
| 1926 | } |
| 1927 | return *this; |
| 1928 | } |
| 1929 | |
| 1930 | template <class _CharT, class _Traits, class _Allocator> |
| 1931 | basic_string<_CharT, _Traits, _Allocator>& |
| 1932 | basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c) |
| 1933 | { |
| 1934 | size_type __cap = capacity(); |
| 1935 | if (__cap < __n) |
| 1936 | { |
| 1937 | size_type __sz = size(); |
| 1938 | __grow_by(__cap, __n - __cap, __sz, 0, __sz); |
| 1939 | } |
| 1940 | else |
| 1941 | __invalidate_iterators_past(__n); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1942 | value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1943 | traits_type::assign(__p, __n, __c); |
| 1944 | traits_type::assign(__p[__n], value_type()); |
| 1945 | __set_size(__n); |
| 1946 | return *this; |
| 1947 | } |
| 1948 | |
| 1949 | template <class _CharT, class _Traits, class _Allocator> |
| 1950 | basic_string<_CharT, _Traits, _Allocator>& |
| 1951 | basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c) |
| 1952 | { |
| 1953 | pointer __p; |
| 1954 | if (__is_long()) |
| 1955 | { |
| 1956 | __p = __get_long_pointer(); |
| 1957 | __set_long_size(1); |
| 1958 | } |
| 1959 | else |
| 1960 | { |
| 1961 | __p = __get_short_pointer(); |
| 1962 | __set_short_size(1); |
| 1963 | } |
| 1964 | traits_type::assign(*__p, __c); |
| 1965 | traits_type::assign(*++__p, value_type()); |
| 1966 | __invalidate_iterators_past(1); |
| 1967 | return *this; |
| 1968 | } |
| 1969 | |
| 1970 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1971 | basic_string<_CharT, _Traits, _Allocator>& |
| 1972 | basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str) |
| 1973 | { |
| 1974 | if (this != &__str) |
| 1975 | { |
| 1976 | __copy_assign_alloc(__str); |
Marshall Clow | f40ec90 | 2016-03-09 18:08:29 +0000 | [diff] [blame] | 1977 | assign(__str.data(), __str.size()); |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1978 | } |
| 1979 | return *this; |
| 1980 | } |
| 1981 | |
| 1982 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 1983 | |
| 1984 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1985 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1986 | void |
| 1987 | basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type) |
Marshall Clow | af961ed | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 1988 | _NOEXCEPT_(__alloc_traits::is_always_equal::value) |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1989 | { |
| 1990 | if (__alloc() != __str.__alloc()) |
| 1991 | assign(__str); |
| 1992 | else |
| 1993 | __move_assign(__str, true_type()); |
| 1994 | } |
| 1995 | |
| 1996 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1997 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1998 | void |
| 1999 | basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type) |
Marshall Clow | af961ed | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2000 | #if _LIBCPP_STD_VER > 14 |
| 2001 | _NOEXCEPT |
| 2002 | #else |
Howard Hinnant | 53f7d4c | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 2003 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
Marshall Clow | af961ed | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2004 | #endif |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2005 | { |
| 2006 | clear(); |
| 2007 | shrink_to_fit(); |
Howard Hinnant | 3fdbbd2 | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 2008 | __r_.first() = __str.__r_.first(); |
| 2009 | __move_assign_alloc(__str); |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2010 | __str.__zero(); |
| 2011 | } |
| 2012 | |
| 2013 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2014 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2015 | basic_string<_CharT, _Traits, _Allocator>& |
| 2016 | basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str) |
Marshall Clow | af961ed | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2017 | _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2018 | { |
| 2019 | __move_assign(__str, integral_constant<bool, |
| 2020 | __alloc_traits::propagate_on_container_move_assignment::value>()); |
| 2021 | return *this; |
| 2022 | } |
| 2023 | |
| 2024 | #endif |
| 2025 | |
| 2026 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2027 | template<class _InputIterator> |
| 2028 | typename enable_if |
| 2029 | < |
Marshall Clow | df9db31 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 2030 | __is_exactly_input_iterator <_InputIterator>::value |
| 2031 | || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2032 | basic_string<_CharT, _Traits, _Allocator>& |
| 2033 | >::type |
| 2034 | basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last) |
| 2035 | { |
Marshall Clow | d979eed | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 2036 | const basic_string __temp(__first, __last, __alloc()); |
Marshall Clow | df9db31 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 2037 | assign(__temp.data(), __temp.size()); |
Argyrios Kyrtzidis | 1dc6f7a | 2012-10-13 02:03:45 +0000 | [diff] [blame] | 2038 | return *this; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | template <class _CharT, class _Traits, class _Allocator> |
| 2042 | template<class _ForwardIterator> |
| 2043 | typename enable_if |
| 2044 | < |
Marshall Clow | df9db31 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 2045 | __is_forward_iterator<_ForwardIterator>::value |
| 2046 | && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2047 | basic_string<_CharT, _Traits, _Allocator>& |
| 2048 | >::type |
| 2049 | basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) |
| 2050 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2051 | size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2052 | size_type __cap = capacity(); |
| 2053 | if (__cap < __n) |
| 2054 | { |
| 2055 | size_type __sz = size(); |
| 2056 | __grow_by(__cap, __n - __cap, __sz, 0, __sz); |
| 2057 | } |
| 2058 | else |
| 2059 | __invalidate_iterators_past(__n); |
| 2060 | pointer __p = __get_pointer(); |
| 2061 | for (; __first != __last; ++__first, ++__p) |
| 2062 | traits_type::assign(*__p, *__first); |
| 2063 | traits_type::assign(*__p, value_type()); |
| 2064 | __set_size(__n); |
| 2065 | return *this; |
| 2066 | } |
| 2067 | |
| 2068 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2069 | basic_string<_CharT, _Traits, _Allocator>& |
| 2070 | basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n) |
| 2071 | { |
| 2072 | size_type __sz = __str.size(); |
| 2073 | if (__pos > __sz) |
| 2074 | this->__throw_out_of_range(); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2075 | return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2076 | } |
| 2077 | |
| 2078 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 6ac8de0 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2079 | template <class _Tp> |
| 2080 | typename enable_if |
| 2081 | < |
| 2082 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 2083 | basic_string<_CharT, _Traits, _Allocator>& |
| 2084 | >::type |
| 2085 | basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n) |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2086 | { |
Marshall Clow | 6ac8de0 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2087 | __self_view __sv = __t; |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2088 | size_type __sz = __sv.size(); |
| 2089 | if (__pos > __sz) |
| 2090 | this->__throw_out_of_range(); |
| 2091 | return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos)); |
| 2092 | } |
| 2093 | |
| 2094 | |
| 2095 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2096 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2097 | basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2098 | { |
Alp Toker | ec34c48 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2099 | _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2100 | return assign(__s, traits_type::length(__s)); |
| 2101 | } |
| 2102 | |
| 2103 | // append |
| 2104 | |
| 2105 | template <class _CharT, class _Traits, class _Allocator> |
| 2106 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2107 | basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2108 | { |
Alp Toker | ec34c48 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2109 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2110 | size_type __cap = capacity(); |
| 2111 | size_type __sz = size(); |
| 2112 | if (__cap - __sz >= __n) |
| 2113 | { |
| 2114 | if (__n) |
| 2115 | { |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2116 | value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2117 | traits_type::copy(__p + __sz, __s, __n); |
| 2118 | __sz += __n; |
| 2119 | __set_size(__sz); |
| 2120 | traits_type::assign(__p[__sz], value_type()); |
| 2121 | } |
| 2122 | } |
| 2123 | else |
| 2124 | __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s); |
| 2125 | return *this; |
| 2126 | } |
| 2127 | |
| 2128 | template <class _CharT, class _Traits, class _Allocator> |
| 2129 | basic_string<_CharT, _Traits, _Allocator>& |
| 2130 | basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c) |
| 2131 | { |
| 2132 | if (__n) |
| 2133 | { |
| 2134 | size_type __cap = capacity(); |
| 2135 | size_type __sz = size(); |
| 2136 | if (__cap - __sz < __n) |
| 2137 | __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); |
| 2138 | pointer __p = __get_pointer(); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2139 | traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2140 | __sz += __n; |
| 2141 | __set_size(__sz); |
| 2142 | traits_type::assign(__p[__sz], value_type()); |
| 2143 | } |
| 2144 | return *this; |
| 2145 | } |
| 2146 | |
| 2147 | template <class _CharT, class _Traits, class _Allocator> |
| 2148 | void |
| 2149 | basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c) |
| 2150 | { |
Howard Hinnant | 1546718 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2151 | bool __is_short = !__is_long(); |
| 2152 | size_type __cap; |
| 2153 | size_type __sz; |
| 2154 | if (__is_short) |
| 2155 | { |
| 2156 | __cap = __min_cap - 1; |
| 2157 | __sz = __get_short_size(); |
| 2158 | } |
| 2159 | else |
| 2160 | { |
| 2161 | __cap = __get_long_cap() - 1; |
| 2162 | __sz = __get_long_size(); |
| 2163 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2164 | if (__sz == __cap) |
Howard Hinnant | 1546718 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2165 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2166 | __grow_by(__cap, 1, __sz, __sz, 0); |
Howard Hinnant | 1546718 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2167 | __is_short = !__is_long(); |
| 2168 | } |
| 2169 | pointer __p; |
| 2170 | if (__is_short) |
| 2171 | { |
| 2172 | __p = __get_short_pointer() + __sz; |
| 2173 | __set_short_size(__sz+1); |
| 2174 | } |
| 2175 | else |
| 2176 | { |
| 2177 | __p = __get_long_pointer() + __sz; |
| 2178 | __set_long_size(__sz+1); |
| 2179 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2180 | traits_type::assign(*__p, __c); |
| 2181 | traits_type::assign(*++__p, value_type()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2182 | } |
| 2183 | |
| 2184 | template <class _CharT, class _Traits, class _Allocator> |
| 2185 | template<class _InputIterator> |
| 2186 | typename enable_if |
| 2187 | < |
Marshall Clow | df9db31 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 2188 | __is_exactly_input_iterator<_InputIterator>::value |
| 2189 | || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2190 | basic_string<_CharT, _Traits, _Allocator>& |
| 2191 | >::type |
| 2192 | basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last) |
| 2193 | { |
Marshall Clow | d979eed | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 2194 | const basic_string __temp (__first, __last, __alloc()); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2195 | append(__temp.data(), __temp.size()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2196 | return *this; |
| 2197 | } |
| 2198 | |
Marshall Clow | ac655ef | 2016-09-07 03:32:06 +0000 | [diff] [blame] | 2199 | template <class _Tp> |
Marshall Clow | d979eed | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 2200 | bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last) |
| 2201 | { |
| 2202 | return __first <= __p && __p < __last; |
| 2203 | } |
| 2204 | |
Marshall Clow | ac655ef | 2016-09-07 03:32:06 +0000 | [diff] [blame] | 2205 | template <class _Tp1, class _Tp2> |
| 2206 | bool __ptr_in_range (const _Tp1* __p, const _Tp2* __first, const _Tp2* __last) |
| 2207 | { |
| 2208 | return false; |
| 2209 | } |
| 2210 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2211 | template <class _CharT, class _Traits, class _Allocator> |
| 2212 | template<class _ForwardIterator> |
| 2213 | typename enable_if |
| 2214 | < |
Marshall Clow | df9db31 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 2215 | __is_forward_iterator<_ForwardIterator>::value |
| 2216 | && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2217 | basic_string<_CharT, _Traits, _Allocator>& |
| 2218 | >::type |
| 2219 | basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last) |
| 2220 | { |
| 2221 | size_type __sz = size(); |
| 2222 | size_type __cap = capacity(); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2223 | size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2224 | if (__n) |
| 2225 | { |
Marshall Clow | d979eed | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 2226 | if ( __ptr_in_range(&*__first, data(), data() + size())) |
| 2227 | { |
| 2228 | const basic_string __temp (__first, __last, __alloc()); |
| 2229 | append(__temp.data(), __temp.size()); |
| 2230 | } |
| 2231 | else |
| 2232 | { |
| 2233 | if (__cap - __sz < __n) |
| 2234 | __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); |
| 2235 | pointer __p = __get_pointer() + __sz; |
| 2236 | for (; __first != __last; ++__p, ++__first) |
| 2237 | traits_type::assign(*__p, *__first); |
| 2238 | traits_type::assign(*__p, value_type()); |
| 2239 | __set_size(__sz + __n); |
| 2240 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2241 | } |
| 2242 | return *this; |
| 2243 | } |
| 2244 | |
| 2245 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2246 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2247 | basic_string<_CharT, _Traits, _Allocator>& |
| 2248 | basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str) |
| 2249 | { |
| 2250 | return append(__str.data(), __str.size()); |
| 2251 | } |
| 2252 | |
| 2253 | template <class _CharT, class _Traits, class _Allocator> |
| 2254 | basic_string<_CharT, _Traits, _Allocator>& |
| 2255 | basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n) |
| 2256 | { |
| 2257 | size_type __sz = __str.size(); |
| 2258 | if (__pos > __sz) |
| 2259 | this->__throw_out_of_range(); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2260 | return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 42a87db | 2016-10-03 23:40:48 +0000 | [diff] [blame^] | 2264 | template <class _Tp> |
Marshall Clow | 6ac8de0 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2265 | typename enable_if |
| 2266 | < |
| 2267 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 2268 | basic_string<_CharT, _Traits, _Allocator>& |
| 2269 | >::type |
| 2270 | basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n) |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2271 | { |
Marshall Clow | 6ac8de0 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2272 | __self_view __sv = __t; |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2273 | size_type __sz = __sv.size(); |
| 2274 | if (__pos > __sz) |
| 2275 | this->__throw_out_of_range(); |
| 2276 | return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos)); |
| 2277 | } |
| 2278 | |
| 2279 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2280 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2281 | basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2282 | { |
Alp Toker | ec34c48 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2283 | _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2284 | return append(__s, traits_type::length(__s)); |
| 2285 | } |
| 2286 | |
| 2287 | // insert |
| 2288 | |
| 2289 | template <class _CharT, class _Traits, class _Allocator> |
| 2290 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2291 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2292 | { |
Alp Toker | ec34c48 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2293 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2294 | size_type __sz = size(); |
| 2295 | if (__pos > __sz) |
| 2296 | this->__throw_out_of_range(); |
| 2297 | size_type __cap = capacity(); |
| 2298 | if (__cap - __sz >= __n) |
| 2299 | { |
| 2300 | if (__n) |
| 2301 | { |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2302 | value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2303 | size_type __n_move = __sz - __pos; |
| 2304 | if (__n_move != 0) |
| 2305 | { |
| 2306 | if (__p + __pos <= __s && __s < __p + __sz) |
| 2307 | __s += __n; |
| 2308 | traits_type::move(__p + __pos + __n, __p + __pos, __n_move); |
| 2309 | } |
| 2310 | traits_type::move(__p + __pos, __s, __n); |
| 2311 | __sz += __n; |
| 2312 | __set_size(__sz); |
| 2313 | traits_type::assign(__p[__sz], value_type()); |
| 2314 | } |
| 2315 | } |
| 2316 | else |
| 2317 | __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s); |
| 2318 | return *this; |
| 2319 | } |
| 2320 | |
| 2321 | template <class _CharT, class _Traits, class _Allocator> |
| 2322 | basic_string<_CharT, _Traits, _Allocator>& |
| 2323 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c) |
| 2324 | { |
| 2325 | size_type __sz = size(); |
| 2326 | if (__pos > __sz) |
| 2327 | this->__throw_out_of_range(); |
| 2328 | if (__n) |
| 2329 | { |
| 2330 | size_type __cap = capacity(); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2331 | value_type* __p; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2332 | if (__cap - __sz >= __n) |
| 2333 | { |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2334 | __p = _VSTD::__to_raw_pointer(__get_pointer()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2335 | size_type __n_move = __sz - __pos; |
| 2336 | if (__n_move != 0) |
| 2337 | traits_type::move(__p + __pos + __n, __p + __pos, __n_move); |
| 2338 | } |
| 2339 | else |
| 2340 | { |
| 2341 | __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2342 | __p = _VSTD::__to_raw_pointer(__get_long_pointer()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2343 | } |
| 2344 | traits_type::assign(__p + __pos, __n, __c); |
| 2345 | __sz += __n; |
| 2346 | __set_size(__sz); |
| 2347 | traits_type::assign(__p[__sz], value_type()); |
| 2348 | } |
| 2349 | return *this; |
| 2350 | } |
| 2351 | |
| 2352 | template <class _CharT, class _Traits, class _Allocator> |
| 2353 | template<class _InputIterator> |
| 2354 | typename enable_if |
| 2355 | < |
Marshall Clow | df9db31 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 2356 | __is_exactly_input_iterator<_InputIterator>::value |
| 2357 | || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, |
| 2358 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2359 | >::type |
| 2360 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last) |
| 2361 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 2362 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2363 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 2364 | "string::insert(iterator, range) called with an iterator not" |
| 2365 | " referring to this string"); |
| 2366 | #endif |
Marshall Clow | d979eed | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 2367 | const basic_string __temp(__first, __last, __alloc()); |
Marshall Clow | df9db31 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 2368 | return insert(__pos, __temp.data(), __temp.data() + __temp.size()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2369 | } |
| 2370 | |
| 2371 | template <class _CharT, class _Traits, class _Allocator> |
| 2372 | template<class _ForwardIterator> |
| 2373 | typename enable_if |
| 2374 | < |
Marshall Clow | df9db31 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 2375 | __is_forward_iterator<_ForwardIterator>::value |
| 2376 | && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2377 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 2378 | >::type |
| 2379 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last) |
| 2380 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 2381 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2382 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 2383 | "string::insert(iterator, range) called with an iterator not" |
| 2384 | " referring to this string"); |
| 2385 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2386 | size_type __ip = static_cast<size_type>(__pos - begin()); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2387 | size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2388 | if (__n) |
| 2389 | { |
Marshall Clow | d979eed | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 2390 | if ( __ptr_in_range(&*__first, data(), data() + size())) |
| 2391 | { |
| 2392 | const basic_string __temp(__first, __last, __alloc()); |
| 2393 | return insert(__pos, __temp.data(), __temp.data() + __temp.size()); |
| 2394 | } |
| 2395 | |
| 2396 | size_type __sz = size(); |
| 2397 | size_type __cap = capacity(); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2398 | value_type* __p; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2399 | if (__cap - __sz >= __n) |
| 2400 | { |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2401 | __p = _VSTD::__to_raw_pointer(__get_pointer()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2402 | size_type __n_move = __sz - __ip; |
| 2403 | if (__n_move != 0) |
| 2404 | traits_type::move(__p + __ip + __n, __p + __ip, __n_move); |
| 2405 | } |
| 2406 | else |
| 2407 | { |
| 2408 | __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2409 | __p = _VSTD::__to_raw_pointer(__get_long_pointer()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2410 | } |
| 2411 | __sz += __n; |
| 2412 | __set_size(__sz); |
| 2413 | traits_type::assign(__p[__sz], value_type()); |
| 2414 | for (__p += __ip; __first != __last; ++__p, ++__first) |
| 2415 | traits_type::assign(*__p, *__first); |
| 2416 | } |
| 2417 | return begin() + __ip; |
| 2418 | } |
| 2419 | |
| 2420 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2421 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2422 | basic_string<_CharT, _Traits, _Allocator>& |
| 2423 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str) |
| 2424 | { |
| 2425 | return insert(__pos1, __str.data(), __str.size()); |
| 2426 | } |
| 2427 | |
| 2428 | template <class _CharT, class _Traits, class _Allocator> |
| 2429 | basic_string<_CharT, _Traits, _Allocator>& |
| 2430 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str, |
| 2431 | size_type __pos2, size_type __n) |
| 2432 | { |
| 2433 | size_type __str_sz = __str.size(); |
| 2434 | if (__pos2 > __str_sz) |
| 2435 | this->__throw_out_of_range(); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2436 | return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2437 | } |
| 2438 | |
| 2439 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 6ac8de0 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2440 | template <class _Tp> |
| 2441 | typename enable_if |
| 2442 | < |
| 2443 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 2444 | basic_string<_CharT, _Traits, _Allocator>& |
| 2445 | >::type |
| 2446 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t, |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2447 | size_type __pos2, size_type __n) |
| 2448 | { |
Marshall Clow | 6ac8de0 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2449 | __self_view __sv = __t; |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2450 | size_type __str_sz = __sv.size(); |
| 2451 | if (__pos2 > __str_sz) |
| 2452 | this->__throw_out_of_range(); |
| 2453 | return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2)); |
| 2454 | } |
| 2455 | |
| 2456 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2457 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2458 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2459 | { |
Alp Toker | ec34c48 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2460 | _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2461 | return insert(__pos, __s, traits_type::length(__s)); |
| 2462 | } |
| 2463 | |
| 2464 | template <class _CharT, class _Traits, class _Allocator> |
| 2465 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 2466 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c) |
| 2467 | { |
| 2468 | size_type __ip = static_cast<size_type>(__pos - begin()); |
| 2469 | size_type __sz = size(); |
| 2470 | size_type __cap = capacity(); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2471 | value_type* __p; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2472 | if (__cap == __sz) |
| 2473 | { |
| 2474 | __grow_by(__cap, 1, __sz, __ip, 0, 1); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2475 | __p = _VSTD::__to_raw_pointer(__get_long_pointer()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2476 | } |
| 2477 | else |
| 2478 | { |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2479 | __p = _VSTD::__to_raw_pointer(__get_pointer()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2480 | size_type __n_move = __sz - __ip; |
| 2481 | if (__n_move != 0) |
| 2482 | traits_type::move(__p + __ip + 1, __p + __ip, __n_move); |
| 2483 | } |
| 2484 | traits_type::assign(__p[__ip], __c); |
| 2485 | traits_type::assign(__p[++__sz], value_type()); |
| 2486 | __set_size(__sz); |
| 2487 | return begin() + static_cast<difference_type>(__ip); |
| 2488 | } |
| 2489 | |
| 2490 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2491 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2492 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 2493 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c) |
| 2494 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 2495 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2496 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 2497 | "string::insert(iterator, n, value) called with an iterator not" |
| 2498 | " referring to this string"); |
| 2499 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2500 | difference_type __p = __pos - begin(); |
| 2501 | insert(static_cast<size_type>(__p), __n, __c); |
| 2502 | return begin() + __p; |
| 2503 | } |
| 2504 | |
| 2505 | // replace |
| 2506 | |
| 2507 | template <class _CharT, class _Traits, class _Allocator> |
| 2508 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2509 | basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2510 | { |
Alp Toker | ec34c48 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2511 | _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2512 | size_type __sz = size(); |
| 2513 | if (__pos > __sz) |
| 2514 | this->__throw_out_of_range(); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2515 | __n1 = _VSTD::min(__n1, __sz - __pos); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2516 | size_type __cap = capacity(); |
| 2517 | if (__cap - __sz + __n1 >= __n2) |
| 2518 | { |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2519 | value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2520 | if (__n1 != __n2) |
| 2521 | { |
| 2522 | size_type __n_move = __sz - __pos - __n1; |
| 2523 | if (__n_move != 0) |
| 2524 | { |
| 2525 | if (__n1 > __n2) |
| 2526 | { |
| 2527 | traits_type::move(__p + __pos, __s, __n2); |
| 2528 | traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); |
| 2529 | goto __finish; |
| 2530 | } |
| 2531 | if (__p + __pos < __s && __s < __p + __sz) |
| 2532 | { |
| 2533 | if (__p + __pos + __n1 <= __s) |
| 2534 | __s += __n2 - __n1; |
| 2535 | else // __p + __pos < __s < __p + __pos + __n1 |
| 2536 | { |
| 2537 | traits_type::move(__p + __pos, __s, __n1); |
| 2538 | __pos += __n1; |
| 2539 | __s += __n2; |
| 2540 | __n2 -= __n1; |
| 2541 | __n1 = 0; |
| 2542 | } |
| 2543 | } |
| 2544 | traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); |
| 2545 | } |
| 2546 | } |
| 2547 | traits_type::move(__p + __pos, __s, __n2); |
| 2548 | __finish: |
| 2549 | __sz += __n2 - __n1; |
| 2550 | __set_size(__sz); |
| 2551 | __invalidate_iterators_past(__sz); |
| 2552 | traits_type::assign(__p[__sz], value_type()); |
| 2553 | } |
| 2554 | else |
| 2555 | __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s); |
| 2556 | return *this; |
| 2557 | } |
| 2558 | |
| 2559 | template <class _CharT, class _Traits, class _Allocator> |
| 2560 | basic_string<_CharT, _Traits, _Allocator>& |
| 2561 | basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c) |
| 2562 | { |
| 2563 | size_type __sz = size(); |
| 2564 | if (__pos > __sz) |
| 2565 | this->__throw_out_of_range(); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2566 | __n1 = _VSTD::min(__n1, __sz - __pos); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2567 | size_type __cap = capacity(); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2568 | value_type* __p; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2569 | if (__cap - __sz + __n1 >= __n2) |
| 2570 | { |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2571 | __p = _VSTD::__to_raw_pointer(__get_pointer()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2572 | if (__n1 != __n2) |
| 2573 | { |
| 2574 | size_type __n_move = __sz - __pos - __n1; |
| 2575 | if (__n_move != 0) |
| 2576 | traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); |
| 2577 | } |
| 2578 | } |
| 2579 | else |
| 2580 | { |
| 2581 | __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2582 | __p = _VSTD::__to_raw_pointer(__get_long_pointer()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2583 | } |
| 2584 | traits_type::assign(__p + __pos, __n2, __c); |
| 2585 | __sz += __n2 - __n1; |
| 2586 | __set_size(__sz); |
| 2587 | __invalidate_iterators_past(__sz); |
| 2588 | traits_type::assign(__p[__sz], value_type()); |
| 2589 | return *this; |
| 2590 | } |
| 2591 | |
| 2592 | template <class _CharT, class _Traits, class _Allocator> |
| 2593 | template<class _InputIterator> |
| 2594 | typename enable_if |
| 2595 | < |
| 2596 | __is_input_iterator<_InputIterator>::value, |
| 2597 | basic_string<_CharT, _Traits, _Allocator>& |
| 2598 | >::type |
Howard Hinnant | 7b2cb48 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 2599 | basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2600 | _InputIterator __j1, _InputIterator __j2) |
| 2601 | { |
Marshall Clow | d979eed | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 2602 | const basic_string __temp(__j1, __j2, __alloc()); |
Marshall Clow | df9db31 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 2603 | return this->replace(__i1, __i2, __temp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2604 | } |
| 2605 | |
| 2606 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2607 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2608 | basic_string<_CharT, _Traits, _Allocator>& |
| 2609 | basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str) |
| 2610 | { |
| 2611 | return replace(__pos1, __n1, __str.data(), __str.size()); |
| 2612 | } |
| 2613 | |
| 2614 | template <class _CharT, class _Traits, class _Allocator> |
| 2615 | basic_string<_CharT, _Traits, _Allocator>& |
| 2616 | basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str, |
| 2617 | size_type __pos2, size_type __n2) |
| 2618 | { |
| 2619 | size_type __str_sz = __str.size(); |
| 2620 | if (__pos2 > __str_sz) |
| 2621 | this->__throw_out_of_range(); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2622 | return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2623 | } |
| 2624 | |
| 2625 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 6ac8de0 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2626 | template <class _Tp> |
| 2627 | typename enable_if |
| 2628 | < |
| 2629 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 2630 | basic_string<_CharT, _Traits, _Allocator>& |
| 2631 | >::type |
| 2632 | basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t, |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2633 | size_type __pos2, size_type __n2) |
| 2634 | { |
Marshall Clow | 6ac8de0 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2635 | __self_view __sv = __t; |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2636 | size_type __str_sz = __sv.size(); |
| 2637 | if (__pos2 > __str_sz) |
| 2638 | this->__throw_out_of_range(); |
| 2639 | return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2)); |
| 2640 | } |
| 2641 | |
| 2642 | template <class _CharT, class _Traits, class _Allocator> |
| 2643 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2644 | basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2645 | { |
Alp Toker | ec34c48 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2646 | _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2647 | return replace(__pos, __n1, __s, traits_type::length(__s)); |
| 2648 | } |
| 2649 | |
| 2650 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2651 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2652 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | 7b2cb48 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 2653 | basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2654 | { |
| 2655 | return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), |
| 2656 | __str.data(), __str.size()); |
| 2657 | } |
| 2658 | |
| 2659 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2660 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2661 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2662 | basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2663 | { |
| 2664 | return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n); |
| 2665 | } |
| 2666 | |
| 2667 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2668 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2669 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2670 | basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2671 | { |
| 2672 | return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s); |
| 2673 | } |
| 2674 | |
| 2675 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2676 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2677 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | 7b2cb48 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 2678 | basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2679 | { |
| 2680 | return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c); |
| 2681 | } |
| 2682 | |
| 2683 | // erase |
| 2684 | |
| 2685 | template <class _CharT, class _Traits, class _Allocator> |
| 2686 | basic_string<_CharT, _Traits, _Allocator>& |
| 2687 | basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n) |
| 2688 | { |
| 2689 | size_type __sz = size(); |
| 2690 | if (__pos > __sz) |
| 2691 | this->__throw_out_of_range(); |
| 2692 | if (__n) |
| 2693 | { |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2694 | value_type* __p = _VSTD::__to_raw_pointer(__get_pointer()); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2695 | __n = _VSTD::min(__n, __sz - __pos); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2696 | size_type __n_move = __sz - __pos - __n; |
| 2697 | if (__n_move != 0) |
| 2698 | traits_type::move(__p + __pos, __p + __pos + __n, __n_move); |
| 2699 | __sz -= __n; |
| 2700 | __set_size(__sz); |
| 2701 | __invalidate_iterators_past(__sz); |
| 2702 | traits_type::assign(__p[__sz], value_type()); |
| 2703 | } |
| 2704 | return *this; |
| 2705 | } |
| 2706 | |
| 2707 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2708 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2709 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 2710 | basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos) |
| 2711 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 2712 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2713 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 2714 | "string::erase(iterator) called with an iterator not" |
| 2715 | " referring to this string"); |
| 2716 | #endif |
| 2717 | _LIBCPP_ASSERT(__pos != end(), |
| 2718 | "string::erase(iterator) called with a non-dereferenceable iterator"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2719 | iterator __b = begin(); |
| 2720 | size_type __r = static_cast<size_type>(__pos - __b); |
| 2721 | erase(__r, 1); |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2722 | return __b + static_cast<difference_type>(__r); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2723 | } |
| 2724 | |
| 2725 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2726 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2727 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 2728 | basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last) |
| 2729 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 2730 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2731 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, |
| 2732 | "string::erase(iterator, iterator) called with an iterator not" |
| 2733 | " referring to this string"); |
| 2734 | #endif |
| 2735 | _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2736 | iterator __b = begin(); |
| 2737 | size_type __r = static_cast<size_type>(__first - __b); |
| 2738 | erase(__r, static_cast<size_type>(__last - __first)); |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2739 | return __b + static_cast<difference_type>(__r); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2740 | } |
| 2741 | |
| 2742 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2743 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2744 | void |
| 2745 | basic_string<_CharT, _Traits, _Allocator>::pop_back() |
| 2746 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 2747 | _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2748 | size_type __sz; |
| 2749 | if (__is_long()) |
| 2750 | { |
| 2751 | __sz = __get_long_size() - 1; |
| 2752 | __set_long_size(__sz); |
| 2753 | traits_type::assign(*(__get_long_pointer() + __sz), value_type()); |
| 2754 | } |
| 2755 | else |
| 2756 | { |
| 2757 | __sz = __get_short_size() - 1; |
| 2758 | __set_short_size(__sz); |
| 2759 | traits_type::assign(*(__get_short_pointer() + __sz), value_type()); |
| 2760 | } |
| 2761 | __invalidate_iterators_past(__sz); |
| 2762 | } |
| 2763 | |
| 2764 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2765 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2766 | void |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 2767 | basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2768 | { |
| 2769 | __invalidate_all_iterators(); |
| 2770 | if (__is_long()) |
| 2771 | { |
| 2772 | traits_type::assign(*__get_long_pointer(), value_type()); |
| 2773 | __set_long_size(0); |
| 2774 | } |
| 2775 | else |
| 2776 | { |
| 2777 | traits_type::assign(*__get_short_pointer(), value_type()); |
| 2778 | __set_short_size(0); |
| 2779 | } |
| 2780 | } |
| 2781 | |
| 2782 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2783 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2784 | void |
| 2785 | basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos) |
| 2786 | { |
| 2787 | if (__is_long()) |
| 2788 | { |
| 2789 | traits_type::assign(*(__get_long_pointer() + __pos), value_type()); |
| 2790 | __set_long_size(__pos); |
| 2791 | } |
| 2792 | else |
| 2793 | { |
| 2794 | traits_type::assign(*(__get_short_pointer() + __pos), value_type()); |
| 2795 | __set_short_size(__pos); |
| 2796 | } |
| 2797 | __invalidate_iterators_past(__pos); |
| 2798 | } |
| 2799 | |
| 2800 | template <class _CharT, class _Traits, class _Allocator> |
| 2801 | void |
| 2802 | basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c) |
| 2803 | { |
| 2804 | size_type __sz = size(); |
| 2805 | if (__n > __sz) |
| 2806 | append(__n - __sz, __c); |
| 2807 | else |
| 2808 | __erase_to_end(__n); |
| 2809 | } |
| 2810 | |
| 2811 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2812 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2813 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 2814 | basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2815 | { |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2816 | size_type __m = __alloc_traits::max_size(__alloc()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2817 | #if _LIBCPP_BIG_ENDIAN |
Marshall Clow | 09f8550 | 2013-10-31 17:23:08 +0000 | [diff] [blame] | 2818 | return (__m <= ~__long_mask ? __m : __m/2) - __alignment; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2819 | #else |
Marshall Clow | 09f8550 | 2013-10-31 17:23:08 +0000 | [diff] [blame] | 2820 | return __m - __alignment; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2821 | #endif |
| 2822 | } |
| 2823 | |
| 2824 | template <class _CharT, class _Traits, class _Allocator> |
| 2825 | void |
| 2826 | basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg) |
| 2827 | { |
| 2828 | if (__res_arg > max_size()) |
| 2829 | this->__throw_length_error(); |
| 2830 | size_type __cap = capacity(); |
| 2831 | size_type __sz = size(); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2832 | __res_arg = _VSTD::max(__res_arg, __sz); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2833 | __res_arg = __recommend(__res_arg); |
| 2834 | if (__res_arg != __cap) |
| 2835 | { |
| 2836 | pointer __new_data, __p; |
| 2837 | bool __was_long, __now_long; |
| 2838 | if (__res_arg == __min_cap - 1) |
| 2839 | { |
| 2840 | __was_long = true; |
| 2841 | __now_long = false; |
| 2842 | __new_data = __get_short_pointer(); |
| 2843 | __p = __get_long_pointer(); |
| 2844 | } |
| 2845 | else |
| 2846 | { |
| 2847 | if (__res_arg > __cap) |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2848 | __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2849 | else |
| 2850 | { |
| 2851 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2852 | try |
| 2853 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2854 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2855 | __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2856 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2857 | } |
| 2858 | catch (...) |
| 2859 | { |
| 2860 | return; |
| 2861 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2862 | #else // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2863 | if (__new_data == nullptr) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2864 | return; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2865 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2866 | } |
| 2867 | __now_long = true; |
| 2868 | __was_long = __is_long(); |
| 2869 | __p = __get_pointer(); |
| 2870 | } |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2871 | traits_type::copy(_VSTD::__to_raw_pointer(__new_data), |
| 2872 | _VSTD::__to_raw_pointer(__p), size()+1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2873 | if (__was_long) |
Howard Hinnant | e32b5e2 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2874 | __alloc_traits::deallocate(__alloc(), __p, __cap+1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2875 | if (__now_long) |
| 2876 | { |
| 2877 | __set_long_cap(__res_arg+1); |
| 2878 | __set_long_size(__sz); |
| 2879 | __set_long_pointer(__new_data); |
| 2880 | } |
| 2881 | else |
| 2882 | __set_short_size(__sz); |
| 2883 | __invalidate_all_iterators(); |
| 2884 | } |
| 2885 | } |
| 2886 | |
| 2887 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2888 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2889 | typename basic_string<_CharT, _Traits, _Allocator>::const_reference |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2890 | basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2891 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 2892 | _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2893 | return *(data() + __pos); |
| 2894 | } |
| 2895 | |
| 2896 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2897 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2898 | typename basic_string<_CharT, _Traits, _Allocator>::reference |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2899 | basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2900 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 2901 | _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2902 | return *(__get_pointer() + __pos); |
| 2903 | } |
| 2904 | |
| 2905 | template <class _CharT, class _Traits, class _Allocator> |
| 2906 | typename basic_string<_CharT, _Traits, _Allocator>::const_reference |
| 2907 | basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const |
| 2908 | { |
| 2909 | if (__n >= size()) |
| 2910 | this->__throw_out_of_range(); |
| 2911 | return (*this)[__n]; |
| 2912 | } |
| 2913 | |
| 2914 | template <class _CharT, class _Traits, class _Allocator> |
| 2915 | typename basic_string<_CharT, _Traits, _Allocator>::reference |
| 2916 | basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) |
| 2917 | { |
| 2918 | if (__n >= size()) |
| 2919 | this->__throw_out_of_range(); |
| 2920 | return (*this)[__n]; |
| 2921 | } |
| 2922 | |
| 2923 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2924 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2925 | typename basic_string<_CharT, _Traits, _Allocator>::reference |
| 2926 | basic_string<_CharT, _Traits, _Allocator>::front() |
| 2927 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 2928 | _LIBCPP_ASSERT(!empty(), "string::front(): string is empty"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2929 | return *__get_pointer(); |
| 2930 | } |
| 2931 | |
| 2932 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2933 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2934 | typename basic_string<_CharT, _Traits, _Allocator>::const_reference |
| 2935 | basic_string<_CharT, _Traits, _Allocator>::front() const |
| 2936 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 2937 | _LIBCPP_ASSERT(!empty(), "string::front(): string is empty"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2938 | return *data(); |
| 2939 | } |
| 2940 | |
| 2941 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2942 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2943 | typename basic_string<_CharT, _Traits, _Allocator>::reference |
| 2944 | basic_string<_CharT, _Traits, _Allocator>::back() |
| 2945 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 2946 | _LIBCPP_ASSERT(!empty(), "string::back(): string is empty"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2947 | return *(__get_pointer() + size() - 1); |
| 2948 | } |
| 2949 | |
| 2950 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2951 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2952 | typename basic_string<_CharT, _Traits, _Allocator>::const_reference |
| 2953 | basic_string<_CharT, _Traits, _Allocator>::back() const |
| 2954 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 2955 | _LIBCPP_ASSERT(!empty(), "string::back(): string is empty"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2956 | return *(data() + size() - 1); |
| 2957 | } |
| 2958 | |
| 2959 | template <class _CharT, class _Traits, class _Allocator> |
| 2960 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2961 | basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2962 | { |
| 2963 | size_type __sz = size(); |
| 2964 | if (__pos > __sz) |
| 2965 | this->__throw_out_of_range(); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2966 | size_type __rlen = _VSTD::min(__n, __sz - __pos); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2967 | traits_type::copy(__s, data() + __pos, __rlen); |
| 2968 | return __rlen; |
| 2969 | } |
| 2970 | |
| 2971 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2972 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2973 | basic_string<_CharT, _Traits, _Allocator> |
| 2974 | basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const |
| 2975 | { |
| 2976 | return basic_string(*this, __pos, __n, __alloc()); |
| 2977 | } |
| 2978 | |
| 2979 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2980 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2981 | void |
| 2982 | basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str) |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 2983 | #if _LIBCPP_STD_VER >= 14 |
| 2984 | _NOEXCEPT |
| 2985 | #else |
| 2986 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
| 2987 | __is_nothrow_swappable<allocator_type>::value) |
| 2988 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2989 | { |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 2990 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2991 | if (!__is_long()) |
| 2992 | __get_db()->__invalidate_all(this); |
| 2993 | if (!__str.__is_long()) |
| 2994 | __get_db()->__invalidate_all(&__str); |
| 2995 | __get_db()->swap(this, &__str); |
| 2996 | #endif |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2997 | _VSTD::swap(__r_.first(), __str.__r_.first()); |
Marshall Clow | 7d914d1 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 2998 | __swap_allocator(__alloc(), __str.__alloc()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2999 | } |
| 3000 | |
| 3001 | // find |
| 3002 | |
| 3003 | template <class _Traits> |
| 3004 | struct _LIBCPP_HIDDEN __traits_eq |
| 3005 | { |
| 3006 | typedef typename _Traits::char_type char_type; |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3007 | _LIBCPP_INLINE_VISIBILITY |
| 3008 | bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT |
| 3009 | {return _Traits::eq(__x, __y);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3010 | }; |
| 3011 | |
| 3012 | template<class _CharT, class _Traits, class _Allocator> |
| 3013 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3014 | basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3015 | size_type __pos, |
| 3016 | size_type __n) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3017 | { |
Alp Toker | ec34c48 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3018 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr"); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3019 | return __str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | 360f319 | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3020 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3021 | } |
| 3022 | |
| 3023 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3024 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3025 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3026 | basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str, |
| 3027 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3028 | { |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3029 | return __str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | 360f319 | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3030 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3031 | } |
| 3032 | |
| 3033 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3034 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3035 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3036 | basic_string<_CharT, _Traits, _Allocator>::find(__self_view __sv, |
| 3037 | size_type __pos) const _NOEXCEPT |
| 3038 | { |
| 3039 | return __str_find<value_type, size_type, traits_type, npos> |
| 3040 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3041 | } |
| 3042 | |
| 3043 | template<class _CharT, class _Traits, class _Allocator> |
| 3044 | inline _LIBCPP_INLINE_VISIBILITY |
| 3045 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3046 | basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3047 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3048 | { |
Alp Toker | ec34c48 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3049 | _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr"); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3050 | return __str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | 360f319 | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3051 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3052 | } |
| 3053 | |
| 3054 | template<class _CharT, class _Traits, class _Allocator> |
| 3055 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3056 | basic_string<_CharT, _Traits, _Allocator>::find(value_type __c, |
| 3057 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3058 | { |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3059 | return __str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | 360f319 | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3060 | (data(), size(), __c, __pos); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3061 | } |
| 3062 | |
| 3063 | // rfind |
| 3064 | |
| 3065 | template<class _CharT, class _Traits, class _Allocator> |
| 3066 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3067 | basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3068 | size_type __pos, |
| 3069 | size_type __n) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3070 | { |
Alp Toker | ec34c48 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3071 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr"); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3072 | return __str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | 360f319 | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3073 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3074 | } |
| 3075 | |
| 3076 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3077 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3078 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3079 | basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str, |
| 3080 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3081 | { |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3082 | return __str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | 360f319 | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3083 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3084 | } |
| 3085 | |
| 3086 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3087 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3088 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3089 | basic_string<_CharT, _Traits, _Allocator>::rfind(__self_view __sv, |
| 3090 | size_type __pos) const _NOEXCEPT |
| 3091 | { |
| 3092 | return __str_rfind<value_type, size_type, traits_type, npos> |
| 3093 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3094 | } |
| 3095 | |
| 3096 | template<class _CharT, class _Traits, class _Allocator> |
| 3097 | inline _LIBCPP_INLINE_VISIBILITY |
| 3098 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3099 | basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3100 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3101 | { |
Alp Toker | ec34c48 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3102 | _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr"); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3103 | return __str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | 360f319 | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3104 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3105 | } |
| 3106 | |
| 3107 | template<class _CharT, class _Traits, class _Allocator> |
| 3108 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3109 | basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c, |
| 3110 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3111 | { |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3112 | return __str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | 360f319 | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3113 | (data(), size(), __c, __pos); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3114 | } |
| 3115 | |
| 3116 | // find_first_of |
| 3117 | |
| 3118 | template<class _CharT, class _Traits, class _Allocator> |
| 3119 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3120 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3121 | size_type __pos, |
| 3122 | size_type __n) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3123 | { |
Alp Toker | ec34c48 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3124 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr"); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3125 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 8eb5acc | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3126 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3127 | } |
| 3128 | |
| 3129 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3130 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3131 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3132 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str, |
| 3133 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3134 | { |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3135 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 8eb5acc | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3136 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3137 | } |
| 3138 | |
| 3139 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3140 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3141 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3142 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(__self_view __sv, |
| 3143 | size_type __pos) const _NOEXCEPT |
| 3144 | { |
| 3145 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
| 3146 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3147 | } |
| 3148 | |
| 3149 | template<class _CharT, class _Traits, class _Allocator> |
| 3150 | inline _LIBCPP_INLINE_VISIBILITY |
| 3151 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3152 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3153 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3154 | { |
Alp Toker | ec34c48 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3155 | _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr"); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3156 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 8eb5acc | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3157 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3158 | } |
| 3159 | |
| 3160 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3161 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3162 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3163 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c, |
| 3164 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3165 | { |
| 3166 | return find(__c, __pos); |
| 3167 | } |
| 3168 | |
| 3169 | // find_last_of |
| 3170 | |
| 3171 | template<class _CharT, class _Traits, class _Allocator> |
| 3172 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3173 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3174 | size_type __pos, |
| 3175 | size_type __n) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3176 | { |
Alp Toker | ec34c48 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3177 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr"); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3178 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 8eb5acc | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3179 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3180 | } |
| 3181 | |
| 3182 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3183 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3184 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3185 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str, |
| 3186 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3187 | { |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3188 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 8eb5acc | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3189 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3190 | } |
| 3191 | |
| 3192 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3193 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3194 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3195 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(__self_view __sv, |
| 3196 | size_type __pos) const _NOEXCEPT |
| 3197 | { |
| 3198 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
| 3199 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3200 | } |
| 3201 | |
| 3202 | template<class _CharT, class _Traits, class _Allocator> |
| 3203 | inline _LIBCPP_INLINE_VISIBILITY |
| 3204 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3205 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3206 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3207 | { |
Alp Toker | ec34c48 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3208 | _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr"); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3209 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 8eb5acc | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3210 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3211 | } |
| 3212 | |
| 3213 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3214 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3215 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3216 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c, |
| 3217 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3218 | { |
| 3219 | return rfind(__c, __pos); |
| 3220 | } |
| 3221 | |
| 3222 | // find_first_not_of |
| 3223 | |
| 3224 | template<class _CharT, class _Traits, class _Allocator> |
| 3225 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3226 | basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3227 | size_type __pos, |
| 3228 | size_type __n) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3229 | { |
Alp Toker | ec34c48 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3230 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr"); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3231 | return __str_find_first_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 8eb5acc | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3232 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3233 | } |
| 3234 | |
| 3235 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3236 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3237 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3238 | basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str, |
| 3239 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3240 | { |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3241 | return __str_find_first_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 8eb5acc | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3242 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3243 | } |
| 3244 | |
| 3245 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3246 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3247 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3248 | basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(__self_view __sv, |
| 3249 | size_type __pos) const _NOEXCEPT |
| 3250 | { |
| 3251 | return __str_find_first_not_of<value_type, size_type, traits_type, npos> |
| 3252 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3253 | } |
| 3254 | |
| 3255 | template<class _CharT, class _Traits, class _Allocator> |
| 3256 | inline _LIBCPP_INLINE_VISIBILITY |
| 3257 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3258 | basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3259 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3260 | { |
Alp Toker | ec34c48 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3261 | _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr"); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3262 | return __str_find_first_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 8eb5acc | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3263 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3264 | } |
| 3265 | |
| 3266 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3267 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3268 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3269 | basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c, |
| 3270 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3271 | { |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3272 | return __str_find_first_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 8eb5acc | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3273 | (data(), size(), __c, __pos); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3274 | } |
| 3275 | |
| 3276 | // find_last_not_of |
| 3277 | |
| 3278 | template<class _CharT, class _Traits, class _Allocator> |
| 3279 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3280 | basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3281 | size_type __pos, |
| 3282 | size_type __n) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3283 | { |
Alp Toker | ec34c48 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3284 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr"); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3285 | return __str_find_last_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 8eb5acc | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3286 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3287 | } |
| 3288 | |
| 3289 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3290 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3291 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3292 | basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str, |
| 3293 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3294 | { |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3295 | return __str_find_last_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 8eb5acc | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3296 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3297 | } |
| 3298 | |
| 3299 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3300 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3301 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3302 | basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(__self_view __sv, |
| 3303 | size_type __pos) const _NOEXCEPT |
| 3304 | { |
| 3305 | return __str_find_last_not_of<value_type, size_type, traits_type, npos> |
| 3306 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3307 | } |
| 3308 | |
| 3309 | template<class _CharT, class _Traits, class _Allocator> |
| 3310 | inline _LIBCPP_INLINE_VISIBILITY |
| 3311 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3312 | basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3313 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3314 | { |
Alp Toker | ec34c48 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3315 | _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr"); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3316 | return __str_find_last_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 8eb5acc | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3317 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3318 | } |
| 3319 | |
| 3320 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3321 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3322 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3323 | basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c, |
| 3324 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3325 | { |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3326 | return __str_find_last_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 8eb5acc | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3327 | (data(), size(), __c, __pos); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3328 | } |
| 3329 | |
| 3330 | // compare |
| 3331 | |
| 3332 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3333 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3334 | int |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3335 | basic_string<_CharT, _Traits, _Allocator>::compare(__self_view __sv) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3336 | { |
Howard Hinnant | fa06d75 | 2011-07-24 21:45:06 +0000 | [diff] [blame] | 3337 | size_t __lhs_sz = size(); |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3338 | size_t __rhs_sz = __sv.size(); |
| 3339 | int __result = traits_type::compare(data(), __sv.data(), |
Howard Hinnant | fa06d75 | 2011-07-24 21:45:06 +0000 | [diff] [blame] | 3340 | _VSTD::min(__lhs_sz, __rhs_sz)); |
| 3341 | if (__result != 0) |
| 3342 | return __result; |
| 3343 | if (__lhs_sz < __rhs_sz) |
| 3344 | return -1; |
| 3345 | if (__lhs_sz > __rhs_sz) |
| 3346 | return 1; |
| 3347 | return 0; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3348 | } |
| 3349 | |
| 3350 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3351 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3352 | int |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3353 | basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3354 | { |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3355 | return compare(__self_view(__str)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3356 | } |
| 3357 | |
| 3358 | template <class _CharT, class _Traits, class _Allocator> |
| 3359 | int |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3360 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3361 | size_type __n1, |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3362 | const value_type* __s, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3363 | size_type __n2) const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3364 | { |
Alp Toker | ec34c48 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3365 | _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3366 | size_type __sz = size(); |
| 3367 | if (__pos1 > __sz || __n2 == npos) |
| 3368 | this->__throw_out_of_range(); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3369 | size_type __rlen = _VSTD::min(__n1, __sz - __pos1); |
| 3370 | int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3371 | if (__r == 0) |
| 3372 | { |
| 3373 | if (__rlen < __n2) |
| 3374 | __r = -1; |
| 3375 | else if (__rlen > __n2) |
| 3376 | __r = 1; |
| 3377 | } |
| 3378 | return __r; |
| 3379 | } |
| 3380 | |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3381 | template <class _CharT, class _Traits, class _Allocator> |
| 3382 | inline _LIBCPP_INLINE_VISIBILITY |
| 3383 | int |
| 3384 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3385 | size_type __n1, |
| 3386 | __self_view __sv) const |
| 3387 | { |
| 3388 | return compare(__pos1, __n1, __sv.data(), __sv.size()); |
| 3389 | } |
| 3390 | |
| 3391 | template <class _CharT, class _Traits, class _Allocator> |
| 3392 | inline _LIBCPP_INLINE_VISIBILITY |
| 3393 | int |
| 3394 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3395 | size_type __n1, |
| 3396 | const basic_string& __str) const |
| 3397 | { |
| 3398 | return compare(__pos1, __n1, __str.data(), __str.size()); |
| 3399 | } |
| 3400 | |
| 3401 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 6ac8de0 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3402 | template <class _Tp> |
| 3403 | typename enable_if |
| 3404 | < |
| 3405 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3406 | int |
| 3407 | >::type |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3408 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3409 | size_type __n1, |
Marshall Clow | 6ac8de0 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3410 | const _Tp& __t, |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3411 | size_type __pos2, |
| 3412 | size_type __n2) const |
| 3413 | { |
Marshall Clow | 6ac8de0 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3414 | __self_view __sv = __t; |
Marshall Clow | 1e00d6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3415 | return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); |
| 3416 | } |
| 3417 | |
| 3418 | template <class _CharT, class _Traits, class _Allocator> |
| 3419 | int |
| 3420 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3421 | size_type __n1, |
| 3422 | const basic_string& __str, |
| 3423 | size_type __pos2, |
| 3424 | size_type __n2) const |
| 3425 | { |
| 3426 | return compare(__pos1, __n1, __self_view(__str), __pos2, __n2); |
| 3427 | } |
| 3428 | |
| 3429 | template <class _CharT, class _Traits, class _Allocator> |
| 3430 | int |
| 3431 | basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT |
| 3432 | { |
| 3433 | _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr"); |
| 3434 | return compare(0, npos, __s, traits_type::length(__s)); |
| 3435 | } |
| 3436 | |
| 3437 | template <class _CharT, class _Traits, class _Allocator> |
| 3438 | int |
| 3439 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3440 | size_type __n1, |
| 3441 | const value_type* __s) const |
| 3442 | { |
| 3443 | _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr"); |
| 3444 | return compare(__pos1, __n1, __s, traits_type::length(__s)); |
| 3445 | } |
| 3446 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3447 | // __invariants |
| 3448 | |
| 3449 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3450 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3451 | bool |
| 3452 | basic_string<_CharT, _Traits, _Allocator>::__invariants() const |
| 3453 | { |
| 3454 | if (size() > capacity()) |
| 3455 | return false; |
| 3456 | if (capacity() < __min_cap - 1) |
| 3457 | return false; |
| 3458 | if (data() == 0) |
| 3459 | return false; |
| 3460 | if (data()[size()] != value_type(0)) |
| 3461 | return false; |
| 3462 | return true; |
| 3463 | } |
| 3464 | |
| 3465 | // operator== |
| 3466 | |
| 3467 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3468 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3469 | bool |
| 3470 | operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3471 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3472 | { |
Howard Hinnant | 08dd253 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 3473 | size_t __lhs_sz = __lhs.size(); |
| 3474 | return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(), |
| 3475 | __rhs.data(), |
| 3476 | __lhs_sz) == 0; |
| 3477 | } |
| 3478 | |
| 3479 | template<class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3480 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 08dd253 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 3481 | bool |
| 3482 | operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs, |
| 3483 | const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT |
| 3484 | { |
| 3485 | size_t __lhs_sz = __lhs.size(); |
| 3486 | if (__lhs_sz != __rhs.size()) |
| 3487 | return false; |
| 3488 | const char* __lp = __lhs.data(); |
| 3489 | const char* __rp = __rhs.data(); |
| 3490 | if (__lhs.__is_long()) |
| 3491 | return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0; |
| 3492 | for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp) |
| 3493 | if (*__lp != *__rp) |
| 3494 | return false; |
| 3495 | return true; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3496 | } |
| 3497 | |
| 3498 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3499 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3500 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3501 | operator==(const _CharT* __lhs, |
| 3502 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3503 | { |
Eric Fiselier | 4f24182 | 2015-08-28 03:02:37 +0000 | [diff] [blame] | 3504 | typedef basic_string<_CharT, _Traits, _Allocator> _String; |
| 3505 | _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr"); |
| 3506 | size_t __lhs_len = _Traits::length(__lhs); |
| 3507 | if (__lhs_len != __rhs.size()) return false; |
| 3508 | return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3509 | } |
| 3510 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3511 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3512 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3513 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3514 | operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs, |
| 3515 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3516 | { |
Eric Fiselier | 4f24182 | 2015-08-28 03:02:37 +0000 | [diff] [blame] | 3517 | typedef basic_string<_CharT, _Traits, _Allocator> _String; |
| 3518 | _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr"); |
| 3519 | size_t __rhs_len = _Traits::length(__rhs); |
| 3520 | if (__rhs_len != __lhs.size()) return false; |
| 3521 | return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3522 | } |
| 3523 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3524 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3525 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3526 | bool |
| 3527 | operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3528 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3529 | { |
| 3530 | return !(__lhs == __rhs); |
| 3531 | } |
| 3532 | |
| 3533 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3534 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3535 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3536 | operator!=(const _CharT* __lhs, |
| 3537 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3538 | { |
| 3539 | return !(__lhs == __rhs); |
| 3540 | } |
| 3541 | |
| 3542 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3543 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3544 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3545 | operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 3546 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3547 | { |
| 3548 | return !(__lhs == __rhs); |
| 3549 | } |
| 3550 | |
| 3551 | // operator< |
| 3552 | |
| 3553 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3554 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3555 | bool |
| 3556 | operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3557 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3558 | { |
Howard Hinnant | 2644a7b | 2011-07-24 15:07:21 +0000 | [diff] [blame] | 3559 | return __lhs.compare(__rhs) < 0; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3560 | } |
| 3561 | |
| 3562 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3563 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3564 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3565 | operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 3566 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3567 | { |
Howard Hinnant | 2644a7b | 2011-07-24 15:07:21 +0000 | [diff] [blame] | 3568 | return __lhs.compare(__rhs) < 0; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3569 | } |
| 3570 | |
| 3571 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3572 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3573 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3574 | operator< (const _CharT* __lhs, |
| 3575 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3576 | { |
| 3577 | return __rhs.compare(__lhs) > 0; |
| 3578 | } |
| 3579 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3580 | // operator> |
| 3581 | |
| 3582 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3583 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3584 | bool |
| 3585 | operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3586 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3587 | { |
| 3588 | return __rhs < __lhs; |
| 3589 | } |
| 3590 | |
| 3591 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3592 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3593 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3594 | operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 3595 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3596 | { |
| 3597 | return __rhs < __lhs; |
| 3598 | } |
| 3599 | |
| 3600 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3601 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3602 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3603 | operator> (const _CharT* __lhs, |
| 3604 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3605 | { |
| 3606 | return __rhs < __lhs; |
| 3607 | } |
| 3608 | |
| 3609 | // operator<= |
| 3610 | |
| 3611 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3612 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3613 | bool |
| 3614 | operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3615 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3616 | { |
| 3617 | return !(__rhs < __lhs); |
| 3618 | } |
| 3619 | |
| 3620 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3621 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3622 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3623 | operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 3624 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3625 | { |
| 3626 | return !(__rhs < __lhs); |
| 3627 | } |
| 3628 | |
| 3629 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3630 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3631 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3632 | operator<=(const _CharT* __lhs, |
| 3633 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3634 | { |
| 3635 | return !(__rhs < __lhs); |
| 3636 | } |
| 3637 | |
| 3638 | // operator>= |
| 3639 | |
| 3640 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3641 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3642 | bool |
| 3643 | operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3644 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3645 | { |
| 3646 | return !(__lhs < __rhs); |
| 3647 | } |
| 3648 | |
| 3649 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3650 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3651 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3652 | operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 3653 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3654 | { |
| 3655 | return !(__lhs < __rhs); |
| 3656 | } |
| 3657 | |
| 3658 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3659 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3660 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3661 | operator>=(const _CharT* __lhs, |
| 3662 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3663 | { |
| 3664 | return !(__lhs < __rhs); |
| 3665 | } |
| 3666 | |
| 3667 | // operator + |
| 3668 | |
| 3669 | template<class _CharT, class _Traits, class _Allocator> |
| 3670 | basic_string<_CharT, _Traits, _Allocator> |
| 3671 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 3672 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) |
| 3673 | { |
| 3674 | basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator()); |
| 3675 | typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size(); |
| 3676 | typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size(); |
| 3677 | __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz); |
| 3678 | __r.append(__rhs.data(), __rhs_sz); |
| 3679 | return __r; |
| 3680 | } |
| 3681 | |
| 3682 | template<class _CharT, class _Traits, class _Allocator> |
| 3683 | basic_string<_CharT, _Traits, _Allocator> |
| 3684 | operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs) |
| 3685 | { |
| 3686 | basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator()); |
| 3687 | typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs); |
| 3688 | typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size(); |
| 3689 | __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz); |
| 3690 | __r.append(__rhs.data(), __rhs_sz); |
| 3691 | return __r; |
| 3692 | } |
| 3693 | |
| 3694 | template<class _CharT, class _Traits, class _Allocator> |
| 3695 | basic_string<_CharT, _Traits, _Allocator> |
| 3696 | operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs) |
| 3697 | { |
| 3698 | basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator()); |
| 3699 | typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size(); |
| 3700 | __r.__init(&__lhs, 1, 1 + __rhs_sz); |
| 3701 | __r.append(__rhs.data(), __rhs_sz); |
| 3702 | return __r; |
| 3703 | } |
| 3704 | |
| 3705 | template<class _CharT, class _Traits, class _Allocator> |
| 3706 | basic_string<_CharT, _Traits, _Allocator> |
| 3707 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) |
| 3708 | { |
| 3709 | basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator()); |
| 3710 | typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size(); |
| 3711 | typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs); |
| 3712 | __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz); |
| 3713 | __r.append(__rhs, __rhs_sz); |
| 3714 | return __r; |
| 3715 | } |
| 3716 | |
| 3717 | template<class _CharT, class _Traits, class _Allocator> |
| 3718 | basic_string<_CharT, _Traits, _Allocator> |
| 3719 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs) |
| 3720 | { |
| 3721 | basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator()); |
| 3722 | typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size(); |
| 3723 | __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1); |
| 3724 | __r.push_back(__rhs); |
| 3725 | return __r; |
| 3726 | } |
| 3727 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3728 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3729 | |
| 3730 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3731 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3732 | basic_string<_CharT, _Traits, _Allocator> |
| 3733 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) |
| 3734 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3735 | return _VSTD::move(__lhs.append(__rhs)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3736 | } |
| 3737 | |
| 3738 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3739 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3740 | basic_string<_CharT, _Traits, _Allocator> |
| 3741 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs) |
| 3742 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3743 | return _VSTD::move(__rhs.insert(0, __lhs)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3744 | } |
| 3745 | |
| 3746 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3747 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3748 | basic_string<_CharT, _Traits, _Allocator> |
| 3749 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs) |
| 3750 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3751 | return _VSTD::move(__lhs.append(__rhs)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3752 | } |
| 3753 | |
| 3754 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3755 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3756 | basic_string<_CharT, _Traits, _Allocator> |
| 3757 | operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs) |
| 3758 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3759 | return _VSTD::move(__rhs.insert(0, __lhs)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3760 | } |
| 3761 | |
| 3762 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3763 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3764 | basic_string<_CharT, _Traits, _Allocator> |
| 3765 | operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs) |
| 3766 | { |
| 3767 | __rhs.insert(__rhs.begin(), __lhs); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3768 | return _VSTD::move(__rhs); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3769 | } |
| 3770 | |
| 3771 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3772 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3773 | basic_string<_CharT, _Traits, _Allocator> |
| 3774 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs) |
| 3775 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3776 | return _VSTD::move(__lhs.append(__rhs)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3777 | } |
| 3778 | |
| 3779 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3780 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3781 | basic_string<_CharT, _Traits, _Allocator> |
| 3782 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs) |
| 3783 | { |
| 3784 | __lhs.push_back(__rhs); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3785 | return _VSTD::move(__lhs); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3786 | } |
| 3787 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 3788 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3789 | |
| 3790 | // swap |
| 3791 | |
| 3792 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 1e56424 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3793 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3794 | void |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3795 | swap(basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | 53f7d4c | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 3796 | basic_string<_CharT, _Traits, _Allocator>& __rhs) |
| 3797 | _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs))) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3798 | { |
| 3799 | __lhs.swap(__rhs); |
| 3800 | } |
| 3801 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3802 | #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS |
| 3803 | |
| 3804 | typedef basic_string<char16_t> u16string; |
| 3805 | typedef basic_string<char32_t> u32string; |
| 3806 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3807 | #endif // _LIBCPP_HAS_NO_UNICODE_CHARS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3808 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 3809 | _LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10); |
| 3810 | _LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10); |
| 3811 | _LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10); |
| 3812 | _LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10); |
| 3813 | _LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10); |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 3814 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 3815 | _LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0); |
| 3816 | _LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0); |
| 3817 | _LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0); |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 3818 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 3819 | _LIBCPP_FUNC_VIS string to_string(int __val); |
| 3820 | _LIBCPP_FUNC_VIS string to_string(unsigned __val); |
| 3821 | _LIBCPP_FUNC_VIS string to_string(long __val); |
| 3822 | _LIBCPP_FUNC_VIS string to_string(unsigned long __val); |
| 3823 | _LIBCPP_FUNC_VIS string to_string(long long __val); |
| 3824 | _LIBCPP_FUNC_VIS string to_string(unsigned long long __val); |
| 3825 | _LIBCPP_FUNC_VIS string to_string(float __val); |
| 3826 | _LIBCPP_FUNC_VIS string to_string(double __val); |
| 3827 | _LIBCPP_FUNC_VIS string to_string(long double __val); |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 3828 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 3829 | _LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10); |
| 3830 | _LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10); |
| 3831 | _LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10); |
| 3832 | _LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10); |
| 3833 | _LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10); |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 3834 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 3835 | _LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0); |
| 3836 | _LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0); |
| 3837 | _LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0); |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 3838 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 3839 | _LIBCPP_FUNC_VIS wstring to_wstring(int __val); |
| 3840 | _LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val); |
| 3841 | _LIBCPP_FUNC_VIS wstring to_wstring(long __val); |
| 3842 | _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val); |
| 3843 | _LIBCPP_FUNC_VIS wstring to_wstring(long long __val); |
| 3844 | _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val); |
| 3845 | _LIBCPP_FUNC_VIS wstring to_wstring(float __val); |
| 3846 | _LIBCPP_FUNC_VIS wstring to_wstring(double __val); |
| 3847 | _LIBCPP_FUNC_VIS wstring to_wstring(long double __val); |
Howard Hinnant | a6a062d | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 3848 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3849 | template<class _CharT, class _Traits, class _Allocator> |
| 3850 | const typename basic_string<_CharT, _Traits, _Allocator>::size_type |
| 3851 | basic_string<_CharT, _Traits, _Allocator>::npos; |
| 3852 | |
| 3853 | template<class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 3854 | struct _LIBCPP_TYPE_VIS_ONLY hash<basic_string<_CharT, _Traits, _Allocator> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3855 | : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t> |
| 3856 | { |
| 3857 | size_t |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3858 | operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3859 | }; |
| 3860 | |
| 3861 | template<class _CharT, class _Traits, class _Allocator> |
| 3862 | size_t |
| 3863 | hash<basic_string<_CharT, _Traits, _Allocator> >::operator()( |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3864 | const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3865 | { |
Sean Hunt | affd9e5 | 2011-07-29 23:31:56 +0000 | [diff] [blame] | 3866 | return __do_string_hash(__val.data(), __val.data() + __val.size()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3867 | } |
| 3868 | |
Howard Hinnant | 464aa5c | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 3869 | template<class _CharT, class _Traits, class _Allocator> |
| 3870 | basic_ostream<_CharT, _Traits>& |
| 3871 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 3872 | const basic_string<_CharT, _Traits, _Allocator>& __str); |
| 3873 | |
| 3874 | template<class _CharT, class _Traits, class _Allocator> |
| 3875 | basic_istream<_CharT, _Traits>& |
| 3876 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 3877 | basic_string<_CharT, _Traits, _Allocator>& __str); |
| 3878 | |
| 3879 | template<class _CharT, class _Traits, class _Allocator> |
| 3880 | basic_istream<_CharT, _Traits>& |
| 3881 | getline(basic_istream<_CharT, _Traits>& __is, |
| 3882 | basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm); |
| 3883 | |
| 3884 | template<class _CharT, class _Traits, class _Allocator> |
| 3885 | inline _LIBCPP_INLINE_VISIBILITY |
| 3886 | basic_istream<_CharT, _Traits>& |
| 3887 | getline(basic_istream<_CharT, _Traits>& __is, |
| 3888 | basic_string<_CharT, _Traits, _Allocator>& __str); |
| 3889 | |
| 3890 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 3891 | |
| 3892 | template<class _CharT, class _Traits, class _Allocator> |
| 3893 | inline _LIBCPP_INLINE_VISIBILITY |
| 3894 | basic_istream<_CharT, _Traits>& |
| 3895 | getline(basic_istream<_CharT, _Traits>&& __is, |
| 3896 | basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm); |
| 3897 | |
| 3898 | template<class _CharT, class _Traits, class _Allocator> |
| 3899 | inline _LIBCPP_INLINE_VISIBILITY |
| 3900 | basic_istream<_CharT, _Traits>& |
| 3901 | getline(basic_istream<_CharT, _Traits>&& __is, |
| 3902 | basic_string<_CharT, _Traits, _Allocator>& __str); |
| 3903 | |
| 3904 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 3905 | |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3906 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 3907 | |
| 3908 | template<class _CharT, class _Traits, class _Allocator> |
| 3909 | bool |
| 3910 | basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const |
| 3911 | { |
| 3912 | return this->data() <= _VSTD::__to_raw_pointer(__i->base()) && |
| 3913 | _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size(); |
| 3914 | } |
| 3915 | |
| 3916 | template<class _CharT, class _Traits, class _Allocator> |
| 3917 | bool |
| 3918 | basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const |
| 3919 | { |
| 3920 | return this->data() < _VSTD::__to_raw_pointer(__i->base()) && |
| 3921 | _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size(); |
| 3922 | } |
| 3923 | |
| 3924 | template<class _CharT, class _Traits, class _Allocator> |
| 3925 | bool |
| 3926 | basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const |
| 3927 | { |
| 3928 | const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n; |
| 3929 | return this->data() <= __p && __p <= this->data() + this->size(); |
| 3930 | } |
| 3931 | |
| 3932 | template<class _CharT, class _Traits, class _Allocator> |
| 3933 | bool |
| 3934 | basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const |
| 3935 | { |
| 3936 | const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n; |
| 3937 | return this->data() <= __p && __p < this->data() + this->size(); |
| 3938 | } |
| 3939 | |
| 3940 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
| 3941 | |
Marshall Clow | 1523432 | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 3942 | #if _LIBCPP_STD_VER > 11 |
| 3943 | // Literal suffixes for basic_string [basic.string.literals] |
Marshall Clow | 8d9dd7a | 2013-10-05 21:18:32 +0000 | [diff] [blame] | 3944 | inline namespace literals |
Marshall Clow | 1523432 | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 3945 | { |
| 3946 | inline namespace string_literals |
| 3947 | { |
Howard Hinnant | ab61b2c | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 3948 | inline _LIBCPP_INLINE_VISIBILITY |
| 3949 | basic_string<char> operator "" s( const char *__str, size_t __len ) |
| 3950 | { |
| 3951 | return basic_string<char> (__str, __len); |
| 3952 | } |
Marshall Clow | 1523432 | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 3953 | |
Howard Hinnant | ab61b2c | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 3954 | inline _LIBCPP_INLINE_VISIBILITY |
| 3955 | basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len ) |
| 3956 | { |
| 3957 | return basic_string<wchar_t> (__str, __len); |
| 3958 | } |
Marshall Clow | 1523432 | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 3959 | |
Howard Hinnant | ab61b2c | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 3960 | inline _LIBCPP_INLINE_VISIBILITY |
| 3961 | basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len ) |
| 3962 | { |
| 3963 | return basic_string<char16_t> (__str, __len); |
| 3964 | } |
Marshall Clow | 1523432 | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 3965 | |
Howard Hinnant | ab61b2c | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 3966 | inline _LIBCPP_INLINE_VISIBILITY |
| 3967 | basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len ) |
| 3968 | { |
| 3969 | return basic_string<char32_t> (__str, __len); |
| 3970 | } |
Marshall Clow | 1523432 | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 3971 | } |
| 3972 | } |
| 3973 | #endif |
| 3974 | |
Eric Fiselier | 833d644 | 2016-09-15 22:27:07 +0000 | [diff] [blame] | 3975 | _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>) |
| 3976 | _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>) |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3977 | _LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3978 | |
| 3979 | _LIBCPP_END_NAMESPACE_STD |
| 3980 | |
| 3981 | #endif // _LIBCPP_STRING |