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