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