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