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