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