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