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