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