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