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