Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===------------------------------ vector --------------------------------===// |
| 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 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_VECTOR |
| 12 | #define _LIBCPP_VECTOR |
| 13 | |
| 14 | /* |
| 15 | vector synopsis |
| 16 | |
| 17 | namespace std |
| 18 | { |
| 19 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 20 | template <class T, class Allocator = allocator<T> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 21 | class vector |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 22 | { |
| 23 | public: |
| 24 | typedef T value_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 25 | typedef Allocator allocator_type; |
| 26 | typedef typename allocator_type::reference reference; |
| 27 | typedef typename allocator_type::const_reference const_reference; |
| 28 | typedef implementation-defined iterator; |
| 29 | typedef implementation-defined const_iterator; |
| 30 | typedef typename allocator_type::size_type size_type; |
| 31 | typedef typename allocator_type::difference_type difference_type; |
| 32 | typedef typename allocator_type::pointer pointer; |
| 33 | typedef typename allocator_type::const_pointer const_pointer; |
| 34 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 35 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 36 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 37 | vector() |
| 38 | noexcept(is_nothrow_default_constructible<allocator_type>::value); |
| 39 | explicit vector(const allocator_type&); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 40 | explicit vector(size_type n); |
| 41 | vector(size_type n, const value_type& value, const allocator_type& = allocator_type()); |
| 42 | template <class InputIterator> |
| 43 | vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); |
| 44 | vector(const vector& x); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 45 | vector(vector&& x) |
| 46 | noexcept(is_nothrow_move_constructible<allocator_type>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 47 | vector(initializer_list<value_type> il); |
| 48 | vector(initializer_list<value_type> il, const allocator_type& a); |
| 49 | ~vector(); |
| 50 | vector& operator=(const vector& x); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 51 | vector& operator=(vector&& x) |
| 52 | noexcept( |
| 53 | allocator_type::propagate_on_container_move_assignment::value && |
| 54 | is_nothrow_move_assignable<allocator_type>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 55 | vector& operator=(initializer_list<value_type> il); |
| 56 | template <class InputIterator> |
| 57 | void assign(InputIterator first, InputIterator last); |
| 58 | void assign(size_type n, const value_type& u); |
| 59 | void assign(initializer_list<value_type> il); |
| 60 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 61 | allocator_type get_allocator() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 62 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 63 | iterator begin() noexcept; |
| 64 | const_iterator begin() const noexcept; |
| 65 | iterator end() noexcept; |
| 66 | const_iterator end() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 67 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 68 | reverse_iterator rbegin() noexcept; |
| 69 | const_reverse_iterator rbegin() const noexcept; |
| 70 | reverse_iterator rend() noexcept; |
| 71 | const_reverse_iterator rend() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 72 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 73 | const_iterator cbegin() const noexcept; |
| 74 | const_iterator cend() const noexcept; |
| 75 | const_reverse_iterator crbegin() const noexcept; |
| 76 | const_reverse_iterator crend() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 77 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 78 | size_type size() const noexcept; |
| 79 | size_type max_size() const noexcept; |
| 80 | size_type capacity() const noexcept; |
| 81 | bool empty() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 82 | void reserve(size_type n); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 83 | void shrink_to_fit() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 84 | |
| 85 | reference operator[](size_type n); |
| 86 | const_reference operator[](size_type n) const; |
| 87 | reference at(size_type n); |
| 88 | const_reference at(size_type n) const; |
| 89 | |
| 90 | reference front(); |
| 91 | const_reference front() const; |
| 92 | reference back(); |
| 93 | const_reference back() const; |
| 94 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 95 | value_type* data() noexcept; |
| 96 | const value_type* data() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 97 | |
| 98 | void push_back(const value_type& x); |
| 99 | void push_back(value_type&& x); |
| 100 | template <class... Args> |
| 101 | void emplace_back(Args&&... args); |
| 102 | void pop_back(); |
| 103 | |
| 104 | template <class... Args> iterator emplace(const_iterator position, Args&&... args); |
| 105 | iterator insert(const_iterator position, const value_type& x); |
| 106 | iterator insert(const_iterator position, value_type&& x); |
| 107 | iterator insert(const_iterator position, size_type n, const value_type& x); |
| 108 | template <class InputIterator> |
| 109 | iterator insert(const_iterator position, InputIterator first, InputIterator last); |
| 110 | iterator insert(const_iterator position, initializer_list<value_type> il); |
| 111 | |
| 112 | iterator erase(const_iterator position); |
| 113 | iterator erase(const_iterator first, const_iterator last); |
| 114 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 115 | void clear() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 116 | |
| 117 | void resize(size_type sz); |
| 118 | void resize(size_type sz, const value_type& c); |
| 119 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 120 | void swap(vector&) |
| 121 | noexcept(!allocator_type::propagate_on_container_swap::value || |
| 122 | __is_nothrow_swappable<allocator_type>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 123 | |
| 124 | bool __invariants() const; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 125 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 126 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 127 | template <class Allocator = allocator<T> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 128 | class vector<bool, Allocator> |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 129 | { |
| 130 | public: |
| 131 | typedef bool value_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 132 | typedef Allocator allocator_type; |
| 133 | typedef implementation-defined iterator; |
| 134 | typedef implementation-defined const_iterator; |
| 135 | typedef typename allocator_type::size_type size_type; |
| 136 | typedef typename allocator_type::difference_type difference_type; |
| 137 | typedef iterator pointer; |
| 138 | typedef const_iterator const_pointer; |
| 139 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 140 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 141 | |
| 142 | class reference |
| 143 | { |
| 144 | public: |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 145 | reference(const reference&) noexcept; |
| 146 | operator bool() const noexcept; |
| 147 | reference& operator=(const bool x) noexcept; |
| 148 | reference& operator=(const reference& x) noexcept; |
| 149 | iterator operator&() const noexcept; |
| 150 | void flip() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | class const_reference |
| 154 | { |
| 155 | public: |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 156 | const_reference(const reference&) noexcept; |
| 157 | operator bool() const noexcept; |
| 158 | const_iterator operator&() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 159 | }; |
| 160 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 161 | vector() |
| 162 | noexcept(is_nothrow_default_constructible<allocator_type>::value); |
Howard Hinnant | 9cbee43 | 2011-09-02 20:42:31 +0000 | [diff] [blame] | 163 | explicit vector(const allocator_type&); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 164 | explicit vector(size_type n, const value_type& value = value_type(), const allocator_type& = allocator_type()); |
| 165 | template <class InputIterator> |
| 166 | vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); |
| 167 | vector(const vector& x); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 168 | vector(vector&& x) |
| 169 | noexcept(is_nothrow_move_constructible<allocator_type>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 170 | vector(initializer_list<value_type> il); |
| 171 | vector(initializer_list<value_type> il, const allocator_type& a); |
| 172 | ~vector(); |
| 173 | vector& operator=(const vector& x); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 174 | vector& operator=(vector&& x) |
| 175 | noexcept( |
| 176 | allocator_type::propagate_on_container_move_assignment::value && |
| 177 | is_nothrow_move_assignable<allocator_type>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 178 | vector& operator=(initializer_list<value_type> il); |
| 179 | template <class InputIterator> |
| 180 | void assign(InputIterator first, InputIterator last); |
| 181 | void assign(size_type n, const value_type& u); |
| 182 | void assign(initializer_list<value_type> il); |
| 183 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 184 | allocator_type get_allocator() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 185 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 186 | iterator begin() noexcept; |
| 187 | const_iterator begin() const noexcept; |
| 188 | iterator end() noexcept; |
| 189 | const_iterator end() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 190 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 191 | reverse_iterator rbegin() noexcept; |
| 192 | const_reverse_iterator rbegin() const noexcept; |
| 193 | reverse_iterator rend() noexcept; |
| 194 | const_reverse_iterator rend() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 195 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 196 | const_iterator cbegin() const noexcept; |
| 197 | const_iterator cend() const noexcept; |
| 198 | const_reverse_iterator crbegin() const noexcept; |
| 199 | const_reverse_iterator crend() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 200 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 201 | size_type size() const noexcept; |
| 202 | size_type max_size() const noexcept; |
| 203 | size_type capacity() const noexcept; |
| 204 | bool empty() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 205 | void reserve(size_type n); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 206 | void shrink_to_fit() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 207 | |
| 208 | reference operator[](size_type n); |
| 209 | const_reference operator[](size_type n) const; |
| 210 | reference at(size_type n); |
| 211 | const_reference at(size_type n) const; |
| 212 | |
| 213 | reference front(); |
| 214 | const_reference front() const; |
| 215 | reference back(); |
| 216 | const_reference back() const; |
| 217 | |
| 218 | void push_back(const value_type& x); |
| 219 | void pop_back(); |
| 220 | |
| 221 | iterator insert(const_iterator position, const value_type& x); |
| 222 | iterator insert(const_iterator position, size_type n, const value_type& x); |
| 223 | template <class InputIterator> |
| 224 | iterator insert(const_iterator position, InputIterator first, InputIterator last); |
| 225 | iterator insert(const_iterator position, initializer_list<value_type> il); |
| 226 | |
| 227 | iterator erase(const_iterator position); |
| 228 | iterator erase(const_iterator first, const_iterator last); |
| 229 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 230 | void clear() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 231 | |
| 232 | void resize(size_type sz); |
| 233 | void resize(size_type sz, value_type x); |
| 234 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 235 | void swap(vector&) |
| 236 | noexcept(!allocator_type::propagate_on_container_swap::value || |
| 237 | __is_nothrow_swappable<allocator_type>::value); |
| 238 | void flip() noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 239 | |
| 240 | bool __invariants() const; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 241 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 242 | |
| 243 | template <class Allocator> struct hash<std::vector<bool, Allocator>>; |
| 244 | |
| 245 | template <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y); |
| 246 | template <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y); |
| 247 | template <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); |
| 248 | template <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y); |
| 249 | template <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); |
| 250 | template <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); |
| 251 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 252 | template <class T, class Allocator> |
| 253 | void swap(vector<T,Allocator>& x, vector<T,Allocator>& y) |
| 254 | noexcept(noexcept(x.swap(y))); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 255 | |
| 256 | } // std |
| 257 | |
| 258 | */ |
| 259 | |
| 260 | #include <__config> |
| 261 | #include <__bit_reference> |
| 262 | #include <type_traits> |
| 263 | #include <climits> |
| 264 | #include <limits> |
| 265 | #include <initializer_list> |
| 266 | #include <memory> |
| 267 | #include <stdexcept> |
| 268 | #include <algorithm> |
| 269 | #include <cstring> |
| 270 | #include <__split_buffer> |
| 271 | #include <__functional_base> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 272 | |
Howard Hinnant | 66c6f97 | 2011-11-29 16:45:27 +0000 | [diff] [blame] | 273 | #include <__undef_min_max> |
| 274 | |
Howard Hinnant | 8b00e6c | 2013-08-02 00:26:35 +0000 | [diff] [blame^] | 275 | #ifdef _LIBCPP_DEBUG2 |
| 276 | # include <__debug> |
| 277 | #else |
| 278 | # define _LIBCPP_ASSERT(x, m) ((void)0) |
| 279 | #endif |
| 280 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 281 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 282 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 283 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 284 | |
| 285 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 286 | |
| 287 | template <bool> |
| 288 | class __vector_base_common |
| 289 | { |
| 290 | protected: |
| 291 | _LIBCPP_ALWAYS_INLINE __vector_base_common() {} |
| 292 | void __throw_length_error() const; |
| 293 | void __throw_out_of_range() const; |
| 294 | }; |
| 295 | |
| 296 | template <bool __b> |
| 297 | void |
| 298 | __vector_base_common<__b>::__throw_length_error() const |
| 299 | { |
| 300 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 301 | throw length_error("vector"); |
| 302 | #else |
| 303 | assert(!"vector length_error"); |
| 304 | #endif |
| 305 | } |
| 306 | |
| 307 | template <bool __b> |
| 308 | void |
| 309 | __vector_base_common<__b>::__throw_out_of_range() const |
| 310 | { |
| 311 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 312 | throw out_of_range("vector"); |
| 313 | #else |
| 314 | assert(!"vector out_of_range"); |
| 315 | #endif |
| 316 | } |
| 317 | |
Howard Hinnant | e9df0a5 | 2013-08-01 18:17:34 +0000 | [diff] [blame] | 318 | #ifdef _LIBCPP_MSVC |
Howard Hinnant | 78b6828 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 319 | #pragma warning( push ) |
| 320 | #pragma warning( disable: 4231 ) |
Howard Hinnant | e9df0a5 | 2013-08-01 18:17:34 +0000 | [diff] [blame] | 321 | #endif // _LIBCPP_MSVC |
Howard Hinnant | ff92677 | 2012-11-06 21:08:48 +0000 | [diff] [blame] | 322 | _LIBCPP_EXTERN_TEMPLATE(class __vector_base_common<true>) |
Howard Hinnant | e9df0a5 | 2013-08-01 18:17:34 +0000 | [diff] [blame] | 323 | #ifdef _LIBCPP_MSVC |
Howard Hinnant | 78b6828 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 324 | #pragma warning( pop ) |
Howard Hinnant | e9df0a5 | 2013-08-01 18:17:34 +0000 | [diff] [blame] | 325 | #endif // _LIBCPP_MSVC |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 326 | |
| 327 | template <class _Tp, class _Allocator> |
| 328 | class __vector_base |
| 329 | : protected __vector_base_common<true> |
| 330 | { |
| 331 | protected: |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 332 | typedef _Tp value_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 333 | typedef _Allocator allocator_type; |
| 334 | typedef allocator_traits<allocator_type> __alloc_traits; |
| 335 | typedef value_type& reference; |
| 336 | typedef const value_type& const_reference; |
| 337 | typedef typename __alloc_traits::size_type size_type; |
| 338 | typedef typename __alloc_traits::difference_type difference_type; |
| 339 | typedef typename __alloc_traits::pointer pointer; |
| 340 | typedef typename __alloc_traits::const_pointer const_pointer; |
| 341 | typedef pointer iterator; |
| 342 | typedef const_pointer const_iterator; |
| 343 | |
| 344 | pointer __begin_; |
| 345 | pointer __end_; |
| 346 | __compressed_pair<pointer, allocator_type> __end_cap_; |
| 347 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 348 | _LIBCPP_INLINE_VISIBILITY |
| 349 | allocator_type& __alloc() _NOEXCEPT |
| 350 | {return __end_cap_.second();} |
| 351 | _LIBCPP_INLINE_VISIBILITY |
| 352 | const allocator_type& __alloc() const _NOEXCEPT |
| 353 | {return __end_cap_.second();} |
| 354 | _LIBCPP_INLINE_VISIBILITY |
| 355 | pointer& __end_cap() _NOEXCEPT |
| 356 | {return __end_cap_.first();} |
| 357 | _LIBCPP_INLINE_VISIBILITY |
| 358 | const pointer& __end_cap() const _NOEXCEPT |
| 359 | {return __end_cap_.first();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 360 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 361 | _LIBCPP_INLINE_VISIBILITY |
| 362 | __vector_base() |
| 363 | _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 364 | _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 365 | ~__vector_base(); |
| 366 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 367 | _LIBCPP_INLINE_VISIBILITY |
| 368 | void clear() _NOEXCEPT {__destruct_at_end(__begin_);} |
| 369 | _LIBCPP_INLINE_VISIBILITY |
| 370 | size_type capacity() const _NOEXCEPT |
| 371 | {return static_cast<size_type>(__end_cap() - __begin_);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 372 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 373 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 374 | void __destruct_at_end(pointer __new_last) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 375 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 376 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 377 | void __copy_assign_alloc(const __vector_base& __c) |
| 378 | {__copy_assign_alloc(__c, integral_constant<bool, |
| 379 | __alloc_traits::propagate_on_container_copy_assignment::value>());} |
| 380 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 381 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 382 | void __move_assign_alloc(__vector_base& __c) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 383 | _NOEXCEPT_( |
| 384 | !__alloc_traits::propagate_on_container_move_assignment::value || |
| 385 | is_nothrow_move_assignable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 386 | {__move_assign_alloc(__c, integral_constant<bool, |
| 387 | __alloc_traits::propagate_on_container_move_assignment::value>());} |
| 388 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 389 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 390 | static void __swap_alloc(allocator_type& __x, allocator_type& __y) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 391 | _NOEXCEPT_( |
| 392 | !__alloc_traits::propagate_on_container_swap::value || |
| 393 | __is_nothrow_swappable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 394 | {__swap_alloc(__x, __y, integral_constant<bool, |
| 395 | __alloc_traits::propagate_on_container_swap::value>());} |
| 396 | private: |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 397 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 398 | void __copy_assign_alloc(const __vector_base& __c, true_type) |
| 399 | { |
| 400 | if (__alloc() != __c.__alloc()) |
| 401 | { |
| 402 | clear(); |
| 403 | __alloc_traits::deallocate(__alloc(), __begin_, capacity()); |
| 404 | __begin_ = __end_ = __end_cap() = nullptr; |
| 405 | } |
| 406 | __alloc() = __c.__alloc(); |
| 407 | } |
| 408 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 409 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 410 | void __copy_assign_alloc(const __vector_base&, false_type) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 411 | {} |
| 412 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 413 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9cbee43 | 2011-09-02 20:42:31 +0000 | [diff] [blame] | 414 | void __move_assign_alloc(__vector_base& __c, true_type) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 415 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 416 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 417 | __alloc() = _VSTD::move(__c.__alloc()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 418 | } |
| 419 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 420 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 421 | void __move_assign_alloc(__vector_base&, false_type) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 422 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 423 | {} |
| 424 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 425 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 426 | static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 427 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 428 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 429 | using _VSTD::swap; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 430 | swap(__x, __y); |
| 431 | } |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 432 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 433 | static void __swap_alloc(allocator_type&, allocator_type&, false_type) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 434 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 435 | {} |
| 436 | }; |
| 437 | |
| 438 | template <class _Tp, class _Allocator> |
| 439 | _LIBCPP_INLINE_VISIBILITY inline |
| 440 | void |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 441 | __vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 442 | { |
Howard Hinnant | b0bfd9b | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 443 | while (__new_last != __end_) |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 444 | __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | template <class _Tp, class _Allocator> |
| 448 | _LIBCPP_INLINE_VISIBILITY inline |
| 449 | __vector_base<_Tp, _Allocator>::__vector_base() |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 450 | _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 451 | : __begin_(nullptr), |
| 452 | __end_(nullptr), |
| 453 | __end_cap_(nullptr) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 454 | { |
| 455 | } |
| 456 | |
| 457 | template <class _Tp, class _Allocator> |
| 458 | _LIBCPP_INLINE_VISIBILITY inline |
| 459 | __vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a) |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 460 | : __begin_(nullptr), |
| 461 | __end_(nullptr), |
| 462 | __end_cap_(nullptr, __a) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 463 | { |
| 464 | } |
| 465 | |
| 466 | template <class _Tp, class _Allocator> |
| 467 | __vector_base<_Tp, _Allocator>::~__vector_base() |
| 468 | { |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 469 | if (__begin_ != nullptr) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 470 | { |
| 471 | clear(); |
| 472 | __alloc_traits::deallocate(__alloc(), __begin_, capacity()); |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | template <class _Tp, class _Allocator = allocator<_Tp> > |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 477 | class _LIBCPP_TYPE_VIS vector |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 478 | : private __vector_base<_Tp, _Allocator> |
| 479 | { |
| 480 | private: |
| 481 | typedef __vector_base<_Tp, _Allocator> __base; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 482 | public: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 483 | typedef vector __self; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 484 | typedef _Tp value_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 485 | typedef _Allocator allocator_type; |
| 486 | typedef typename __base::__alloc_traits __alloc_traits; |
| 487 | typedef typename __base::reference reference; |
| 488 | typedef typename __base::const_reference const_reference; |
| 489 | typedef typename __base::size_type size_type; |
| 490 | typedef typename __base::difference_type difference_type; |
| 491 | typedef typename __base::pointer pointer; |
| 492 | typedef typename __base::const_pointer const_pointer; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 493 | typedef __wrap_iter<pointer> iterator; |
| 494 | typedef __wrap_iter<const_pointer> const_iterator; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 495 | typedef _VSTD::reverse_iterator<iterator> reverse_iterator; |
| 496 | typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 497 | |
Howard Hinnant | 02d5e18 | 2013-03-26 19:04:56 +0000 | [diff] [blame] | 498 | static_assert((is_same<typename allocator_type::value_type, value_type>::value), |
| 499 | "Allocator::value_type must be same type as value_type"); |
| 500 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 501 | _LIBCPP_INLINE_VISIBILITY |
| 502 | vector() |
| 503 | _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 504 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 505 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 506 | __get_db()->__insert_c(this); |
| 507 | #endif |
| 508 | } |
| 509 | _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) |
| 510 | : __base(__a) |
| 511 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 512 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 513 | __get_db()->__insert_c(this); |
| 514 | #endif |
| 515 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 516 | explicit vector(size_type __n); |
| 517 | vector(size_type __n, const_reference __x); |
| 518 | vector(size_type __n, const_reference __x, const allocator_type& __a); |
| 519 | template <class _InputIterator> |
| 520 | vector(_InputIterator __first, _InputIterator __last, |
| 521 | typename enable_if<__is_input_iterator <_InputIterator>::value && |
Howard Hinnant | 742fecb | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 522 | !__is_forward_iterator<_InputIterator>::value && |
| 523 | is_constructible< |
| 524 | value_type, |
| 525 | typename iterator_traits<_InputIterator>::reference>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 526 | template <class _InputIterator> |
| 527 | vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, |
| 528 | typename enable_if<__is_input_iterator <_InputIterator>::value && |
Howard Hinnant | 742fecb | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 529 | !__is_forward_iterator<_InputIterator>::value && |
| 530 | is_constructible< |
| 531 | value_type, |
| 532 | typename iterator_traits<_InputIterator>::reference>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 533 | template <class _ForwardIterator> |
| 534 | vector(_ForwardIterator __first, _ForwardIterator __last, |
Howard Hinnant | 742fecb | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 535 | typename enable_if<__is_forward_iterator<_ForwardIterator>::value && |
| 536 | is_constructible< |
| 537 | value_type, |
| 538 | typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 539 | template <class _ForwardIterator> |
| 540 | vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, |
Howard Hinnant | 742fecb | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 541 | typename enable_if<__is_forward_iterator<_ForwardIterator>::value && |
| 542 | is_constructible< |
| 543 | value_type, |
| 544 | typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 545 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 546 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 547 | vector(initializer_list<value_type> __il); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 548 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 549 | vector(initializer_list<value_type> __il, const allocator_type& __a); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 550 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 551 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 552 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 553 | ~vector() |
| 554 | { |
| 555 | __get_db()->__erase_c(this); |
| 556 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 557 | #endif |
| 558 | |
| 559 | vector(const vector& __x); |
| 560 | vector(const vector& __x, const allocator_type& __a); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 561 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 562 | vector& operator=(const vector& __x); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 563 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 564 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 565 | vector(vector&& __x) |
| 566 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 567 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 568 | vector(vector&& __x, const allocator_type& __a); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 569 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 570 | vector& operator=(vector&& __x) |
| 571 | _NOEXCEPT_( |
| 572 | __alloc_traits::propagate_on_container_move_assignment::value && |
| 573 | is_nothrow_move_assignable<allocator_type>::value); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 574 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 575 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 576 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 577 | vector& operator=(initializer_list<value_type> __il) |
| 578 | {assign(__il.begin(), __il.end()); return *this;} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 579 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 580 | |
| 581 | template <class _InputIterator> |
| 582 | typename enable_if |
| 583 | < |
| 584 | __is_input_iterator <_InputIterator>::value && |
Howard Hinnant | 742fecb | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 585 | !__is_forward_iterator<_InputIterator>::value && |
| 586 | is_constructible< |
| 587 | value_type, |
| 588 | typename iterator_traits<_InputIterator>::reference>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 589 | void |
| 590 | >::type |
| 591 | assign(_InputIterator __first, _InputIterator __last); |
| 592 | template <class _ForwardIterator> |
| 593 | typename enable_if |
| 594 | < |
Howard Hinnant | 742fecb | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 595 | __is_forward_iterator<_ForwardIterator>::value && |
| 596 | is_constructible< |
| 597 | value_type, |
| 598 | typename iterator_traits<_ForwardIterator>::reference>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 599 | void |
| 600 | >::type |
| 601 | assign(_ForwardIterator __first, _ForwardIterator __last); |
| 602 | |
| 603 | void assign(size_type __n, const_reference __u); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 604 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 605 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 606 | void assign(initializer_list<value_type> __il) |
| 607 | {assign(__il.begin(), __il.end());} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 608 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 609 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 610 | _LIBCPP_INLINE_VISIBILITY |
| 611 | allocator_type get_allocator() const _NOEXCEPT |
| 612 | {return this->__alloc();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 613 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 614 | _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT; |
| 615 | _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT; |
| 616 | _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT; |
| 617 | _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 618 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 619 | _LIBCPP_INLINE_VISIBILITY |
| 620 | reverse_iterator rbegin() _NOEXCEPT |
| 621 | {return reverse_iterator(end());} |
| 622 | _LIBCPP_INLINE_VISIBILITY |
| 623 | const_reverse_iterator rbegin() const _NOEXCEPT |
| 624 | {return const_reverse_iterator(end());} |
| 625 | _LIBCPP_INLINE_VISIBILITY |
| 626 | reverse_iterator rend() _NOEXCEPT |
| 627 | {return reverse_iterator(begin());} |
| 628 | _LIBCPP_INLINE_VISIBILITY |
| 629 | const_reverse_iterator rend() const _NOEXCEPT |
| 630 | {return const_reverse_iterator(begin());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 631 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 632 | _LIBCPP_INLINE_VISIBILITY |
| 633 | const_iterator cbegin() const _NOEXCEPT |
| 634 | {return begin();} |
| 635 | _LIBCPP_INLINE_VISIBILITY |
| 636 | const_iterator cend() const _NOEXCEPT |
| 637 | {return end();} |
| 638 | _LIBCPP_INLINE_VISIBILITY |
| 639 | const_reverse_iterator crbegin() const _NOEXCEPT |
| 640 | {return rbegin();} |
| 641 | _LIBCPP_INLINE_VISIBILITY |
| 642 | const_reverse_iterator crend() const _NOEXCEPT |
| 643 | {return rend();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 644 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 645 | _LIBCPP_INLINE_VISIBILITY |
| 646 | size_type size() const _NOEXCEPT |
| 647 | {return static_cast<size_type>(this->__end_ - this->__begin_);} |
| 648 | _LIBCPP_INLINE_VISIBILITY |
| 649 | size_type capacity() const _NOEXCEPT |
| 650 | {return __base::capacity();} |
| 651 | _LIBCPP_INLINE_VISIBILITY |
| 652 | bool empty() const _NOEXCEPT |
| 653 | {return this->__begin_ == this->__end_;} |
| 654 | size_type max_size() const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 655 | void reserve(size_type __n); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 656 | void shrink_to_fit() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 657 | |
| 658 | _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n); |
| 659 | _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const; |
| 660 | reference at(size_type __n); |
| 661 | const_reference at(size_type __n) const; |
| 662 | |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 663 | _LIBCPP_INLINE_VISIBILITY reference front() |
| 664 | { |
| 665 | _LIBCPP_ASSERT(!empty(), "front() called for empty vector"); |
| 666 | return *this->__begin_; |
| 667 | } |
| 668 | _LIBCPP_INLINE_VISIBILITY const_reference front() const |
| 669 | { |
| 670 | _LIBCPP_ASSERT(!empty(), "front() called for empty vector"); |
| 671 | return *this->__begin_; |
| 672 | } |
| 673 | _LIBCPP_INLINE_VISIBILITY reference back() |
| 674 | { |
| 675 | _LIBCPP_ASSERT(!empty(), "back() called for empty vector"); |
| 676 | return *(this->__end_ - 1); |
| 677 | } |
| 678 | _LIBCPP_INLINE_VISIBILITY const_reference back() const |
| 679 | { |
| 680 | _LIBCPP_ASSERT(!empty(), "back() called for empty vector"); |
| 681 | return *(this->__end_ - 1); |
| 682 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 683 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 684 | _LIBCPP_INLINE_VISIBILITY |
| 685 | value_type* data() _NOEXCEPT |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 686 | {return _VSTD::__to_raw_pointer(this->__begin_);} |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 687 | _LIBCPP_INLINE_VISIBILITY |
| 688 | const value_type* data() const _NOEXCEPT |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 689 | {return _VSTD::__to_raw_pointer(this->__begin_);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 690 | |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 691 | _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 692 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | b0bfd9b | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 693 | _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 694 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 695 | template <class... _Args> |
| 696 | void emplace_back(_Args&&... __args); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 697 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 698 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 699 | void pop_back(); |
| 700 | |
| 701 | iterator insert(const_iterator __position, const_reference __x); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 702 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 703 | iterator insert(const_iterator __position, value_type&& __x); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 704 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 705 | template <class... _Args> |
| 706 | iterator emplace(const_iterator __position, _Args&&... __args); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 707 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 708 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 709 | iterator insert(const_iterator __position, size_type __n, const_reference __x); |
| 710 | template <class _InputIterator> |
| 711 | typename enable_if |
| 712 | < |
| 713 | __is_input_iterator <_InputIterator>::value && |
Howard Hinnant | 742fecb | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 714 | !__is_forward_iterator<_InputIterator>::value && |
| 715 | is_constructible< |
| 716 | value_type, |
| 717 | typename iterator_traits<_InputIterator>::reference>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 718 | iterator |
| 719 | >::type |
| 720 | insert(const_iterator __position, _InputIterator __first, _InputIterator __last); |
| 721 | template <class _ForwardIterator> |
| 722 | typename enable_if |
| 723 | < |
Howard Hinnant | 742fecb | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 724 | __is_forward_iterator<_ForwardIterator>::value && |
| 725 | is_constructible< |
| 726 | value_type, |
| 727 | typename iterator_traits<_ForwardIterator>::reference>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 728 | iterator |
| 729 | >::type |
| 730 | insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 731 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 732 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 733 | iterator insert(const_iterator __position, initializer_list<value_type> __il) |
| 734 | {return insert(__position, __il.begin(), __il.end());} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 735 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 736 | |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 737 | _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 738 | iterator erase(const_iterator __first, const_iterator __last); |
| 739 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 740 | _LIBCPP_INLINE_VISIBILITY |
| 741 | void clear() _NOEXCEPT |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 742 | { |
| 743 | __base::clear(); |
| 744 | __invalidate_all_iterators(); |
| 745 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 746 | |
| 747 | void resize(size_type __sz); |
| 748 | void resize(size_type __sz, const_reference __x); |
| 749 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 750 | void swap(vector&) |
| 751 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
| 752 | __is_nothrow_swappable<allocator_type>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 753 | |
| 754 | bool __invariants() const; |
| 755 | |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 756 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 757 | |
| 758 | bool __dereferenceable(const const_iterator* __i) const; |
| 759 | bool __decrementable(const const_iterator* __i) const; |
| 760 | bool __addable(const const_iterator* __i, ptrdiff_t __n) const; |
| 761 | bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; |
| 762 | |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 763 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 764 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 765 | private: |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 766 | _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 767 | void allocate(size_type __n); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 768 | void deallocate() _NOEXCEPT; |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 769 | _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; |
Howard Hinnant | 04240d9 | 2011-01-04 19:53:31 +0000 | [diff] [blame] | 770 | void __construct_at_end(size_type __n); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 771 | void __construct_at_end(size_type __n, const_reference __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 772 | template <class _ForwardIterator> |
| 773 | typename enable_if |
| 774 | < |
| 775 | __is_forward_iterator<_ForwardIterator>::value, |
| 776 | void |
| 777 | >::type |
| 778 | __construct_at_end(_ForwardIterator __first, _ForwardIterator __last); |
| 779 | void __move_construct_at_end(pointer __first, pointer __last); |
| 780 | void __append(size_type __n); |
| 781 | void __append(size_type __n, const_reference __x); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 782 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 783 | iterator __make_iter(pointer __p) _NOEXCEPT; |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 784 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 785 | const_iterator __make_iter(const_pointer __p) const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 786 | void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v); |
| 787 | pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p); |
| 788 | void __move_range(pointer __from_s, pointer __from_e, pointer __to); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 789 | void __move_assign(vector& __c, true_type) |
| 790 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 791 | void __move_assign(vector& __c, false_type); |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 792 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 793 | void __destruct_at_end(pointer __new_last) _NOEXCEPT |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 794 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 795 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 796 | __c_node* __c = __get_db()->__find_c_and_lock(this); |
| 797 | for (__i_node** __p = __c->end_; __p != __c->beg_; ) |
| 798 | { |
| 799 | --__p; |
| 800 | const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); |
| 801 | if (__i->base() > __new_last) |
| 802 | { |
| 803 | (*__p)->__c_ = nullptr; |
| 804 | if (--__c->end_ != __p) |
| 805 | memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); |
| 806 | } |
| 807 | } |
| 808 | __get_db()->unlock(); |
| 809 | #endif |
| 810 | __base::__destruct_at_end(__new_last); |
| 811 | } |
Howard Hinnant | b0bfd9b | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 812 | template <class _Up> |
| 813 | void |
| 814 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 815 | __push_back_slow_path(_Up&& __x); |
| 816 | #else |
| 817 | __push_back_slow_path(_Up& __x); |
| 818 | #endif |
Howard Hinnant | 0438ea2 | 2012-02-26 15:30:12 +0000 | [diff] [blame] | 819 | #if !defined(_LIBCPP_HAS_NO_VARIADICS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) |
| 820 | template <class... _Args> |
| 821 | void |
| 822 | __emplace_back_slow_path(_Args&&... __args); |
| 823 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 824 | }; |
| 825 | |
| 826 | template <class _Tp, class _Allocator> |
| 827 | void |
| 828 | vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v) |
| 829 | { |
Howard Hinnant | b0bfd9b | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 830 | __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, this->__end_, __v.__begin_); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 831 | _VSTD::swap(this->__begin_, __v.__begin_); |
| 832 | _VSTD::swap(this->__end_, __v.__end_); |
| 833 | _VSTD::swap(this->__end_cap(), __v.__end_cap()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 834 | __v.__first_ = __v.__begin_; |
| 835 | __invalidate_all_iterators(); |
| 836 | } |
| 837 | |
| 838 | template <class _Tp, class _Allocator> |
| 839 | typename vector<_Tp, _Allocator>::pointer |
| 840 | vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p) |
| 841 | { |
| 842 | pointer __r = __v.__begin_; |
Howard Hinnant | b0bfd9b | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 843 | __alloc_traits::__construct_backward(this->__alloc(), this->__begin_, __p, __v.__begin_); |
| 844 | __alloc_traits::__construct_forward(this->__alloc(), __p, this->__end_, __v.__end_); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 845 | _VSTD::swap(this->__begin_, __v.__begin_); |
| 846 | _VSTD::swap(this->__end_, __v.__end_); |
| 847 | _VSTD::swap(this->__end_cap(), __v.__end_cap()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 848 | __v.__first_ = __v.__begin_; |
| 849 | __invalidate_all_iterators(); |
| 850 | return __r; |
| 851 | } |
| 852 | |
| 853 | // Allocate space for __n objects |
| 854 | // throws length_error if __n > max_size() |
| 855 | // throws (probably bad_alloc) if memory run out |
| 856 | // Precondition: __begin_ == __end_ == __end_cap() == 0 |
| 857 | // Precondition: __n > 0 |
| 858 | // Postcondition: capacity() == __n |
| 859 | // Postcondition: size() == 0 |
| 860 | template <class _Tp, class _Allocator> |
| 861 | void |
| 862 | vector<_Tp, _Allocator>::allocate(size_type __n) |
| 863 | { |
| 864 | if (__n > max_size()) |
| 865 | this->__throw_length_error(); |
| 866 | this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n); |
| 867 | this->__end_cap() = this->__begin_ + __n; |
| 868 | } |
| 869 | |
| 870 | template <class _Tp, class _Allocator> |
| 871 | void |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 872 | vector<_Tp, _Allocator>::deallocate() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 873 | { |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 874 | if (this->__begin_ != nullptr) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 875 | { |
| 876 | clear(); |
| 877 | __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity()); |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 878 | this->__begin_ = this->__end_ = this->__end_cap() = nullptr; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 879 | } |
| 880 | } |
| 881 | |
| 882 | template <class _Tp, class _Allocator> |
| 883 | typename vector<_Tp, _Allocator>::size_type |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 884 | vector<_Tp, _Allocator>::max_size() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 885 | { |
Sean Hunt | 110b8bf | 2011-07-29 23:31:58 +0000 | [diff] [blame] | 886 | return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()), numeric_limits<size_type>::max() / 2); // end() >= begin(), always |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | // Precondition: __new_size > capacity() |
| 890 | template <class _Tp, class _Allocator> |
| 891 | _LIBCPP_INLINE_VISIBILITY inline |
| 892 | typename vector<_Tp, _Allocator>::size_type |
| 893 | vector<_Tp, _Allocator>::__recommend(size_type __new_size) const |
| 894 | { |
| 895 | const size_type __ms = max_size(); |
| 896 | if (__new_size > __ms) |
| 897 | this->__throw_length_error(); |
| 898 | const size_type __cap = capacity(); |
| 899 | if (__cap >= __ms / 2) |
| 900 | return __ms; |
Sean Hunt | 110b8bf | 2011-07-29 23:31:58 +0000 | [diff] [blame] | 901 | return _VSTD::max<size_type>(2*__cap, __new_size); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | // Default constructs __n objects starting at __end_ |
| 905 | // throws if construction throws |
| 906 | // Precondition: __n > 0 |
| 907 | // Precondition: size() + __n <= capacity() |
| 908 | // Postcondition: size() == size() + __n |
| 909 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 910 | void |
| 911 | vector<_Tp, _Allocator>::__construct_at_end(size_type __n) |
| 912 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 913 | allocator_type& __a = this->__alloc(); |
| 914 | do |
| 915 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 916 | __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 917 | ++this->__end_; |
| 918 | --__n; |
| 919 | } while (__n > 0); |
| 920 | } |
| 921 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 922 | // Copy constructs __n objects starting at __end_ from __x |
| 923 | // throws if construction throws |
| 924 | // Precondition: __n > 0 |
| 925 | // Precondition: size() + __n <= capacity() |
| 926 | // Postcondition: size() == old size() + __n |
| 927 | // Postcondition: [i] == __x for all i in [size() - __n, __n) |
| 928 | template <class _Tp, class _Allocator> |
| 929 | _LIBCPP_INLINE_VISIBILITY inline |
| 930 | void |
| 931 | vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) |
| 932 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 933 | allocator_type& __a = this->__alloc(); |
| 934 | do |
| 935 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 936 | __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 937 | ++this->__end_; |
| 938 | --__n; |
| 939 | } while (__n > 0); |
| 940 | } |
| 941 | |
| 942 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 943 | template <class _ForwardIterator> |
| 944 | typename enable_if |
| 945 | < |
| 946 | __is_forward_iterator<_ForwardIterator>::value, |
| 947 | void |
| 948 | >::type |
| 949 | vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last) |
| 950 | { |
| 951 | allocator_type& __a = this->__alloc(); |
| 952 | for (; __first != __last; ++__first) |
| 953 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 954 | __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 955 | ++this->__end_; |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | template <class _Tp, class _Allocator> |
| 960 | void |
| 961 | vector<_Tp, _Allocator>::__move_construct_at_end(pointer __first, pointer __last) |
| 962 | { |
| 963 | allocator_type& __a = this->__alloc(); |
| 964 | for (; __first != __last; ++__first) |
| 965 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 966 | __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), |
| 967 | _VSTD::move(*__first)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 968 | ++this->__end_; |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | // Default constructs __n objects starting at __end_ |
| 973 | // throws if construction throws |
| 974 | // Postcondition: size() == size() + __n |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 975 | // Exception safety: strong. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 976 | template <class _Tp, class _Allocator> |
| 977 | void |
| 978 | vector<_Tp, _Allocator>::__append(size_type __n) |
| 979 | { |
| 980 | if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) |
| 981 | this->__construct_at_end(__n); |
| 982 | else |
| 983 | { |
| 984 | allocator_type& __a = this->__alloc(); |
| 985 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); |
| 986 | __v.__construct_at_end(__n); |
| 987 | __swap_out_circular_buffer(__v); |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | // Default constructs __n objects starting at __end_ |
| 992 | // throws if construction throws |
| 993 | // Postcondition: size() == size() + __n |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 994 | // Exception safety: strong. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 995 | template <class _Tp, class _Allocator> |
| 996 | void |
| 997 | vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x) |
| 998 | { |
| 999 | if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) |
| 1000 | this->__construct_at_end(__n, __x); |
| 1001 | else |
| 1002 | { |
| 1003 | allocator_type& __a = this->__alloc(); |
| 1004 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); |
| 1005 | __v.__construct_at_end(__n, __x); |
| 1006 | __swap_out_circular_buffer(__v); |
| 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | template <class _Tp, class _Allocator> |
| 1011 | vector<_Tp, _Allocator>::vector(size_type __n) |
| 1012 | { |
Howard Hinnant | 0442b12 | 2011-09-16 18:41:29 +0000 | [diff] [blame] | 1013 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1014 | __get_db()->__insert_c(this); |
| 1015 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1016 | if (__n > 0) |
| 1017 | { |
| 1018 | allocate(__n); |
| 1019 | __construct_at_end(__n); |
| 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | template <class _Tp, class _Allocator> |
| 1024 | vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x) |
| 1025 | { |
Howard Hinnant | 0442b12 | 2011-09-16 18:41:29 +0000 | [diff] [blame] | 1026 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1027 | __get_db()->__insert_c(this); |
| 1028 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1029 | if (__n > 0) |
| 1030 | { |
| 1031 | allocate(__n); |
| 1032 | __construct_at_end(__n, __x); |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | template <class _Tp, class _Allocator> |
| 1037 | vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a) |
| 1038 | : __base(__a) |
| 1039 | { |
Howard Hinnant | 0442b12 | 2011-09-16 18:41:29 +0000 | [diff] [blame] | 1040 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1041 | __get_db()->__insert_c(this); |
| 1042 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1043 | if (__n > 0) |
| 1044 | { |
| 1045 | allocate(__n); |
| 1046 | __construct_at_end(__n, __x); |
| 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | template <class _Tp, class _Allocator> |
| 1051 | template <class _InputIterator> |
| 1052 | vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, |
| 1053 | typename enable_if<__is_input_iterator <_InputIterator>::value && |
Howard Hinnant | 742fecb | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 1054 | !__is_forward_iterator<_InputIterator>::value && |
| 1055 | is_constructible< |
| 1056 | value_type, |
| 1057 | typename iterator_traits<_InputIterator>::reference>::value>::type*) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1058 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1059 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1060 | __get_db()->__insert_c(this); |
| 1061 | #endif |
Howard Hinnant | 0442b12 | 2011-09-16 18:41:29 +0000 | [diff] [blame] | 1062 | for (; __first != __last; ++__first) |
| 1063 | push_back(*__first); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | template <class _Tp, class _Allocator> |
| 1067 | template <class _InputIterator> |
| 1068 | vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, |
| 1069 | typename enable_if<__is_input_iterator <_InputIterator>::value && |
Howard Hinnant | 742fecb | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 1070 | !__is_forward_iterator<_InputIterator>::value && |
| 1071 | is_constructible< |
| 1072 | value_type, |
| 1073 | typename iterator_traits<_InputIterator>::reference>::value>::type*) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1074 | : __base(__a) |
| 1075 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1076 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1077 | __get_db()->__insert_c(this); |
| 1078 | #endif |
Howard Hinnant | 0442b12 | 2011-09-16 18:41:29 +0000 | [diff] [blame] | 1079 | for (; __first != __last; ++__first) |
| 1080 | push_back(*__first); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | template <class _Tp, class _Allocator> |
| 1084 | template <class _ForwardIterator> |
| 1085 | vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, |
Howard Hinnant | 742fecb | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 1086 | typename enable_if<__is_forward_iterator<_ForwardIterator>::value && |
| 1087 | is_constructible< |
| 1088 | value_type, |
| 1089 | typename iterator_traits<_ForwardIterator>::reference>::value>::type*) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1090 | { |
Howard Hinnant | 0442b12 | 2011-09-16 18:41:29 +0000 | [diff] [blame] | 1091 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1092 | __get_db()->__insert_c(this); |
| 1093 | #endif |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1094 | size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1095 | if (__n > 0) |
| 1096 | { |
| 1097 | allocate(__n); |
| 1098 | __construct_at_end(__first, __last); |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | template <class _Tp, class _Allocator> |
| 1103 | template <class _ForwardIterator> |
| 1104 | vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, |
Howard Hinnant | 742fecb | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 1105 | typename enable_if<__is_forward_iterator<_ForwardIterator>::value && |
| 1106 | is_constructible< |
| 1107 | value_type, |
| 1108 | typename iterator_traits<_ForwardIterator>::reference>::value>::type*) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1109 | : __base(__a) |
| 1110 | { |
Howard Hinnant | 0442b12 | 2011-09-16 18:41:29 +0000 | [diff] [blame] | 1111 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1112 | __get_db()->__insert_c(this); |
| 1113 | #endif |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1114 | size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1115 | if (__n > 0) |
| 1116 | { |
| 1117 | allocate(__n); |
| 1118 | __construct_at_end(__first, __last); |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | template <class _Tp, class _Allocator> |
| 1123 | vector<_Tp, _Allocator>::vector(const vector& __x) |
| 1124 | : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc())) |
| 1125 | { |
Howard Hinnant | 0442b12 | 2011-09-16 18:41:29 +0000 | [diff] [blame] | 1126 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1127 | __get_db()->__insert_c(this); |
| 1128 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1129 | size_type __n = __x.size(); |
| 1130 | if (__n > 0) |
| 1131 | { |
| 1132 | allocate(__n); |
| 1133 | __construct_at_end(__x.__begin_, __x.__end_); |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | template <class _Tp, class _Allocator> |
| 1138 | vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a) |
| 1139 | : __base(__a) |
| 1140 | { |
Howard Hinnant | 0442b12 | 2011-09-16 18:41:29 +0000 | [diff] [blame] | 1141 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1142 | __get_db()->__insert_c(this); |
| 1143 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1144 | size_type __n = __x.size(); |
| 1145 | if (__n > 0) |
| 1146 | { |
| 1147 | allocate(__n); |
| 1148 | __construct_at_end(__x.__begin_, __x.__end_); |
| 1149 | } |
| 1150 | } |
| 1151 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1152 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1153 | |
| 1154 | template <class _Tp, class _Allocator> |
| 1155 | _LIBCPP_INLINE_VISIBILITY inline |
| 1156 | vector<_Tp, _Allocator>::vector(vector&& __x) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1157 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1158 | : __base(_VSTD::move(__x.__alloc())) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1159 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1160 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1161 | __get_db()->__insert_c(this); |
Howard Hinnant | e6125bd | 2011-09-19 16:34:29 +0000 | [diff] [blame] | 1162 | __get_db()->swap(this, &__x); |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1163 | #endif |
Howard Hinnant | 0442b12 | 2011-09-16 18:41:29 +0000 | [diff] [blame] | 1164 | this->__begin_ = __x.__begin_; |
| 1165 | this->__end_ = __x.__end_; |
| 1166 | this->__end_cap() = __x.__end_cap(); |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 1167 | __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | template <class _Tp, class _Allocator> |
| 1171 | _LIBCPP_INLINE_VISIBILITY inline |
| 1172 | vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a) |
| 1173 | : __base(__a) |
| 1174 | { |
Howard Hinnant | 0442b12 | 2011-09-16 18:41:29 +0000 | [diff] [blame] | 1175 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1176 | __get_db()->__insert_c(this); |
| 1177 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1178 | if (__a == __x.__alloc()) |
| 1179 | { |
| 1180 | this->__begin_ = __x.__begin_; |
| 1181 | this->__end_ = __x.__end_; |
| 1182 | this->__end_cap() = __x.__end_cap(); |
| 1183 | __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; |
Howard Hinnant | e6125bd | 2011-09-19 16:34:29 +0000 | [diff] [blame] | 1184 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1185 | __get_db()->swap(this, &__x); |
| 1186 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1187 | } |
| 1188 | else |
| 1189 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1190 | typedef move_iterator<iterator> _Ip; |
| 1191 | assign(_Ip(__x.begin()), _Ip(__x.end())); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1192 | } |
| 1193 | } |
| 1194 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1195 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 1196 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1197 | template <class _Tp, class _Allocator> |
| 1198 | _LIBCPP_INLINE_VISIBILITY inline |
| 1199 | vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il) |
| 1200 | { |
Howard Hinnant | 0442b12 | 2011-09-16 18:41:29 +0000 | [diff] [blame] | 1201 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1202 | __get_db()->__insert_c(this); |
| 1203 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1204 | if (__il.size() > 0) |
| 1205 | { |
| 1206 | allocate(__il.size()); |
| 1207 | __construct_at_end(__il.begin(), __il.end()); |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | template <class _Tp, class _Allocator> |
| 1212 | _LIBCPP_INLINE_VISIBILITY inline |
| 1213 | vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) |
| 1214 | : __base(__a) |
| 1215 | { |
Howard Hinnant | 0442b12 | 2011-09-16 18:41:29 +0000 | [diff] [blame] | 1216 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1217 | __get_db()->__insert_c(this); |
| 1218 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1219 | if (__il.size() > 0) |
| 1220 | { |
| 1221 | allocate(__il.size()); |
| 1222 | __construct_at_end(__il.begin(), __il.end()); |
| 1223 | } |
| 1224 | } |
| 1225 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1226 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 1227 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1228 | template <class _Tp, class _Allocator> |
| 1229 | _LIBCPP_INLINE_VISIBILITY inline |
| 1230 | vector<_Tp, _Allocator>& |
| 1231 | vector<_Tp, _Allocator>::operator=(vector&& __x) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1232 | _NOEXCEPT_( |
| 1233 | __alloc_traits::propagate_on_container_move_assignment::value && |
| 1234 | is_nothrow_move_assignable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1235 | { |
| 1236 | __move_assign(__x, integral_constant<bool, |
| 1237 | __alloc_traits::propagate_on_container_move_assignment::value>()); |
| 1238 | return *this; |
| 1239 | } |
| 1240 | |
| 1241 | template <class _Tp, class _Allocator> |
| 1242 | void |
| 1243 | vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type) |
| 1244 | { |
| 1245 | if (__base::__alloc() != __c.__alloc()) |
| 1246 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1247 | typedef move_iterator<iterator> _Ip; |
| 1248 | assign(_Ip(__c.begin()), _Ip(__c.end())); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1249 | } |
| 1250 | else |
| 1251 | __move_assign(__c, true_type()); |
| 1252 | } |
| 1253 | |
| 1254 | template <class _Tp, class _Allocator> |
| 1255 | void |
| 1256 | vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1257 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1258 | { |
| 1259 | deallocate(); |
| 1260 | this->__begin_ = __c.__begin_; |
| 1261 | this->__end_ = __c.__end_; |
| 1262 | this->__end_cap() = __c.__end_cap(); |
| 1263 | __base::__move_assign_alloc(__c); |
| 1264 | __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr; |
Howard Hinnant | e6125bd | 2011-09-19 16:34:29 +0000 | [diff] [blame] | 1265 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1266 | __get_db()->swap(this, &__c); |
| 1267 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1268 | } |
| 1269 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1270 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1271 | |
| 1272 | template <class _Tp, class _Allocator> |
| 1273 | _LIBCPP_INLINE_VISIBILITY inline |
| 1274 | vector<_Tp, _Allocator>& |
| 1275 | vector<_Tp, _Allocator>::operator=(const vector& __x) |
| 1276 | { |
| 1277 | if (this != &__x) |
| 1278 | { |
| 1279 | __base::__copy_assign_alloc(__x); |
| 1280 | assign(__x.__begin_, __x.__end_); |
| 1281 | } |
| 1282 | return *this; |
| 1283 | } |
| 1284 | |
| 1285 | template <class _Tp, class _Allocator> |
| 1286 | template <class _InputIterator> |
| 1287 | typename enable_if |
| 1288 | < |
| 1289 | __is_input_iterator <_InputIterator>::value && |
Howard Hinnant | 742fecb | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 1290 | !__is_forward_iterator<_InputIterator>::value && |
| 1291 | is_constructible< |
| 1292 | _Tp, |
| 1293 | typename iterator_traits<_InputIterator>::reference>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1294 | void |
| 1295 | >::type |
| 1296 | vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last) |
| 1297 | { |
| 1298 | clear(); |
| 1299 | for (; __first != __last; ++__first) |
| 1300 | push_back(*__first); |
| 1301 | } |
| 1302 | |
| 1303 | template <class _Tp, class _Allocator> |
| 1304 | template <class _ForwardIterator> |
| 1305 | typename enable_if |
| 1306 | < |
Howard Hinnant | 742fecb | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 1307 | __is_forward_iterator<_ForwardIterator>::value && |
| 1308 | is_constructible< |
| 1309 | _Tp, |
| 1310 | typename iterator_traits<_ForwardIterator>::reference>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1311 | void |
| 1312 | >::type |
| 1313 | vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) |
| 1314 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1315 | typename iterator_traits<_ForwardIterator>::difference_type __new_size = _VSTD::distance(__first, __last); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1316 | if (static_cast<size_type>(__new_size) <= capacity()) |
| 1317 | { |
| 1318 | _ForwardIterator __mid = __last; |
| 1319 | bool __growing = false; |
| 1320 | if (static_cast<size_type>(__new_size) > size()) |
| 1321 | { |
| 1322 | __growing = true; |
| 1323 | __mid = __first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1324 | _VSTD::advance(__mid, size()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1325 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1326 | pointer __m = _VSTD::copy(__first, __mid, this->__begin_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1327 | if (__growing) |
| 1328 | __construct_at_end(__mid, __last); |
| 1329 | else |
| 1330 | this->__destruct_at_end(__m); |
| 1331 | } |
| 1332 | else |
| 1333 | { |
| 1334 | deallocate(); |
| 1335 | allocate(__recommend(static_cast<size_type>(__new_size))); |
| 1336 | __construct_at_end(__first, __last); |
| 1337 | } |
| 1338 | } |
| 1339 | |
| 1340 | template <class _Tp, class _Allocator> |
| 1341 | void |
| 1342 | vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u) |
| 1343 | { |
| 1344 | if (__n <= capacity()) |
| 1345 | { |
| 1346 | size_type __s = size(); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1347 | _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1348 | if (__n > __s) |
| 1349 | __construct_at_end(__n - __s, __u); |
| 1350 | else |
Howard Hinnant | adff489 | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 1351 | this->__destruct_at_end(this->__begin_ + __n); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1352 | } |
| 1353 | else |
| 1354 | { |
| 1355 | deallocate(); |
| 1356 | allocate(__recommend(static_cast<size_type>(__n))); |
| 1357 | __construct_at_end(__n, __u); |
| 1358 | } |
| 1359 | } |
| 1360 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1361 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1362 | _LIBCPP_INLINE_VISIBILITY inline |
| 1363 | typename vector<_Tp, _Allocator>::iterator |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1364 | vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1365 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1366 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1367 | return iterator(this, __p); |
| 1368 | #else |
| 1369 | return iterator(__p); |
| 1370 | #endif |
| 1371 | } |
| 1372 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1373 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1374 | _LIBCPP_INLINE_VISIBILITY inline |
| 1375 | typename vector<_Tp, _Allocator>::const_iterator |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1376 | vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1377 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1378 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1379 | return const_iterator(this, __p); |
| 1380 | #else |
| 1381 | return const_iterator(__p); |
| 1382 | #endif |
| 1383 | } |
| 1384 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1385 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1386 | _LIBCPP_INLINE_VISIBILITY inline |
| 1387 | typename vector<_Tp, _Allocator>::iterator |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1388 | vector<_Tp, _Allocator>::begin() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1389 | { |
| 1390 | return __make_iter(this->__begin_); |
| 1391 | } |
| 1392 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1393 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1394 | _LIBCPP_INLINE_VISIBILITY inline |
| 1395 | typename vector<_Tp, _Allocator>::const_iterator |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1396 | vector<_Tp, _Allocator>::begin() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1397 | { |
| 1398 | return __make_iter(this->__begin_); |
| 1399 | } |
| 1400 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1401 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1402 | _LIBCPP_INLINE_VISIBILITY inline |
| 1403 | typename vector<_Tp, _Allocator>::iterator |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1404 | vector<_Tp, _Allocator>::end() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1405 | { |
| 1406 | return __make_iter(this->__end_); |
| 1407 | } |
| 1408 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1409 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1410 | _LIBCPP_INLINE_VISIBILITY inline |
| 1411 | typename vector<_Tp, _Allocator>::const_iterator |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1412 | vector<_Tp, _Allocator>::end() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1413 | { |
| 1414 | return __make_iter(this->__end_); |
| 1415 | } |
| 1416 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1417 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1418 | _LIBCPP_INLINE_VISIBILITY inline |
| 1419 | typename vector<_Tp, _Allocator>::reference |
| 1420 | vector<_Tp, _Allocator>::operator[](size_type __n) |
| 1421 | { |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1422 | _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1423 | return this->__begin_[__n]; |
| 1424 | } |
| 1425 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1426 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1427 | _LIBCPP_INLINE_VISIBILITY inline |
| 1428 | typename vector<_Tp, _Allocator>::const_reference |
| 1429 | vector<_Tp, _Allocator>::operator[](size_type __n) const |
| 1430 | { |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1431 | _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1432 | return this->__begin_[__n]; |
| 1433 | } |
| 1434 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1435 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1436 | typename vector<_Tp, _Allocator>::reference |
| 1437 | vector<_Tp, _Allocator>::at(size_type __n) |
| 1438 | { |
| 1439 | if (__n >= size()) |
| 1440 | this->__throw_out_of_range(); |
| 1441 | return this->__begin_[__n]; |
| 1442 | } |
| 1443 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1444 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1445 | typename vector<_Tp, _Allocator>::const_reference |
| 1446 | vector<_Tp, _Allocator>::at(size_type __n) const |
| 1447 | { |
| 1448 | if (__n >= size()) |
| 1449 | this->__throw_out_of_range(); |
| 1450 | return this->__begin_[__n]; |
| 1451 | } |
| 1452 | |
| 1453 | template <class _Tp, class _Allocator> |
| 1454 | void |
| 1455 | vector<_Tp, _Allocator>::reserve(size_type __n) |
| 1456 | { |
| 1457 | if (__n > capacity()) |
| 1458 | { |
| 1459 | allocator_type& __a = this->__alloc(); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1460 | __split_buffer<value_type, allocator_type&> __v(__n, size(), __a); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1461 | __swap_out_circular_buffer(__v); |
| 1462 | } |
| 1463 | } |
| 1464 | |
| 1465 | template <class _Tp, class _Allocator> |
| 1466 | void |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1467 | vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1468 | { |
| 1469 | if (capacity() > size()) |
| 1470 | { |
| 1471 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1472 | try |
| 1473 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1474 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1475 | allocator_type& __a = this->__alloc(); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1476 | __split_buffer<value_type, allocator_type&> __v(size(), size(), __a); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1477 | __swap_out_circular_buffer(__v); |
| 1478 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1479 | } |
| 1480 | catch (...) |
| 1481 | { |
| 1482 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1483 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1484 | } |
| 1485 | } |
| 1486 | |
| 1487 | template <class _Tp, class _Allocator> |
Howard Hinnant | b0bfd9b | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1488 | template <class _Up> |
| 1489 | void |
| 1490 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 1491 | vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x) |
| 1492 | #else |
| 1493 | vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x) |
| 1494 | #endif |
| 1495 | { |
| 1496 | allocator_type& __a = this->__alloc(); |
| 1497 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); |
| 1498 | // __v.push_back(_VSTD::forward<_Up>(__x)); |
Howard Hinnant | f619e23 | 2013-01-11 20:36:59 +0000 | [diff] [blame] | 1499 | __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Up>(__x)); |
| 1500 | __v.__end_++; |
Howard Hinnant | b0bfd9b | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1501 | __swap_out_circular_buffer(__v); |
| 1502 | } |
| 1503 | |
| 1504 | template <class _Tp, class _Allocator> |
| 1505 | _LIBCPP_INLINE_VISIBILITY inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1506 | void |
| 1507 | vector<_Tp, _Allocator>::push_back(const_reference __x) |
| 1508 | { |
Howard Hinnant | b0bfd9b | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1509 | if (this->__end_ != this->__end_cap()) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1510 | { |
| 1511 | __alloc_traits::construct(this->__alloc(), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1512 | _VSTD::__to_raw_pointer(this->__end_), __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1513 | ++this->__end_; |
| 1514 | } |
| 1515 | else |
Howard Hinnant | b0bfd9b | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1516 | __push_back_slow_path(__x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1519 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1520 | |
| 1521 | template <class _Tp, class _Allocator> |
Howard Hinnant | b0bfd9b | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1522 | _LIBCPP_INLINE_VISIBILITY inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1523 | void |
| 1524 | vector<_Tp, _Allocator>::push_back(value_type&& __x) |
| 1525 | { |
| 1526 | if (this->__end_ < this->__end_cap()) |
| 1527 | { |
| 1528 | __alloc_traits::construct(this->__alloc(), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1529 | _VSTD::__to_raw_pointer(this->__end_), |
| 1530 | _VSTD::move(__x)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1531 | ++this->__end_; |
| 1532 | } |
| 1533 | else |
Howard Hinnant | b0bfd9b | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1534 | __push_back_slow_path(_VSTD::move(__x)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1535 | } |
| 1536 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1537 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1538 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1539 | template <class _Tp, class _Allocator> |
| 1540 | template <class... _Args> |
| 1541 | void |
Howard Hinnant | 0438ea2 | 2012-02-26 15:30:12 +0000 | [diff] [blame] | 1542 | vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args) |
| 1543 | { |
| 1544 | allocator_type& __a = this->__alloc(); |
| 1545 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); |
| 1546 | // __v.emplace_back(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | f619e23 | 2013-01-11 20:36:59 +0000 | [diff] [blame] | 1547 | __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Args>(__args)...); |
| 1548 | __v.__end_++; |
Howard Hinnant | 0438ea2 | 2012-02-26 15:30:12 +0000 | [diff] [blame] | 1549 | __swap_out_circular_buffer(__v); |
| 1550 | } |
| 1551 | |
| 1552 | template <class _Tp, class _Allocator> |
| 1553 | template <class... _Args> |
| 1554 | _LIBCPP_INLINE_VISIBILITY inline |
| 1555 | void |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1556 | vector<_Tp, _Allocator>::emplace_back(_Args&&... __args) |
| 1557 | { |
| 1558 | if (this->__end_ < this->__end_cap()) |
| 1559 | { |
| 1560 | __alloc_traits::construct(this->__alloc(), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1561 | _VSTD::__to_raw_pointer(this->__end_), |
| 1562 | _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1563 | ++this->__end_; |
| 1564 | } |
| 1565 | else |
Howard Hinnant | 0438ea2 | 2012-02-26 15:30:12 +0000 | [diff] [blame] | 1566 | __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1567 | } |
| 1568 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1569 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1570 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1571 | |
| 1572 | template <class _Tp, class _Allocator> |
| 1573 | _LIBCPP_INLINE_VISIBILITY inline |
| 1574 | void |
| 1575 | vector<_Tp, _Allocator>::pop_back() |
| 1576 | { |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1577 | _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1578 | this->__destruct_at_end(this->__end_ - 1); |
| 1579 | } |
| 1580 | |
| 1581 | template <class _Tp, class _Allocator> |
| 1582 | _LIBCPP_INLINE_VISIBILITY inline |
| 1583 | typename vector<_Tp, _Allocator>::iterator |
| 1584 | vector<_Tp, _Allocator>::erase(const_iterator __position) |
| 1585 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1586 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1587 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, |
| 1588 | "vector::erase(iterator) called with an iterator not" |
| 1589 | " referring to this vector"); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1590 | #endif |
Howard Hinnant | 782da33 | 2013-03-25 22:12:26 +0000 | [diff] [blame] | 1591 | _LIBCPP_ASSERT(__position != end(), |
| 1592 | "vector::erase(iterator) called with a non-dereferenceable iterator"); |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 1593 | difference_type __ps = __position - cbegin(); |
| 1594 | pointer __p = this->__begin_ + __ps; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1595 | iterator __r = __make_iter(__p); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1596 | this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1597 | return __r; |
| 1598 | } |
| 1599 | |
| 1600 | template <class _Tp, class _Allocator> |
| 1601 | typename vector<_Tp, _Allocator>::iterator |
| 1602 | vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) |
| 1603 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1604 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1605 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, |
| 1606 | "vector::erase(iterator, iterator) called with an iterator not" |
| 1607 | " referring to this vector"); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1608 | #endif |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1609 | _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1610 | pointer __p = this->__begin_ + (__first - begin()); |
| 1611 | iterator __r = __make_iter(__p); |
Howard Hinnant | b4e67cf | 2013-04-18 15:02:57 +0000 | [diff] [blame] | 1612 | if (__first != __last) |
| 1613 | this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1614 | return __r; |
| 1615 | } |
| 1616 | |
| 1617 | template <class _Tp, class _Allocator> |
| 1618 | void |
| 1619 | vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to) |
| 1620 | { |
| 1621 | pointer __old_last = this->__end_; |
| 1622 | difference_type __n = __old_last - __to; |
| 1623 | for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_) |
| 1624 | __alloc_traits::construct(this->__alloc(), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1625 | _VSTD::__to_raw_pointer(this->__end_), |
| 1626 | _VSTD::move(*__i)); |
| 1627 | _VSTD::move_backward(__from_s, __from_s + __n, __old_last); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | template <class _Tp, class _Allocator> |
| 1631 | typename vector<_Tp, _Allocator>::iterator |
| 1632 | vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) |
| 1633 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1634 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1635 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, |
| 1636 | "vector::insert(iterator, x) called with an iterator not" |
| 1637 | " referring to this vector"); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1638 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1639 | pointer __p = this->__begin_ + (__position - begin()); |
| 1640 | if (this->__end_ < this->__end_cap()) |
| 1641 | { |
| 1642 | if (__p == this->__end_) |
| 1643 | { |
| 1644 | __alloc_traits::construct(this->__alloc(), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1645 | _VSTD::__to_raw_pointer(this->__end_), __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1646 | ++this->__end_; |
| 1647 | } |
| 1648 | else |
| 1649 | { |
| 1650 | __move_range(__p, this->__end_, __p + 1); |
| 1651 | const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); |
| 1652 | if (__p <= __xr && __xr < this->__end_) |
| 1653 | ++__xr; |
| 1654 | *__p = *__xr; |
| 1655 | } |
| 1656 | } |
| 1657 | else |
| 1658 | { |
| 1659 | allocator_type& __a = this->__alloc(); |
| 1660 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); |
| 1661 | __v.push_back(__x); |
| 1662 | __p = __swap_out_circular_buffer(__v, __p); |
| 1663 | } |
| 1664 | return __make_iter(__p); |
| 1665 | } |
| 1666 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1667 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1668 | |
| 1669 | template <class _Tp, class _Allocator> |
| 1670 | typename vector<_Tp, _Allocator>::iterator |
| 1671 | vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) |
| 1672 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1673 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1674 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, |
| 1675 | "vector::insert(iterator, x) called with an iterator not" |
| 1676 | " referring to this vector"); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1677 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1678 | pointer __p = this->__begin_ + (__position - begin()); |
| 1679 | if (this->__end_ < this->__end_cap()) |
| 1680 | { |
| 1681 | if (__p == this->__end_) |
| 1682 | { |
| 1683 | __alloc_traits::construct(this->__alloc(), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1684 | _VSTD::__to_raw_pointer(this->__end_), |
| 1685 | _VSTD::move(__x)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1686 | ++this->__end_; |
| 1687 | } |
| 1688 | else |
| 1689 | { |
| 1690 | __move_range(__p, this->__end_, __p + 1); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1691 | *__p = _VSTD::move(__x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1692 | } |
| 1693 | } |
| 1694 | else |
| 1695 | { |
| 1696 | allocator_type& __a = this->__alloc(); |
| 1697 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1698 | __v.push_back(_VSTD::move(__x)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1699 | __p = __swap_out_circular_buffer(__v, __p); |
| 1700 | } |
| 1701 | return __make_iter(__p); |
| 1702 | } |
| 1703 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1704 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1705 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1706 | template <class _Tp, class _Allocator> |
| 1707 | template <class... _Args> |
| 1708 | typename vector<_Tp, _Allocator>::iterator |
| 1709 | vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) |
| 1710 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1711 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1712 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, |
| 1713 | "vector::emplace(iterator, x) called with an iterator not" |
| 1714 | " referring to this vector"); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1715 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1716 | pointer __p = this->__begin_ + (__position - begin()); |
| 1717 | if (this->__end_ < this->__end_cap()) |
| 1718 | { |
| 1719 | if (__p == this->__end_) |
| 1720 | { |
| 1721 | __alloc_traits::construct(this->__alloc(), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1722 | _VSTD::__to_raw_pointer(this->__end_), |
| 1723 | _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1724 | ++this->__end_; |
| 1725 | } |
| 1726 | else |
| 1727 | { |
Howard Hinnant | a58402a | 2012-07-08 23:23:04 +0000 | [diff] [blame] | 1728 | value_type __tmp(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1729 | __move_range(__p, this->__end_, __p + 1); |
Howard Hinnant | a58402a | 2012-07-08 23:23:04 +0000 | [diff] [blame] | 1730 | *__p = _VSTD::move(__tmp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1731 | } |
| 1732 | } |
| 1733 | else |
| 1734 | { |
| 1735 | allocator_type& __a = this->__alloc(); |
| 1736 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1737 | __v.emplace_back(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1738 | __p = __swap_out_circular_buffer(__v, __p); |
| 1739 | } |
| 1740 | return __make_iter(__p); |
| 1741 | } |
| 1742 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1743 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1744 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1745 | |
| 1746 | template <class _Tp, class _Allocator> |
| 1747 | typename vector<_Tp, _Allocator>::iterator |
| 1748 | vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x) |
| 1749 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1750 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1751 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, |
| 1752 | "vector::insert(iterator, n, x) called with an iterator not" |
| 1753 | " referring to this vector"); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1754 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1755 | pointer __p = this->__begin_ + (__position - begin()); |
| 1756 | if (__n > 0) |
| 1757 | { |
| 1758 | if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_)) |
| 1759 | { |
| 1760 | size_type __old_n = __n; |
| 1761 | pointer __old_last = this->__end_; |
| 1762 | if (__n > static_cast<size_type>(this->__end_ - __p)) |
| 1763 | { |
| 1764 | size_type __cx = __n - (this->__end_ - __p); |
| 1765 | __construct_at_end(__cx, __x); |
| 1766 | __n -= __cx; |
| 1767 | } |
| 1768 | if (__n > 0) |
| 1769 | { |
| 1770 | __move_range(__p, __old_last, __p + __old_n); |
| 1771 | const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); |
| 1772 | if (__p <= __xr && __xr < this->__end_) |
| 1773 | __xr += __old_n; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1774 | _VSTD::fill_n(__p, __n, *__xr); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1775 | } |
| 1776 | } |
| 1777 | else |
| 1778 | { |
| 1779 | allocator_type& __a = this->__alloc(); |
| 1780 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); |
| 1781 | __v.__construct_at_end(__n, __x); |
| 1782 | __p = __swap_out_circular_buffer(__v, __p); |
| 1783 | } |
| 1784 | } |
| 1785 | return __make_iter(__p); |
| 1786 | } |
| 1787 | |
| 1788 | template <class _Tp, class _Allocator> |
| 1789 | template <class _InputIterator> |
| 1790 | typename enable_if |
| 1791 | < |
| 1792 | __is_input_iterator <_InputIterator>::value && |
Howard Hinnant | 742fecb | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 1793 | !__is_forward_iterator<_InputIterator>::value && |
| 1794 | is_constructible< |
| 1795 | _Tp, |
| 1796 | typename iterator_traits<_InputIterator>::reference>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1797 | typename vector<_Tp, _Allocator>::iterator |
| 1798 | >::type |
| 1799 | vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) |
| 1800 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1801 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1802 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, |
| 1803 | "vector::insert(iterator, range) called with an iterator not" |
| 1804 | " referring to this vector"); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1805 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1806 | difference_type __off = __position - begin(); |
| 1807 | pointer __p = this->__begin_ + __off; |
| 1808 | allocator_type& __a = this->__alloc(); |
| 1809 | pointer __old_last = this->__end_; |
| 1810 | for (; this->__end_ != this->__end_cap() && __first != __last; ++__first) |
| 1811 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1812 | __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1813 | *__first); |
| 1814 | ++this->__end_; |
| 1815 | } |
| 1816 | __split_buffer<value_type, allocator_type&> __v(__a); |
| 1817 | if (__first != __last) |
| 1818 | { |
| 1819 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1820 | try |
| 1821 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1822 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1823 | __v.__construct_at_end(__first, __last); |
| 1824 | difference_type __old_size = __old_last - this->__begin_; |
| 1825 | difference_type __old_p = __p - this->__begin_; |
| 1826 | reserve(__recommend(size() + __v.size())); |
| 1827 | __p = this->__begin_ + __old_p; |
| 1828 | __old_last = this->__begin_ + __old_size; |
| 1829 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1830 | } |
| 1831 | catch (...) |
| 1832 | { |
| 1833 | erase(__make_iter(__old_last), end()); |
| 1834 | throw; |
| 1835 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1836 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1837 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1838 | __p = _VSTD::rotate(__p, __old_last, this->__end_); |
Howard Hinnant | 0442b12 | 2011-09-16 18:41:29 +0000 | [diff] [blame] | 1839 | insert(__make_iter(__p), make_move_iterator(__v.begin()), |
| 1840 | make_move_iterator(__v.end())); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1841 | return begin() + __off; |
| 1842 | } |
| 1843 | |
| 1844 | template <class _Tp, class _Allocator> |
| 1845 | template <class _ForwardIterator> |
| 1846 | typename enable_if |
| 1847 | < |
Howard Hinnant | 742fecb | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 1848 | __is_forward_iterator<_ForwardIterator>::value && |
| 1849 | is_constructible< |
| 1850 | _Tp, |
| 1851 | typename iterator_traits<_ForwardIterator>::reference>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1852 | typename vector<_Tp, _Allocator>::iterator |
| 1853 | >::type |
| 1854 | vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) |
| 1855 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1856 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1857 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, |
| 1858 | "vector::insert(iterator, range) called with an iterator not" |
| 1859 | " referring to this vector"); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1860 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1861 | pointer __p = this->__begin_ + (__position - begin()); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1862 | difference_type __n = _VSTD::distance(__first, __last); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1863 | if (__n > 0) |
| 1864 | { |
| 1865 | if (__n <= this->__end_cap() - this->__end_) |
| 1866 | { |
| 1867 | size_type __old_n = __n; |
| 1868 | pointer __old_last = this->__end_; |
| 1869 | _ForwardIterator __m = __last; |
| 1870 | difference_type __dx = this->__end_ - __p; |
| 1871 | if (__n > __dx) |
| 1872 | { |
| 1873 | __m = __first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1874 | _VSTD::advance(__m, this->__end_ - __p); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1875 | __construct_at_end(__m, __last); |
| 1876 | __n = __dx; |
| 1877 | } |
| 1878 | if (__n > 0) |
| 1879 | { |
| 1880 | __move_range(__p, __old_last, __p + __old_n); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1881 | _VSTD::copy(__first, __m, __p); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1882 | } |
| 1883 | } |
| 1884 | else |
| 1885 | { |
| 1886 | allocator_type& __a = this->__alloc(); |
| 1887 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); |
| 1888 | __v.__construct_at_end(__first, __last); |
| 1889 | __p = __swap_out_circular_buffer(__v, __p); |
| 1890 | } |
| 1891 | } |
| 1892 | return __make_iter(__p); |
| 1893 | } |
| 1894 | |
| 1895 | template <class _Tp, class _Allocator> |
| 1896 | void |
| 1897 | vector<_Tp, _Allocator>::resize(size_type __sz) |
| 1898 | { |
| 1899 | size_type __cs = size(); |
| 1900 | if (__cs < __sz) |
| 1901 | this->__append(__sz - __cs); |
| 1902 | else if (__cs > __sz) |
| 1903 | this->__destruct_at_end(this->__begin_ + __sz); |
| 1904 | } |
| 1905 | |
| 1906 | template <class _Tp, class _Allocator> |
| 1907 | void |
| 1908 | vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x) |
| 1909 | { |
| 1910 | size_type __cs = size(); |
| 1911 | if (__cs < __sz) |
| 1912 | this->__append(__sz - __cs, __x); |
| 1913 | else if (__cs > __sz) |
| 1914 | this->__destruct_at_end(this->__begin_ + __sz); |
| 1915 | } |
| 1916 | |
| 1917 | template <class _Tp, class _Allocator> |
| 1918 | void |
| 1919 | vector<_Tp, _Allocator>::swap(vector& __x) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1920 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
| 1921 | __is_nothrow_swappable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1922 | { |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1923 | _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value || |
| 1924 | this->__alloc() == __x.__alloc(), |
| 1925 | "vector::swap: Either propagate_on_container_swap must be true" |
| 1926 | " or the allocators must compare equal"); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1927 | _VSTD::swap(this->__begin_, __x.__begin_); |
| 1928 | _VSTD::swap(this->__end_, __x.__end_); |
| 1929 | _VSTD::swap(this->__end_cap(), __x.__end_cap()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1930 | __base::__swap_alloc(this->__alloc(), __x.__alloc()); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1931 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1932 | __get_db()->swap(this, &__x); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1933 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1934 | } |
| 1935 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1936 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1937 | bool |
| 1938 | vector<_Tp, _Allocator>::__invariants() const |
| 1939 | { |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 1940 | if (this->__begin_ == nullptr) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1941 | { |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 1942 | if (this->__end_ != nullptr || this->__end_cap() != nullptr) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1943 | return false; |
| 1944 | } |
| 1945 | else |
| 1946 | { |
| 1947 | if (this->__begin_ > this->__end_) |
| 1948 | return false; |
| 1949 | if (this->__begin_ == this->__end_cap()) |
| 1950 | return false; |
| 1951 | if (this->__end_ > this->__end_cap()) |
| 1952 | return false; |
| 1953 | } |
| 1954 | return true; |
| 1955 | } |
| 1956 | |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1957 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1958 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1959 | template <class _Tp, class _Allocator> |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1960 | bool |
| 1961 | vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const |
| 1962 | { |
| 1963 | return this->__begin_ <= __i->base() && __i->base() < this->__end_; |
| 1964 | } |
| 1965 | |
| 1966 | template <class _Tp, class _Allocator> |
| 1967 | bool |
| 1968 | vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const |
| 1969 | { |
| 1970 | return this->__begin_ < __i->base() && __i->base() <= this->__end_; |
| 1971 | } |
| 1972 | |
| 1973 | template <class _Tp, class _Allocator> |
| 1974 | bool |
| 1975 | vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const |
| 1976 | { |
| 1977 | const_pointer __p = __i->base() + __n; |
| 1978 | return this->__begin_ <= __p && __p <= this->__end_; |
| 1979 | } |
| 1980 | |
| 1981 | template <class _Tp, class _Allocator> |
| 1982 | bool |
| 1983 | vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const |
| 1984 | { |
| 1985 | const_pointer __p = __i->base() + __n; |
| 1986 | return this->__begin_ <= __p && __p < this->__end_; |
| 1987 | } |
| 1988 | |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1989 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1990 | |
| 1991 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1992 | _LIBCPP_INLINE_VISIBILITY inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1993 | void |
| 1994 | vector<_Tp, _Allocator>::__invalidate_all_iterators() |
| 1995 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1996 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1997 | __get_db()->__invalidate_all(this); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1998 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | // vector<bool> |
| 2002 | |
| 2003 | template <class _Allocator> class vector<bool, _Allocator>; |
| 2004 | |
| 2005 | template <class _Allocator> struct hash<vector<bool, _Allocator> >; |
| 2006 | |
| 2007 | template <class _Allocator> |
Howard Hinnant | f03c3b4 | 2011-07-02 20:33:23 +0000 | [diff] [blame] | 2008 | struct __has_storage_type<vector<bool, _Allocator> > |
| 2009 | { |
| 2010 | static const bool value = true; |
| 2011 | }; |
| 2012 | |
| 2013 | template <class _Allocator> |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 2014 | class _LIBCPP_TYPE_VIS vector<bool, _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2015 | : private __vector_base_common<true> |
| 2016 | { |
| 2017 | public: |
| 2018 | typedef vector __self; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2019 | typedef bool value_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2020 | typedef _Allocator allocator_type; |
| 2021 | typedef allocator_traits<allocator_type> __alloc_traits; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2022 | typedef typename __alloc_traits::size_type size_type; |
| 2023 | typedef typename __alloc_traits::difference_type difference_type; |
Howard Hinnant | f867f63 | 2012-05-07 16:50:38 +0000 | [diff] [blame] | 2024 | typedef size_type __storage_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2025 | typedef __bit_iterator<vector, false> pointer; |
| 2026 | typedef __bit_iterator<vector, true> const_pointer; |
| 2027 | #ifdef _LIBCPP_DEBUG |
| 2028 | typedef __debug_iter<vector, pointer> iterator; |
| 2029 | typedef __debug_iter<vector, const_pointer> const_iterator; |
| 2030 | |
| 2031 | friend class __debug_iter<vector, pointer>; |
| 2032 | friend class __debug_iter<vector, const_pointer>; |
| 2033 | |
| 2034 | pair<iterator*, const_iterator*> __iterator_list_; |
| 2035 | |
| 2036 | _LIBCPP_INLINE_VISIBILITY iterator*& __get_iterator_list(iterator*) {return __iterator_list_.first;} |
| 2037 | _LIBCPP_INLINE_VISIBILITY const_iterator*& __get_iterator_list(const_iterator*) {return __iterator_list_.second;} |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2038 | #else // _LIBCPP_DEBUG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2039 | typedef pointer iterator; |
| 2040 | typedef const_pointer const_iterator; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2041 | #endif // _LIBCPP_DEBUG |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2042 | typedef _VSTD::reverse_iterator<iterator> reverse_iterator; |
| 2043 | typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2044 | |
| 2045 | private: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2046 | typedef typename __alloc_traits::template |
| 2047 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 2048 | rebind_alloc<__storage_type> |
| 2049 | #else |
| 2050 | rebind_alloc<__storage_type>::other |
| 2051 | #endif |
| 2052 | __storage_allocator; |
| 2053 | typedef allocator_traits<__storage_allocator> __storage_traits; |
| 2054 | typedef typename __storage_traits::pointer __storage_pointer; |
| 2055 | typedef typename __storage_traits::const_pointer __const_storage_pointer; |
| 2056 | |
| 2057 | __storage_pointer __begin_; |
| 2058 | size_type __size_; |
| 2059 | __compressed_pair<size_type, __storage_allocator> __cap_alloc_; |
Howard Hinnant | 2bf1c08 | 2011-07-09 15:50:42 +0000 | [diff] [blame] | 2060 | public: |
Howard Hinnant | f03c3b4 | 2011-07-02 20:33:23 +0000 | [diff] [blame] | 2061 | typedef __bit_reference<vector> reference; |
| 2062 | typedef __bit_const_reference<vector> const_reference; |
Howard Hinnant | 2bf1c08 | 2011-07-09 15:50:42 +0000 | [diff] [blame] | 2063 | private: |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2064 | _LIBCPP_INLINE_VISIBILITY |
| 2065 | size_type& __cap() _NOEXCEPT |
| 2066 | {return __cap_alloc_.first();} |
| 2067 | _LIBCPP_INLINE_VISIBILITY |
| 2068 | const size_type& __cap() const _NOEXCEPT |
| 2069 | {return __cap_alloc_.first();} |
| 2070 | _LIBCPP_INLINE_VISIBILITY |
| 2071 | __storage_allocator& __alloc() _NOEXCEPT |
| 2072 | {return __cap_alloc_.second();} |
| 2073 | _LIBCPP_INLINE_VISIBILITY |
| 2074 | const __storage_allocator& __alloc() const _NOEXCEPT |
| 2075 | {return __cap_alloc_.second();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2076 | |
| 2077 | static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); |
| 2078 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2079 | _LIBCPP_INLINE_VISIBILITY |
| 2080 | static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2081 | {return __n * __bits_per_word;} |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2082 | _LIBCPP_INLINE_VISIBILITY |
| 2083 | static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2084 | {return (__n - 1) / __bits_per_word + 1;} |
| 2085 | |
| 2086 | public: |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2087 | _LIBCPP_INLINE_VISIBILITY |
| 2088 | vector() |
| 2089 | _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 2090 | _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2091 | ~vector(); |
| 2092 | explicit vector(size_type __n); |
| 2093 | vector(size_type __n, const value_type& __v); |
| 2094 | vector(size_type __n, const value_type& __v, const allocator_type& __a); |
| 2095 | template <class _InputIterator> |
| 2096 | vector(_InputIterator __first, _InputIterator __last, |
| 2097 | typename enable_if<__is_input_iterator <_InputIterator>::value && |
| 2098 | !__is_forward_iterator<_InputIterator>::value>::type* = 0); |
| 2099 | template <class _InputIterator> |
| 2100 | vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, |
| 2101 | typename enable_if<__is_input_iterator <_InputIterator>::value && |
| 2102 | !__is_forward_iterator<_InputIterator>::value>::type* = 0); |
| 2103 | template <class _ForwardIterator> |
| 2104 | vector(_ForwardIterator __first, _ForwardIterator __last, |
| 2105 | typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0); |
| 2106 | template <class _ForwardIterator> |
| 2107 | vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, |
| 2108 | typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0); |
| 2109 | |
| 2110 | vector(const vector& __v); |
| 2111 | vector(const vector& __v, const allocator_type& __a); |
| 2112 | vector& operator=(const vector& __v); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2113 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2114 | vector(initializer_list<value_type> __il); |
| 2115 | vector(initializer_list<value_type> __il, const allocator_type& __a); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2116 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2117 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2118 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2119 | _LIBCPP_INLINE_VISIBILITY |
| 2120 | vector(vector&& __v) |
| 2121 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2122 | vector(vector&& __v, const allocator_type& __a); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2123 | _LIBCPP_INLINE_VISIBILITY |
| 2124 | vector& operator=(vector&& __v) |
| 2125 | _NOEXCEPT_( |
| 2126 | __alloc_traits::propagate_on_container_move_assignment::value && |
| 2127 | is_nothrow_move_assignable<allocator_type>::value); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2128 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2129 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2130 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2131 | vector& operator=(initializer_list<value_type> __il) |
| 2132 | {assign(__il.begin(), __il.end()); return *this;} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2133 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2134 | |
| 2135 | template <class _InputIterator> |
| 2136 | typename enable_if |
| 2137 | < |
| 2138 | __is_input_iterator<_InputIterator>::value && |
| 2139 | !__is_forward_iterator<_InputIterator>::value, |
| 2140 | void |
| 2141 | >::type |
| 2142 | assign(_InputIterator __first, _InputIterator __last); |
| 2143 | template <class _ForwardIterator> |
| 2144 | typename enable_if |
| 2145 | < |
| 2146 | __is_forward_iterator<_ForwardIterator>::value, |
| 2147 | void |
| 2148 | >::type |
| 2149 | assign(_ForwardIterator __first, _ForwardIterator __last); |
| 2150 | |
| 2151 | void assign(size_type __n, const value_type& __x); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2152 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2153 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2154 | void assign(initializer_list<value_type> __il) |
| 2155 | {assign(__il.begin(), __il.end());} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2156 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2157 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2158 | _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2159 | {return allocator_type(this->__alloc());} |
| 2160 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2161 | size_type max_size() const _NOEXCEPT; |
| 2162 | _LIBCPP_INLINE_VISIBILITY |
| 2163 | size_type capacity() const _NOEXCEPT |
| 2164 | {return __internal_cap_to_external(__cap());} |
| 2165 | _LIBCPP_INLINE_VISIBILITY |
| 2166 | size_type size() const _NOEXCEPT |
| 2167 | {return __size_;} |
| 2168 | _LIBCPP_INLINE_VISIBILITY |
| 2169 | bool empty() const _NOEXCEPT |
| 2170 | {return __size_ == 0;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2171 | void reserve(size_type __n); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2172 | void shrink_to_fit() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2173 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2174 | _LIBCPP_INLINE_VISIBILITY |
| 2175 | iterator begin() _NOEXCEPT |
| 2176 | {return __make_iter(0);} |
| 2177 | _LIBCPP_INLINE_VISIBILITY |
| 2178 | const_iterator begin() const _NOEXCEPT |
| 2179 | {return __make_iter(0);} |
| 2180 | _LIBCPP_INLINE_VISIBILITY |
| 2181 | iterator end() _NOEXCEPT |
| 2182 | {return __make_iter(__size_);} |
| 2183 | _LIBCPP_INLINE_VISIBILITY |
| 2184 | const_iterator end() const _NOEXCEPT |
| 2185 | {return __make_iter(__size_);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2186 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2187 | _LIBCPP_INLINE_VISIBILITY |
| 2188 | reverse_iterator rbegin() _NOEXCEPT |
| 2189 | {return reverse_iterator(end());} |
| 2190 | _LIBCPP_INLINE_VISIBILITY |
| 2191 | const_reverse_iterator rbegin() const _NOEXCEPT |
| 2192 | {return const_reverse_iterator(end());} |
| 2193 | _LIBCPP_INLINE_VISIBILITY |
| 2194 | reverse_iterator rend() _NOEXCEPT |
| 2195 | {return reverse_iterator(begin());} |
| 2196 | _LIBCPP_INLINE_VISIBILITY |
| 2197 | const_reverse_iterator rend() const _NOEXCEPT |
| 2198 | {return const_reverse_iterator(begin());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2199 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2200 | _LIBCPP_INLINE_VISIBILITY |
| 2201 | const_iterator cbegin() const _NOEXCEPT |
| 2202 | {return __make_iter(0);} |
| 2203 | _LIBCPP_INLINE_VISIBILITY |
| 2204 | const_iterator cend() const _NOEXCEPT |
| 2205 | {return __make_iter(__size_);} |
| 2206 | _LIBCPP_INLINE_VISIBILITY |
| 2207 | const_reverse_iterator crbegin() const _NOEXCEPT |
| 2208 | {return rbegin();} |
| 2209 | _LIBCPP_INLINE_VISIBILITY |
| 2210 | const_reverse_iterator crend() const _NOEXCEPT |
| 2211 | {return rend();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2212 | |
| 2213 | _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);} |
| 2214 | _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);} |
| 2215 | reference at(size_type __n); |
| 2216 | const_reference at(size_type __n) const; |
| 2217 | |
| 2218 | _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);} |
| 2219 | _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);} |
| 2220 | _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);} |
| 2221 | _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);} |
| 2222 | |
| 2223 | void push_back(const value_type& __x); |
| 2224 | _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;} |
| 2225 | |
| 2226 | iterator insert(const_iterator __position, const value_type& __x); |
| 2227 | iterator insert(const_iterator __position, size_type __n, const value_type& __x); |
| 2228 | iterator insert(const_iterator __position, size_type __n, const_reference __x); |
| 2229 | template <class _InputIterator> |
| 2230 | typename enable_if |
| 2231 | < |
| 2232 | __is_input_iterator <_InputIterator>::value && |
| 2233 | !__is_forward_iterator<_InputIterator>::value, |
| 2234 | iterator |
| 2235 | >::type |
| 2236 | insert(const_iterator __position, _InputIterator __first, _InputIterator __last); |
| 2237 | template <class _ForwardIterator> |
| 2238 | typename enable_if |
| 2239 | < |
| 2240 | __is_forward_iterator<_ForwardIterator>::value, |
| 2241 | iterator |
| 2242 | >::type |
| 2243 | insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2244 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2245 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2246 | iterator insert(const_iterator __position, initializer_list<value_type> __il) |
| 2247 | {return insert(__position, __il.begin(), __il.end());} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2248 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2249 | |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 2250 | _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2251 | iterator erase(const_iterator __first, const_iterator __last); |
| 2252 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2253 | _LIBCPP_INLINE_VISIBILITY |
| 2254 | void clear() _NOEXCEPT {__size_ = 0;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2255 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2256 | void swap(vector&) |
| 2257 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
| 2258 | __is_nothrow_swappable<allocator_type>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2259 | |
| 2260 | void resize(size_type __sz, value_type __x = false); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2261 | void flip() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2262 | |
| 2263 | bool __invariants() const; |
| 2264 | |
| 2265 | private: |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 2266 | _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2267 | void allocate(size_type __n); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2268 | void deallocate() _NOEXCEPT; |
| 2269 | _LIBCPP_INLINE_VISIBILITY |
| 2270 | static size_type __align(size_type __new_size) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2271 | {return __new_size + (__bits_per_word-1) & ~(__bits_per_word-1);}; |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 2272 | _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; |
| 2273 | _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2274 | template <class _ForwardIterator> |
| 2275 | typename enable_if |
| 2276 | < |
| 2277 | __is_forward_iterator<_ForwardIterator>::value, |
| 2278 | void |
| 2279 | >::type |
| 2280 | __construct_at_end(_ForwardIterator __first, _ForwardIterator __last); |
| 2281 | void __append(size_type __n, const_reference __x); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2282 | _LIBCPP_INLINE_VISIBILITY |
| 2283 | reference __make_ref(size_type __pos) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2284 | {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2285 | _LIBCPP_INLINE_VISIBILITY |
| 2286 | const_reference __make_ref(size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2287 | {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} |
| 2288 | #ifdef _LIBCPP_DEBUG |
| 2289 | _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_type __pos) |
| 2290 | {return iterator(this, pointer(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word)));} |
| 2291 | _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_type __pos) const |
| 2292 | {return const_iterator(this, const_pointer(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word)));} |
| 2293 | _LIBCPP_INLINE_VISIBILITY iterator __const_iterator_cast(const_iterator __p) |
| 2294 | {return iterator(this, pointer(const_cast<__storage_pointer>(__p.base().__seg_), __p.base().__ctz_));} |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2295 | #else // _LIBCPP_DEBUG |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2296 | _LIBCPP_INLINE_VISIBILITY |
| 2297 | iterator __make_iter(size_type __pos) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2298 | {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));} |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2299 | _LIBCPP_INLINE_VISIBILITY |
| 2300 | const_iterator __make_iter(size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2301 | {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));} |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2302 | _LIBCPP_INLINE_VISIBILITY |
| 2303 | iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2304 | {return begin() + (__p - cbegin());} |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2305 | #endif // _LIBCPP_DEBUG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2306 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2307 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2308 | void __copy_assign_alloc(const vector& __v) |
| 2309 | {__copy_assign_alloc(__v, integral_constant<bool, |
| 2310 | __storage_traits::propagate_on_container_copy_assignment::value>());} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2311 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2312 | void __copy_assign_alloc(const vector& __c, true_type) |
| 2313 | { |
| 2314 | if (__alloc() != __c.__alloc()) |
| 2315 | deallocate(); |
| 2316 | __alloc() = __c.__alloc(); |
| 2317 | } |
| 2318 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2319 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2320 | void __copy_assign_alloc(const vector&, false_type) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2321 | {} |
| 2322 | |
| 2323 | void __move_assign(vector& __c, false_type); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2324 | void __move_assign(vector& __c, true_type) |
| 2325 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2326 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2327 | void __move_assign_alloc(vector& __c) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2328 | _NOEXCEPT_( |
| 2329 | !__storage_traits::propagate_on_container_move_assignment::value || |
| 2330 | is_nothrow_move_assignable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2331 | {__move_assign_alloc(__c, integral_constant<bool, |
| 2332 | __storage_traits::propagate_on_container_move_assignment::value>());} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2333 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9cbee43 | 2011-09-02 20:42:31 +0000 | [diff] [blame] | 2334 | void __move_assign_alloc(vector& __c, true_type) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2335 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2336 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2337 | __alloc() = _VSTD::move(__c.__alloc()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2338 | } |
| 2339 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2340 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2341 | void __move_assign_alloc(vector&, false_type) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2342 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2343 | {} |
| 2344 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2345 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2346 | static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2347 | _NOEXCEPT_( |
| 2348 | !__storage_traits::propagate_on_container_swap::value || |
| 2349 | __is_nothrow_swappable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2350 | {__swap_alloc(__x, __y, integral_constant<bool, |
| 2351 | __storage_traits::propagate_on_container_swap::value>());} |
| 2352 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2353 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2354 | static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, true_type) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2355 | _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2356 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2357 | using _VSTD::swap; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2358 | swap(__x, __y); |
| 2359 | } |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2360 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2361 | static void __swap_alloc(__storage_allocator&, __storage_allocator&, false_type) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2362 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2363 | {} |
| 2364 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2365 | size_t __hash_code() const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2366 | |
| 2367 | friend class __bit_reference<vector>; |
| 2368 | friend class __bit_const_reference<vector>; |
| 2369 | friend class __bit_iterator<vector, false>; |
| 2370 | friend class __bit_iterator<vector, true>; |
Howard Hinnant | 4ae952a | 2012-08-17 17:10:18 +0000 | [diff] [blame] | 2371 | friend struct __bit_array<vector>; |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 2372 | friend struct _LIBCPP_TYPE_VIS hash<vector>; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2373 | }; |
| 2374 | |
| 2375 | template <class _Allocator> |
| 2376 | #ifndef _LIBCPP_DEBUG |
| 2377 | _LIBCPP_INLINE_VISIBILITY inline |
| 2378 | #endif |
| 2379 | void |
| 2380 | vector<bool, _Allocator>::__invalidate_all_iterators() |
| 2381 | { |
| 2382 | #ifdef _LIBCPP_DEBUG |
| 2383 | iterator::__remove_all(this); |
| 2384 | const_iterator::__remove_all(this); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2385 | #endif // _LIBCPP_DEBUG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2386 | } |
| 2387 | |
| 2388 | // Allocate space for __n objects |
| 2389 | // throws length_error if __n > max_size() |
| 2390 | // throws (probably bad_alloc) if memory run out |
| 2391 | // Precondition: __begin_ == __end_ == __cap() == 0 |
| 2392 | // Precondition: __n > 0 |
| 2393 | // Postcondition: capacity() == __n |
| 2394 | // Postcondition: size() == 0 |
| 2395 | template <class _Allocator> |
| 2396 | void |
| 2397 | vector<bool, _Allocator>::allocate(size_type __n) |
| 2398 | { |
| 2399 | if (__n > max_size()) |
| 2400 | this->__throw_length_error(); |
| 2401 | __n = __external_cap_to_internal(__n); |
| 2402 | this->__begin_ = __storage_traits::allocate(this->__alloc(), __n); |
| 2403 | this->__size_ = 0; |
| 2404 | this->__cap() = __n; |
| 2405 | } |
| 2406 | |
| 2407 | template <class _Allocator> |
| 2408 | void |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2409 | vector<bool, _Allocator>::deallocate() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2410 | { |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2411 | if (this->__begin_ != nullptr) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2412 | { |
| 2413 | __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap()); |
| 2414 | __invalidate_all_iterators(); |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2415 | this->__begin_ = nullptr; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2416 | this->__size_ = this->__cap() = 0; |
| 2417 | } |
| 2418 | } |
| 2419 | |
| 2420 | template <class _Allocator> |
| 2421 | typename vector<bool, _Allocator>::size_type |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2422 | vector<bool, _Allocator>::max_size() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2423 | { |
| 2424 | size_type __amax = __storage_traits::max_size(__alloc()); |
| 2425 | size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always |
| 2426 | if (__nmax / __bits_per_word <= __amax) |
| 2427 | return __nmax; |
| 2428 | return __internal_cap_to_external(__amax); |
| 2429 | } |
| 2430 | |
| 2431 | // Precondition: __new_size > capacity() |
| 2432 | template <class _Allocator> |
| 2433 | _LIBCPP_INLINE_VISIBILITY inline |
| 2434 | typename vector<bool, _Allocator>::size_type |
| 2435 | vector<bool, _Allocator>::__recommend(size_type __new_size) const |
| 2436 | { |
| 2437 | const size_type __ms = max_size(); |
| 2438 | if (__new_size > __ms) |
| 2439 | this->__throw_length_error(); |
| 2440 | const size_type __cap = capacity(); |
| 2441 | if (__cap >= __ms / 2) |
| 2442 | return __ms; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2443 | return _VSTD::max(2*__cap, __align(__new_size)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2444 | } |
| 2445 | |
| 2446 | // Default constructs __n objects starting at __end_ |
| 2447 | // Precondition: __n > 0 |
| 2448 | // Precondition: size() + __n <= capacity() |
| 2449 | // Postcondition: size() == size() + __n |
| 2450 | template <class _Allocator> |
| 2451 | _LIBCPP_INLINE_VISIBILITY inline |
| 2452 | void |
| 2453 | vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x) |
| 2454 | { |
| 2455 | size_type __old_size = this->__size_; |
| 2456 | this->__size_ += __n; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2457 | _VSTD::fill_n(__make_iter(__old_size), __n, __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2458 | } |
| 2459 | |
| 2460 | template <class _Allocator> |
| 2461 | template <class _ForwardIterator> |
| 2462 | typename enable_if |
| 2463 | < |
| 2464 | __is_forward_iterator<_ForwardIterator>::value, |
| 2465 | void |
| 2466 | >::type |
| 2467 | vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last) |
| 2468 | { |
| 2469 | size_type __old_size = this->__size_; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2470 | this->__size_ += _VSTD::distance(__first, __last); |
| 2471 | _VSTD::copy(__first, __last, __make_iter(__old_size)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2472 | } |
| 2473 | |
| 2474 | template <class _Allocator> |
| 2475 | _LIBCPP_INLINE_VISIBILITY inline |
| 2476 | vector<bool, _Allocator>::vector() |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2477 | _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2478 | : __begin_(nullptr), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2479 | __size_(0), |
| 2480 | __cap_alloc_(0) |
| 2481 | { |
| 2482 | } |
| 2483 | |
| 2484 | template <class _Allocator> |
| 2485 | _LIBCPP_INLINE_VISIBILITY inline |
| 2486 | vector<bool, _Allocator>::vector(const allocator_type& __a) |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2487 | : __begin_(nullptr), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2488 | __size_(0), |
| 2489 | __cap_alloc_(0, static_cast<__storage_allocator>(__a)) |
| 2490 | { |
| 2491 | } |
| 2492 | |
| 2493 | template <class _Allocator> |
| 2494 | vector<bool, _Allocator>::vector(size_type __n) |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2495 | : __begin_(nullptr), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2496 | __size_(0), |
| 2497 | __cap_alloc_(0) |
| 2498 | { |
| 2499 | if (__n > 0) |
| 2500 | { |
| 2501 | allocate(__n); |
| 2502 | __construct_at_end(__n, false); |
| 2503 | } |
| 2504 | } |
| 2505 | |
| 2506 | template <class _Allocator> |
| 2507 | vector<bool, _Allocator>::vector(size_type __n, const value_type& __x) |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2508 | : __begin_(nullptr), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2509 | __size_(0), |
| 2510 | __cap_alloc_(0) |
| 2511 | { |
| 2512 | if (__n > 0) |
| 2513 | { |
| 2514 | allocate(__n); |
| 2515 | __construct_at_end(__n, __x); |
| 2516 | } |
| 2517 | } |
| 2518 | |
| 2519 | template <class _Allocator> |
| 2520 | vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a) |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2521 | : __begin_(nullptr), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2522 | __size_(0), |
| 2523 | __cap_alloc_(0, static_cast<__storage_allocator>(__a)) |
| 2524 | { |
| 2525 | if (__n > 0) |
| 2526 | { |
| 2527 | allocate(__n); |
| 2528 | __construct_at_end(__n, __x); |
| 2529 | } |
| 2530 | } |
| 2531 | |
| 2532 | template <class _Allocator> |
| 2533 | template <class _InputIterator> |
| 2534 | vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, |
| 2535 | typename enable_if<__is_input_iterator <_InputIterator>::value && |
| 2536 | !__is_forward_iterator<_InputIterator>::value>::type*) |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2537 | : __begin_(nullptr), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2538 | __size_(0), |
| 2539 | __cap_alloc_(0) |
| 2540 | { |
| 2541 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2542 | try |
| 2543 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2544 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2545 | for (; __first != __last; ++__first) |
| 2546 | push_back(*__first); |
| 2547 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2548 | } |
| 2549 | catch (...) |
| 2550 | { |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2551 | if (__begin_ != nullptr) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2552 | __storage_traits::deallocate(__alloc(), __begin_, __cap()); |
| 2553 | __invalidate_all_iterators(); |
| 2554 | throw; |
| 2555 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2556 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | template <class _Allocator> |
| 2560 | template <class _InputIterator> |
| 2561 | vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, |
| 2562 | typename enable_if<__is_input_iterator <_InputIterator>::value && |
| 2563 | !__is_forward_iterator<_InputIterator>::value>::type*) |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2564 | : __begin_(nullptr), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2565 | __size_(0), |
| 2566 | __cap_alloc_(0, static_cast<__storage_allocator>(__a)) |
| 2567 | { |
| 2568 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2569 | try |
| 2570 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2571 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2572 | for (; __first != __last; ++__first) |
| 2573 | push_back(*__first); |
| 2574 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2575 | } |
| 2576 | catch (...) |
| 2577 | { |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2578 | if (__begin_ != nullptr) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2579 | __storage_traits::deallocate(__alloc(), __begin_, __cap()); |
| 2580 | __invalidate_all_iterators(); |
| 2581 | throw; |
| 2582 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2583 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2584 | } |
| 2585 | |
| 2586 | template <class _Allocator> |
| 2587 | template <class _ForwardIterator> |
| 2588 | vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, |
| 2589 | typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*) |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2590 | : __begin_(nullptr), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2591 | __size_(0), |
| 2592 | __cap_alloc_(0) |
| 2593 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2594 | size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2595 | if (__n > 0) |
| 2596 | { |
| 2597 | allocate(__n); |
| 2598 | __construct_at_end(__first, __last); |
| 2599 | } |
| 2600 | } |
| 2601 | |
| 2602 | template <class _Allocator> |
| 2603 | template <class _ForwardIterator> |
| 2604 | vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, |
| 2605 | typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*) |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2606 | : __begin_(nullptr), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2607 | __size_(0), |
| 2608 | __cap_alloc_(0, static_cast<__storage_allocator>(__a)) |
| 2609 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2610 | size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2611 | if (__n > 0) |
| 2612 | { |
| 2613 | allocate(__n); |
| 2614 | __construct_at_end(__first, __last); |
| 2615 | } |
| 2616 | } |
| 2617 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2618 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 2619 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2620 | template <class _Allocator> |
| 2621 | vector<bool, _Allocator>::vector(initializer_list<value_type> __il) |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2622 | : __begin_(nullptr), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2623 | __size_(0), |
| 2624 | __cap_alloc_(0) |
| 2625 | { |
| 2626 | size_type __n = static_cast<size_type>(__il.size()); |
| 2627 | if (__n > 0) |
| 2628 | { |
| 2629 | allocate(__n); |
| 2630 | __construct_at_end(__il.begin(), __il.end()); |
| 2631 | } |
| 2632 | } |
| 2633 | |
| 2634 | template <class _Allocator> |
| 2635 | vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2636 | : __begin_(nullptr), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2637 | __size_(0), |
| 2638 | __cap_alloc_(0, static_cast<__storage_allocator>(__a)) |
| 2639 | { |
| 2640 | size_type __n = static_cast<size_type>(__il.size()); |
| 2641 | if (__n > 0) |
| 2642 | { |
| 2643 | allocate(__n); |
| 2644 | __construct_at_end(__il.begin(), __il.end()); |
| 2645 | } |
| 2646 | } |
| 2647 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2648 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 2649 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2650 | template <class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2651 | vector<bool, _Allocator>::~vector() |
| 2652 | { |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2653 | if (__begin_ != nullptr) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2654 | __storage_traits::deallocate(__alloc(), __begin_, __cap()); |
| 2655 | #ifdef _LIBCPP_DEBUG |
| 2656 | __invalidate_all_iterators(); |
| 2657 | #endif |
| 2658 | } |
| 2659 | |
| 2660 | template <class _Allocator> |
| 2661 | vector<bool, _Allocator>::vector(const vector& __v) |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2662 | : __begin_(nullptr), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2663 | __size_(0), |
| 2664 | __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc())) |
| 2665 | { |
| 2666 | if (__v.size() > 0) |
| 2667 | { |
| 2668 | allocate(__v.size()); |
| 2669 | __construct_at_end(__v.begin(), __v.end()); |
| 2670 | } |
| 2671 | } |
| 2672 | |
| 2673 | template <class _Allocator> |
| 2674 | vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a) |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2675 | : __begin_(nullptr), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2676 | __size_(0), |
| 2677 | __cap_alloc_(0, __a) |
| 2678 | { |
| 2679 | if (__v.size() > 0) |
| 2680 | { |
| 2681 | allocate(__v.size()); |
| 2682 | __construct_at_end(__v.begin(), __v.end()); |
| 2683 | } |
| 2684 | } |
| 2685 | |
| 2686 | template <class _Allocator> |
| 2687 | vector<bool, _Allocator>& |
| 2688 | vector<bool, _Allocator>::operator=(const vector& __v) |
| 2689 | { |
| 2690 | if (this != &__v) |
| 2691 | { |
| 2692 | __copy_assign_alloc(__v); |
| 2693 | if (__v.__size_) |
| 2694 | { |
| 2695 | if (__v.__size_ > capacity()) |
| 2696 | { |
| 2697 | deallocate(); |
| 2698 | allocate(__v.__size_); |
| 2699 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2700 | _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2701 | } |
| 2702 | __size_ = __v.__size_; |
| 2703 | } |
| 2704 | return *this; |
| 2705 | } |
| 2706 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2707 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 2708 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2709 | template <class _Allocator> |
| 2710 | _LIBCPP_INLINE_VISIBILITY inline |
| 2711 | vector<bool, _Allocator>::vector(vector&& __v) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2712 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2713 | : __begin_(__v.__begin_), |
| 2714 | __size_(__v.__size_), |
| 2715 | __cap_alloc_(__v.__cap_alloc_) |
| 2716 | { |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2717 | __v.__begin_ = nullptr; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2718 | __v.__size_ = 0; |
| 2719 | __v.__cap() = 0; |
| 2720 | } |
| 2721 | |
| 2722 | template <class _Allocator> |
| 2723 | vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a) |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2724 | : __begin_(nullptr), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2725 | __size_(0), |
| 2726 | __cap_alloc_(0, __a) |
| 2727 | { |
| 2728 | if (__a == allocator_type(__v.__alloc())) |
| 2729 | { |
| 2730 | this->__begin_ = __v.__begin_; |
| 2731 | this->__size_ = __v.__size_; |
| 2732 | this->__cap() = __v.__cap(); |
| 2733 | __v.__begin_ = nullptr; |
| 2734 | __v.__cap() = __v.__size_ = 0; |
| 2735 | } |
| 2736 | else if (__v.size() > 0) |
| 2737 | { |
| 2738 | allocate(__v.size()); |
| 2739 | __construct_at_end(__v.begin(), __v.end()); |
| 2740 | } |
| 2741 | } |
| 2742 | |
| 2743 | template <class _Allocator> |
| 2744 | _LIBCPP_INLINE_VISIBILITY inline |
| 2745 | vector<bool, _Allocator>& |
| 2746 | vector<bool, _Allocator>::operator=(vector&& __v) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2747 | _NOEXCEPT_( |
| 2748 | __alloc_traits::propagate_on_container_move_assignment::value && |
| 2749 | is_nothrow_move_assignable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2750 | { |
| 2751 | __move_assign(__v, integral_constant<bool, |
| 2752 | __storage_traits::propagate_on_container_move_assignment::value>()); |
Argyrios Kyrtzidis | 1dc6f7a | 2012-10-13 02:03:45 +0000 | [diff] [blame] | 2753 | return *this; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2754 | } |
| 2755 | |
| 2756 | template <class _Allocator> |
| 2757 | void |
| 2758 | vector<bool, _Allocator>::__move_assign(vector& __c, false_type) |
| 2759 | { |
| 2760 | if (__alloc() != __c.__alloc()) |
| 2761 | assign(__c.begin(), __c.end()); |
| 2762 | else |
| 2763 | __move_assign(__c, true_type()); |
| 2764 | } |
| 2765 | |
| 2766 | template <class _Allocator> |
| 2767 | void |
| 2768 | vector<bool, _Allocator>::__move_assign(vector& __c, true_type) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2769 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2770 | { |
| 2771 | deallocate(); |
| 2772 | this->__begin_ = __c.__begin_; |
| 2773 | this->__size_ = __c.__size_; |
| 2774 | this->__cap() = __c.__cap(); |
| 2775 | __move_assign_alloc(__c); |
| 2776 | __c.__begin_ = nullptr; |
| 2777 | __c.__cap() = __c.__size_ = 0; |
| 2778 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2779 | |
| 2780 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2781 | |
| 2782 | template <class _Allocator> |
| 2783 | void |
| 2784 | vector<bool, _Allocator>::assign(size_type __n, const value_type& __x) |
| 2785 | { |
| 2786 | __size_ = 0; |
| 2787 | if (__n > 0) |
| 2788 | { |
| 2789 | size_type __c = capacity(); |
| 2790 | if (__n <= __c) |
| 2791 | __size_ = __n; |
| 2792 | else |
| 2793 | { |
| 2794 | vector __v(__alloc()); |
| 2795 | __v.reserve(__recommend(__n)); |
| 2796 | __v.__size_ = __n; |
| 2797 | swap(__v); |
| 2798 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2799 | _VSTD::fill_n(begin(), __n, __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2800 | } |
| 2801 | } |
| 2802 | |
| 2803 | template <class _Allocator> |
| 2804 | template <class _InputIterator> |
| 2805 | typename enable_if |
| 2806 | < |
| 2807 | __is_input_iterator<_InputIterator>::value && |
| 2808 | !__is_forward_iterator<_InputIterator>::value, |
| 2809 | void |
| 2810 | >::type |
| 2811 | vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last) |
| 2812 | { |
| 2813 | clear(); |
| 2814 | for (; __first != __last; ++__first) |
| 2815 | push_back(*__first); |
| 2816 | } |
| 2817 | |
| 2818 | template <class _Allocator> |
| 2819 | template <class _ForwardIterator> |
| 2820 | typename enable_if |
| 2821 | < |
| 2822 | __is_forward_iterator<_ForwardIterator>::value, |
| 2823 | void |
| 2824 | >::type |
| 2825 | vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) |
| 2826 | { |
| 2827 | clear(); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2828 | difference_type __n = _VSTD::distance(__first, __last); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2829 | if (__n) |
| 2830 | { |
| 2831 | if (__n > capacity()) |
| 2832 | { |
| 2833 | deallocate(); |
| 2834 | allocate(__n); |
| 2835 | } |
| 2836 | __construct_at_end(__first, __last); |
| 2837 | } |
| 2838 | } |
| 2839 | |
| 2840 | template <class _Allocator> |
| 2841 | void |
| 2842 | vector<bool, _Allocator>::reserve(size_type __n) |
| 2843 | { |
| 2844 | if (__n > capacity()) |
| 2845 | { |
| 2846 | vector __v(this->__alloc()); |
| 2847 | __v.allocate(__n); |
| 2848 | __v.__construct_at_end(this->begin(), this->end()); |
| 2849 | swap(__v); |
| 2850 | __invalidate_all_iterators(); |
| 2851 | } |
| 2852 | } |
| 2853 | |
| 2854 | template <class _Allocator> |
| 2855 | void |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2856 | vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2857 | { |
| 2858 | if (__external_cap_to_internal(size()) > __cap()) |
| 2859 | { |
| 2860 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2861 | try |
| 2862 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2863 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2864 | vector(*this, allocator_type(__alloc())).swap(*this); |
| 2865 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2866 | } |
| 2867 | catch (...) |
| 2868 | { |
| 2869 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2870 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2871 | } |
| 2872 | } |
| 2873 | |
| 2874 | template <class _Allocator> |
| 2875 | typename vector<bool, _Allocator>::reference |
| 2876 | vector<bool, _Allocator>::at(size_type __n) |
| 2877 | { |
| 2878 | if (__n >= size()) |
| 2879 | this->__throw_out_of_range(); |
| 2880 | return (*this)[__n]; |
| 2881 | } |
| 2882 | |
| 2883 | template <class _Allocator> |
| 2884 | typename vector<bool, _Allocator>::const_reference |
| 2885 | vector<bool, _Allocator>::at(size_type __n) const |
| 2886 | { |
| 2887 | if (__n >= size()) |
| 2888 | this->__throw_out_of_range(); |
| 2889 | return (*this)[__n]; |
| 2890 | } |
| 2891 | |
| 2892 | template <class _Allocator> |
| 2893 | void |
| 2894 | vector<bool, _Allocator>::push_back(const value_type& __x) |
| 2895 | { |
| 2896 | if (this->__size_ == this->capacity()) |
| 2897 | reserve(__recommend(this->__size_ + 1)); |
| 2898 | ++this->__size_; |
| 2899 | back() = __x; |
| 2900 | } |
| 2901 | |
| 2902 | template <class _Allocator> |
| 2903 | typename vector<bool, _Allocator>::iterator |
| 2904 | vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x) |
| 2905 | { |
| 2906 | iterator __r; |
| 2907 | if (size() < capacity()) |
| 2908 | { |
| 2909 | const_iterator __old_end = end(); |
| 2910 | ++__size_; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2911 | _VSTD::copy_backward(__position, __old_end, end()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2912 | __r = __const_iterator_cast(__position); |
| 2913 | } |
| 2914 | else |
| 2915 | { |
| 2916 | vector __v(__alloc()); |
| 2917 | __v.reserve(__recommend(__size_ + 1)); |
| 2918 | __v.__size_ = __size_ + 1; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2919 | __r = _VSTD::copy(cbegin(), __position, __v.begin()); |
| 2920 | _VSTD::copy_backward(__position, cend(), __v.end()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2921 | swap(__v); |
| 2922 | } |
| 2923 | *__r = __x; |
| 2924 | return __r; |
| 2925 | } |
| 2926 | |
| 2927 | template <class _Allocator> |
| 2928 | typename vector<bool, _Allocator>::iterator |
| 2929 | vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x) |
| 2930 | { |
| 2931 | iterator __r; |
| 2932 | size_type __c = capacity(); |
| 2933 | if (__n <= __c && size() <= __c - __n) |
| 2934 | { |
| 2935 | const_iterator __old_end = end(); |
| 2936 | __size_ += __n; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2937 | _VSTD::copy_backward(__position, __old_end, end()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2938 | __r = __const_iterator_cast(__position); |
| 2939 | } |
| 2940 | else |
| 2941 | { |
| 2942 | vector __v(__alloc()); |
| 2943 | __v.reserve(__recommend(__size_ + __n)); |
| 2944 | __v.__size_ = __size_ + __n; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2945 | __r = _VSTD::copy(cbegin(), __position, __v.begin()); |
| 2946 | _VSTD::copy_backward(__position, cend(), __v.end()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2947 | swap(__v); |
| 2948 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2949 | _VSTD::fill_n(__r, __n, __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2950 | return __r; |
| 2951 | } |
| 2952 | |
| 2953 | template <class _Allocator> |
| 2954 | template <class _InputIterator> |
| 2955 | typename enable_if |
| 2956 | < |
| 2957 | __is_input_iterator <_InputIterator>::value && |
| 2958 | !__is_forward_iterator<_InputIterator>::value, |
| 2959 | typename vector<bool, _Allocator>::iterator |
| 2960 | >::type |
| 2961 | vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) |
| 2962 | { |
| 2963 | difference_type __off = __position - begin(); |
| 2964 | iterator __p = __const_iterator_cast(__position); |
| 2965 | iterator __old_end = end(); |
| 2966 | for (; size() != capacity() && __first != __last; ++__first) |
| 2967 | { |
| 2968 | ++this->__size_; |
| 2969 | back() = *__first; |
| 2970 | } |
| 2971 | vector __v(__alloc()); |
| 2972 | if (__first != __last) |
| 2973 | { |
| 2974 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2975 | try |
| 2976 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2977 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2978 | __v.assign(__first, __last); |
| 2979 | difference_type __old_size = static_cast<difference_type>(__old_end - begin()); |
| 2980 | difference_type __old_p = __p - begin(); |
| 2981 | reserve(__recommend(size() + __v.size())); |
| 2982 | __p = begin() + __old_p; |
| 2983 | __old_end = begin() + __old_size; |
| 2984 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2985 | } |
| 2986 | catch (...) |
| 2987 | { |
| 2988 | erase(__old_end, end()); |
| 2989 | throw; |
| 2990 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2991 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2992 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2993 | __p = _VSTD::rotate(__p, __old_end, end()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2994 | insert(__p, __v.begin(), __v.end()); |
| 2995 | return begin() + __off; |
| 2996 | } |
| 2997 | |
| 2998 | template <class _Allocator> |
| 2999 | template <class _ForwardIterator> |
| 3000 | typename enable_if |
| 3001 | < |
| 3002 | __is_forward_iterator<_ForwardIterator>::value, |
| 3003 | typename vector<bool, _Allocator>::iterator |
| 3004 | >::type |
| 3005 | vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) |
| 3006 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3007 | difference_type __n = _VSTD::distance(__first, __last); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3008 | iterator __r; |
| 3009 | size_type __c = capacity(); |
| 3010 | if (__n <= __c && size() <= __c - __n) |
| 3011 | { |
| 3012 | const_iterator __old_end = end(); |
| 3013 | __size_ += __n; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3014 | _VSTD::copy_backward(__position, __old_end, end()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3015 | __r = __const_iterator_cast(__position); |
| 3016 | } |
| 3017 | else |
| 3018 | { |
| 3019 | vector __v(__alloc()); |
| 3020 | __v.reserve(__recommend(__size_ + __n)); |
| 3021 | __v.__size_ = __size_ + __n; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3022 | __r = _VSTD::copy(cbegin(), __position, __v.begin()); |
| 3023 | _VSTD::copy_backward(__position, cend(), __v.end()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3024 | swap(__v); |
| 3025 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3026 | _VSTD::copy(__first, __last, __r); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3027 | return __r; |
| 3028 | } |
| 3029 | |
| 3030 | template <class _Allocator> |
| 3031 | _LIBCPP_INLINE_VISIBILITY inline |
| 3032 | typename vector<bool, _Allocator>::iterator |
| 3033 | vector<bool, _Allocator>::erase(const_iterator __position) |
| 3034 | { |
| 3035 | iterator __r = __const_iterator_cast(__position); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3036 | _VSTD::copy(__position + 1, this->cend(), __r); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3037 | --__size_; |
| 3038 | return __r; |
| 3039 | } |
| 3040 | |
| 3041 | template <class _Allocator> |
| 3042 | typename vector<bool, _Allocator>::iterator |
| 3043 | vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last) |
| 3044 | { |
| 3045 | iterator __r = __const_iterator_cast(__first); |
| 3046 | difference_type __d = __last - __first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3047 | _VSTD::copy(__last, this->cend(), __r); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3048 | __size_ -= __d; |
| 3049 | return __r; |
| 3050 | } |
| 3051 | |
| 3052 | template <class _Allocator> |
| 3053 | void |
| 3054 | vector<bool, _Allocator>::swap(vector& __x) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 3055 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
| 3056 | __is_nothrow_swappable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3057 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3058 | _VSTD::swap(this->__begin_, __x.__begin_); |
| 3059 | _VSTD::swap(this->__size_, __x.__size_); |
| 3060 | _VSTD::swap(this->__cap(), __x.__cap()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3061 | __swap_alloc(this->__alloc(), __x.__alloc()); |
| 3062 | #ifdef _LIBCPP_DEBUG |
| 3063 | iterator::swap(this, &__x); |
| 3064 | const_iterator::swap(this, &__x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3065 | #endif // _LIBCPP_DEBUG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3066 | } |
| 3067 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3068 | template <class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3069 | void |
| 3070 | vector<bool, _Allocator>::resize(size_type __sz, value_type __x) |
| 3071 | { |
| 3072 | size_type __cs = size(); |
| 3073 | if (__cs < __sz) |
| 3074 | { |
| 3075 | iterator __r; |
| 3076 | size_type __c = capacity(); |
| 3077 | size_type __n = __sz - __cs; |
| 3078 | if (__n <= __c && __cs <= __c - __n) |
| 3079 | { |
| 3080 | __r = end(); |
| 3081 | __size_ += __n; |
| 3082 | } |
| 3083 | else |
| 3084 | { |
| 3085 | vector __v(__alloc()); |
| 3086 | __v.reserve(__recommend(__size_ + __n)); |
| 3087 | __v.__size_ = __size_ + __n; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3088 | __r = _VSTD::copy(cbegin(), cend(), __v.begin()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3089 | swap(__v); |
| 3090 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3091 | _VSTD::fill_n(__r, __n, __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3092 | } |
| 3093 | else |
| 3094 | __size_ = __sz; |
| 3095 | } |
| 3096 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3097 | template <class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3098 | void |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 3099 | vector<bool, _Allocator>::flip() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3100 | { |
| 3101 | // do middle whole words |
| 3102 | size_type __n = __size_; |
| 3103 | __storage_pointer __p = __begin_; |
| 3104 | for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) |
| 3105 | *__p = ~*__p; |
| 3106 | // do last partial word |
| 3107 | if (__n > 0) |
| 3108 | { |
| 3109 | __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); |
| 3110 | __storage_type __b = *__p & __m; |
| 3111 | *__p &= ~__m; |
| 3112 | *__p |= ~__b & __m; |
| 3113 | } |
| 3114 | } |
| 3115 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3116 | template <class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3117 | bool |
| 3118 | vector<bool, _Allocator>::__invariants() const |
| 3119 | { |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 3120 | if (this->__begin_ == nullptr) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3121 | { |
| 3122 | if (this->__size_ != 0 || this->__cap() != 0) |
| 3123 | return false; |
| 3124 | } |
| 3125 | else |
| 3126 | { |
| 3127 | if (this->__cap() == 0) |
| 3128 | return false; |
| 3129 | if (this->__size_ > this->capacity()) |
| 3130 | return false; |
| 3131 | } |
| 3132 | return true; |
| 3133 | } |
| 3134 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3135 | template <class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3136 | size_t |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 3137 | vector<bool, _Allocator>::__hash_code() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3138 | { |
| 3139 | size_t __h = 0; |
| 3140 | // do middle whole words |
| 3141 | size_type __n = __size_; |
| 3142 | __storage_pointer __p = __begin_; |
| 3143 | for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) |
| 3144 | __h ^= *__p; |
| 3145 | // do last partial word |
| 3146 | if (__n > 0) |
| 3147 | { |
| 3148 | const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); |
| 3149 | __h ^= *__p & __m; |
| 3150 | } |
| 3151 | return __h; |
| 3152 | } |
| 3153 | |
| 3154 | template <class _Allocator> |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 3155 | struct _LIBCPP_TYPE_VIS hash<vector<bool, _Allocator> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3156 | : public unary_function<vector<bool, _Allocator>, size_t> |
| 3157 | { |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 3158 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 3159 | size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3160 | {return __vec.__hash_code();} |
| 3161 | }; |
| 3162 | |
| 3163 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3164 | _LIBCPP_INLINE_VISIBILITY inline |
| 3165 | bool |
| 3166 | operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) |
| 3167 | { |
| 3168 | const typename vector<_Tp, _Allocator>::size_type __sz = __x.size(); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3169 | return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3170 | } |
| 3171 | |
| 3172 | template <class _Tp, class _Allocator> |
| 3173 | _LIBCPP_INLINE_VISIBILITY inline |
| 3174 | bool |
| 3175 | operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) |
| 3176 | { |
| 3177 | return !(__x == __y); |
| 3178 | } |
| 3179 | |
| 3180 | template <class _Tp, class _Allocator> |
| 3181 | _LIBCPP_INLINE_VISIBILITY inline |
| 3182 | bool |
| 3183 | operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) |
| 3184 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3185 | return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3186 | } |
| 3187 | |
| 3188 | template <class _Tp, class _Allocator> |
| 3189 | _LIBCPP_INLINE_VISIBILITY inline |
| 3190 | bool |
| 3191 | operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) |
| 3192 | { |
| 3193 | return __y < __x; |
| 3194 | } |
| 3195 | |
| 3196 | template <class _Tp, class _Allocator> |
| 3197 | _LIBCPP_INLINE_VISIBILITY inline |
| 3198 | bool |
| 3199 | operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) |
| 3200 | { |
| 3201 | return !(__x < __y); |
| 3202 | } |
| 3203 | |
| 3204 | template <class _Tp, class _Allocator> |
| 3205 | _LIBCPP_INLINE_VISIBILITY inline |
| 3206 | bool |
| 3207 | operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) |
| 3208 | { |
| 3209 | return !(__y < __x); |
| 3210 | } |
| 3211 | |
| 3212 | template <class _Tp, class _Allocator> |
| 3213 | _LIBCPP_INLINE_VISIBILITY inline |
| 3214 | void |
| 3215 | swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 3216 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3217 | { |
| 3218 | __x.swap(__y); |
| 3219 | } |
| 3220 | |
| 3221 | _LIBCPP_END_NAMESPACE_STD |
| 3222 | |
| 3223 | #endif // _LIBCPP_VECTOR |