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