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