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