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