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