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