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