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