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