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