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