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