10b57cec5SDimitry Andric// -*- C++ -*- 20b57cec5SDimitry Andric//===------------------------------ vector --------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP_VECTOR 110b57cec5SDimitry Andric#define _LIBCPP_VECTOR 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric/* 140b57cec5SDimitry Andric vector synopsis 150b57cec5SDimitry Andric 160b57cec5SDimitry Andricnamespace std 170b57cec5SDimitry Andric{ 180b57cec5SDimitry Andric 190b57cec5SDimitry Andrictemplate <class T, class Allocator = allocator<T> > 200b57cec5SDimitry Andricclass vector 210b57cec5SDimitry Andric{ 220b57cec5SDimitry Andricpublic: 230b57cec5SDimitry Andric typedef T value_type; 240b57cec5SDimitry Andric typedef Allocator allocator_type; 250b57cec5SDimitry Andric typedef typename allocator_type::reference reference; 260b57cec5SDimitry Andric typedef typename allocator_type::const_reference const_reference; 270b57cec5SDimitry Andric typedef implementation-defined iterator; 280b57cec5SDimitry Andric typedef implementation-defined const_iterator; 290b57cec5SDimitry Andric typedef typename allocator_type::size_type size_type; 300b57cec5SDimitry Andric typedef typename allocator_type::difference_type difference_type; 310b57cec5SDimitry Andric typedef typename allocator_type::pointer pointer; 320b57cec5SDimitry Andric typedef typename allocator_type::const_pointer const_pointer; 330b57cec5SDimitry Andric typedef std::reverse_iterator<iterator> reverse_iterator; 340b57cec5SDimitry Andric typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 350b57cec5SDimitry Andric 360b57cec5SDimitry Andric vector() 370b57cec5SDimitry Andric noexcept(is_nothrow_default_constructible<allocator_type>::value); 380b57cec5SDimitry Andric explicit vector(const allocator_type&); 390b57cec5SDimitry Andric explicit vector(size_type n); 400b57cec5SDimitry Andric explicit vector(size_type n, const allocator_type&); // C++14 410b57cec5SDimitry Andric vector(size_type n, const value_type& value, const allocator_type& = allocator_type()); 420b57cec5SDimitry Andric template <class InputIterator> 430b57cec5SDimitry Andric vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); 440b57cec5SDimitry Andric vector(const vector& x); 450b57cec5SDimitry Andric vector(vector&& x) 460b57cec5SDimitry Andric noexcept(is_nothrow_move_constructible<allocator_type>::value); 470b57cec5SDimitry Andric vector(initializer_list<value_type> il); 480b57cec5SDimitry Andric vector(initializer_list<value_type> il, const allocator_type& a); 490b57cec5SDimitry Andric ~vector(); 500b57cec5SDimitry Andric vector& operator=(const vector& x); 510b57cec5SDimitry Andric vector& operator=(vector&& x) 520b57cec5SDimitry Andric noexcept( 530b57cec5SDimitry Andric allocator_type::propagate_on_container_move_assignment::value || 540b57cec5SDimitry Andric allocator_type::is_always_equal::value); // C++17 550b57cec5SDimitry Andric vector& operator=(initializer_list<value_type> il); 560b57cec5SDimitry Andric template <class InputIterator> 570b57cec5SDimitry Andric void assign(InputIterator first, InputIterator last); 580b57cec5SDimitry Andric void assign(size_type n, const value_type& u); 590b57cec5SDimitry Andric void assign(initializer_list<value_type> il); 600b57cec5SDimitry Andric 610b57cec5SDimitry Andric allocator_type get_allocator() const noexcept; 620b57cec5SDimitry Andric 630b57cec5SDimitry Andric iterator begin() noexcept; 640b57cec5SDimitry Andric const_iterator begin() const noexcept; 650b57cec5SDimitry Andric iterator end() noexcept; 660b57cec5SDimitry Andric const_iterator end() const noexcept; 670b57cec5SDimitry Andric 680b57cec5SDimitry Andric reverse_iterator rbegin() noexcept; 690b57cec5SDimitry Andric const_reverse_iterator rbegin() const noexcept; 700b57cec5SDimitry Andric reverse_iterator rend() noexcept; 710b57cec5SDimitry Andric const_reverse_iterator rend() const noexcept; 720b57cec5SDimitry Andric 730b57cec5SDimitry Andric const_iterator cbegin() const noexcept; 740b57cec5SDimitry Andric const_iterator cend() const noexcept; 750b57cec5SDimitry Andric const_reverse_iterator crbegin() const noexcept; 760b57cec5SDimitry Andric const_reverse_iterator crend() const noexcept; 770b57cec5SDimitry Andric 780b57cec5SDimitry Andric size_type size() const noexcept; 790b57cec5SDimitry Andric size_type max_size() const noexcept; 800b57cec5SDimitry Andric size_type capacity() const noexcept; 810b57cec5SDimitry Andric bool empty() const noexcept; 820b57cec5SDimitry Andric void reserve(size_type n); 830b57cec5SDimitry Andric void shrink_to_fit() noexcept; 840b57cec5SDimitry Andric 850b57cec5SDimitry Andric reference operator[](size_type n); 860b57cec5SDimitry Andric const_reference operator[](size_type n) const; 870b57cec5SDimitry Andric reference at(size_type n); 880b57cec5SDimitry Andric const_reference at(size_type n) const; 890b57cec5SDimitry Andric 900b57cec5SDimitry Andric reference front(); 910b57cec5SDimitry Andric const_reference front() const; 920b57cec5SDimitry Andric reference back(); 930b57cec5SDimitry Andric const_reference back() const; 940b57cec5SDimitry Andric 950b57cec5SDimitry Andric value_type* data() noexcept; 960b57cec5SDimitry Andric const value_type* data() const noexcept; 970b57cec5SDimitry Andric 980b57cec5SDimitry Andric void push_back(const value_type& x); 990b57cec5SDimitry Andric void push_back(value_type&& x); 1000b57cec5SDimitry Andric template <class... Args> 1010b57cec5SDimitry Andric reference emplace_back(Args&&... args); // reference in C++17 1020b57cec5SDimitry Andric void pop_back(); 1030b57cec5SDimitry Andric 1040b57cec5SDimitry Andric template <class... Args> iterator emplace(const_iterator position, Args&&... args); 1050b57cec5SDimitry Andric iterator insert(const_iterator position, const value_type& x); 1060b57cec5SDimitry Andric iterator insert(const_iterator position, value_type&& x); 1070b57cec5SDimitry Andric iterator insert(const_iterator position, size_type n, const value_type& x); 1080b57cec5SDimitry Andric template <class InputIterator> 1090b57cec5SDimitry Andric iterator insert(const_iterator position, InputIterator first, InputIterator last); 1100b57cec5SDimitry Andric iterator insert(const_iterator position, initializer_list<value_type> il); 1110b57cec5SDimitry Andric 1120b57cec5SDimitry Andric iterator erase(const_iterator position); 1130b57cec5SDimitry Andric iterator erase(const_iterator first, const_iterator last); 1140b57cec5SDimitry Andric 1150b57cec5SDimitry Andric void clear() noexcept; 1160b57cec5SDimitry Andric 1170b57cec5SDimitry Andric void resize(size_type sz); 1180b57cec5SDimitry Andric void resize(size_type sz, const value_type& c); 1190b57cec5SDimitry Andric 1200b57cec5SDimitry Andric void swap(vector&) 1210b57cec5SDimitry Andric noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || 1220b57cec5SDimitry Andric allocator_traits<allocator_type>::is_always_equal::value); // C++17 1230b57cec5SDimitry Andric 1240b57cec5SDimitry Andric bool __invariants() const; 1250b57cec5SDimitry Andric}; 1260b57cec5SDimitry Andric 1270b57cec5SDimitry Andrictemplate <class Allocator = allocator<T> > 1280b57cec5SDimitry Andricclass vector<bool, Allocator> 1290b57cec5SDimitry Andric{ 1300b57cec5SDimitry Andricpublic: 1310b57cec5SDimitry Andric typedef bool value_type; 1320b57cec5SDimitry Andric typedef Allocator allocator_type; 1330b57cec5SDimitry Andric typedef implementation-defined iterator; 1340b57cec5SDimitry Andric typedef implementation-defined const_iterator; 1350b57cec5SDimitry Andric typedef typename allocator_type::size_type size_type; 1360b57cec5SDimitry Andric typedef typename allocator_type::difference_type difference_type; 1370b57cec5SDimitry Andric typedef iterator pointer; 1380b57cec5SDimitry Andric typedef const_iterator const_pointer; 1390b57cec5SDimitry Andric typedef std::reverse_iterator<iterator> reverse_iterator; 1400b57cec5SDimitry Andric typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 1410b57cec5SDimitry Andric 1420b57cec5SDimitry Andric class reference 1430b57cec5SDimitry Andric { 1440b57cec5SDimitry Andric public: 1450b57cec5SDimitry Andric reference(const reference&) noexcept; 1460b57cec5SDimitry Andric operator bool() const noexcept; 1470b57cec5SDimitry Andric reference& operator=(const bool x) noexcept; 1480b57cec5SDimitry Andric reference& operator=(const reference& x) noexcept; 1490b57cec5SDimitry Andric iterator operator&() const noexcept; 1500b57cec5SDimitry Andric void flip() noexcept; 1510b57cec5SDimitry Andric }; 1520b57cec5SDimitry Andric 1530b57cec5SDimitry Andric class const_reference 1540b57cec5SDimitry Andric { 1550b57cec5SDimitry Andric public: 1560b57cec5SDimitry Andric const_reference(const reference&) noexcept; 1570b57cec5SDimitry Andric operator bool() const noexcept; 1580b57cec5SDimitry Andric const_iterator operator&() const noexcept; 1590b57cec5SDimitry Andric }; 1600b57cec5SDimitry Andric 1610b57cec5SDimitry Andric vector() 1620b57cec5SDimitry Andric noexcept(is_nothrow_default_constructible<allocator_type>::value); 1630b57cec5SDimitry Andric explicit vector(const allocator_type&); 1640b57cec5SDimitry Andric explicit vector(size_type n, const allocator_type& a = allocator_type()); // C++14 1650b57cec5SDimitry Andric vector(size_type n, const value_type& value, const allocator_type& = allocator_type()); 1660b57cec5SDimitry Andric template <class InputIterator> 1670b57cec5SDimitry Andric vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); 1680b57cec5SDimitry Andric vector(const vector& x); 1690b57cec5SDimitry Andric vector(vector&& x) 1700b57cec5SDimitry Andric noexcept(is_nothrow_move_constructible<allocator_type>::value); 1710b57cec5SDimitry Andric vector(initializer_list<value_type> il); 1720b57cec5SDimitry Andric vector(initializer_list<value_type> il, const allocator_type& a); 1730b57cec5SDimitry Andric ~vector(); 1740b57cec5SDimitry Andric vector& operator=(const vector& x); 1750b57cec5SDimitry Andric vector& operator=(vector&& x) 1760b57cec5SDimitry Andric noexcept( 1770b57cec5SDimitry Andric allocator_type::propagate_on_container_move_assignment::value || 1780b57cec5SDimitry Andric allocator_type::is_always_equal::value); // C++17 1790b57cec5SDimitry Andric vector& operator=(initializer_list<value_type> il); 1800b57cec5SDimitry Andric template <class InputIterator> 1810b57cec5SDimitry Andric void assign(InputIterator first, InputIterator last); 1820b57cec5SDimitry Andric void assign(size_type n, const value_type& u); 1830b57cec5SDimitry Andric void assign(initializer_list<value_type> il); 1840b57cec5SDimitry Andric 1850b57cec5SDimitry Andric allocator_type get_allocator() const noexcept; 1860b57cec5SDimitry Andric 1870b57cec5SDimitry Andric iterator begin() noexcept; 1880b57cec5SDimitry Andric const_iterator begin() const noexcept; 1890b57cec5SDimitry Andric iterator end() noexcept; 1900b57cec5SDimitry Andric const_iterator end() const noexcept; 1910b57cec5SDimitry Andric 1920b57cec5SDimitry Andric reverse_iterator rbegin() noexcept; 1930b57cec5SDimitry Andric const_reverse_iterator rbegin() const noexcept; 1940b57cec5SDimitry Andric reverse_iterator rend() noexcept; 1950b57cec5SDimitry Andric const_reverse_iterator rend() const noexcept; 1960b57cec5SDimitry Andric 1970b57cec5SDimitry Andric const_iterator cbegin() const noexcept; 1980b57cec5SDimitry Andric const_iterator cend() const noexcept; 1990b57cec5SDimitry Andric const_reverse_iterator crbegin() const noexcept; 2000b57cec5SDimitry Andric const_reverse_iterator crend() const noexcept; 2010b57cec5SDimitry Andric 2020b57cec5SDimitry Andric size_type size() const noexcept; 2030b57cec5SDimitry Andric size_type max_size() const noexcept; 2040b57cec5SDimitry Andric size_type capacity() const noexcept; 2050b57cec5SDimitry Andric bool empty() const noexcept; 2060b57cec5SDimitry Andric void reserve(size_type n); 2070b57cec5SDimitry Andric void shrink_to_fit() noexcept; 2080b57cec5SDimitry Andric 2090b57cec5SDimitry Andric reference operator[](size_type n); 2100b57cec5SDimitry Andric const_reference operator[](size_type n) const; 2110b57cec5SDimitry Andric reference at(size_type n); 2120b57cec5SDimitry Andric const_reference at(size_type n) const; 2130b57cec5SDimitry Andric 2140b57cec5SDimitry Andric reference front(); 2150b57cec5SDimitry Andric const_reference front() const; 2160b57cec5SDimitry Andric reference back(); 2170b57cec5SDimitry Andric const_reference back() const; 2180b57cec5SDimitry Andric 2190b57cec5SDimitry Andric void push_back(const value_type& x); 2200b57cec5SDimitry Andric template <class... Args> reference emplace_back(Args&&... args); // C++14; reference in C++17 2210b57cec5SDimitry Andric void pop_back(); 2220b57cec5SDimitry Andric 2230b57cec5SDimitry Andric template <class... Args> iterator emplace(const_iterator position, Args&&... args); // C++14 2240b57cec5SDimitry Andric iterator insert(const_iterator position, const value_type& x); 2250b57cec5SDimitry Andric iterator insert(const_iterator position, size_type n, const value_type& x); 2260b57cec5SDimitry Andric template <class InputIterator> 2270b57cec5SDimitry Andric iterator insert(const_iterator position, InputIterator first, InputIterator last); 2280b57cec5SDimitry Andric iterator insert(const_iterator position, initializer_list<value_type> il); 2290b57cec5SDimitry Andric 2300b57cec5SDimitry Andric iterator erase(const_iterator position); 2310b57cec5SDimitry Andric iterator erase(const_iterator first, const_iterator last); 2320b57cec5SDimitry Andric 2330b57cec5SDimitry Andric void clear() noexcept; 2340b57cec5SDimitry Andric 2350b57cec5SDimitry Andric void resize(size_type sz); 2360b57cec5SDimitry Andric void resize(size_type sz, value_type x); 2370b57cec5SDimitry Andric 2380b57cec5SDimitry Andric void swap(vector&) 2390b57cec5SDimitry Andric noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || 2400b57cec5SDimitry Andric allocator_traits<allocator_type>::is_always_equal::value); // C++17 2410b57cec5SDimitry Andric void flip() noexcept; 2420b57cec5SDimitry Andric 2430b57cec5SDimitry Andric bool __invariants() const; 2440b57cec5SDimitry Andric}; 2450b57cec5SDimitry Andric 2460b57cec5SDimitry Andrictemplate <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> 2470b57cec5SDimitry Andric vector(InputIterator, InputIterator, Allocator = Allocator()) 2480b57cec5SDimitry Andric -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>; 2490b57cec5SDimitry Andric 2500b57cec5SDimitry Andrictemplate <class Allocator> struct hash<std::vector<bool, Allocator>>; 2510b57cec5SDimitry Andric 2520b57cec5SDimitry Andrictemplate <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2530b57cec5SDimitry Andrictemplate <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2540b57cec5SDimitry Andrictemplate <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2550b57cec5SDimitry Andrictemplate <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2560b57cec5SDimitry Andrictemplate <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2570b57cec5SDimitry Andrictemplate <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); 2580b57cec5SDimitry Andric 2590b57cec5SDimitry Andrictemplate <class T, class Allocator> 2600b57cec5SDimitry Andricvoid swap(vector<T,Allocator>& x, vector<T,Allocator>& y) 2610b57cec5SDimitry Andric noexcept(noexcept(x.swap(y))); 2620b57cec5SDimitry Andric 2630b57cec5SDimitry Andrictemplate <class T, class Allocator, class U> 264*5ffd83dbSDimitry Andrictypename vector<T, Allocator>::size_type 265*5ffd83dbSDimitry Andricerase(vector<T, Allocator>& c, const U& value); // C++20 2660b57cec5SDimitry Andrictemplate <class T, class Allocator, class Predicate> 267*5ffd83dbSDimitry Andrictypename vector<T, Allocator>::size_type 268*5ffd83dbSDimitry Andricerase_if(vector<T, Allocator>& c, Predicate pred); // C++20 2690b57cec5SDimitry Andric 2700b57cec5SDimitry Andric} // std 2710b57cec5SDimitry Andric 2720b57cec5SDimitry Andric*/ 2730b57cec5SDimitry Andric 2740b57cec5SDimitry Andric#include <__config> 2750b57cec5SDimitry Andric#include <iosfwd> // for forward declaration of vector 2760b57cec5SDimitry Andric#include <__bit_reference> 2770b57cec5SDimitry Andric#include <type_traits> 2780b57cec5SDimitry Andric#include <climits> 2790b57cec5SDimitry Andric#include <limits> 2800b57cec5SDimitry Andric#include <initializer_list> 2810b57cec5SDimitry Andric#include <memory> 2820b57cec5SDimitry Andric#include <stdexcept> 2830b57cec5SDimitry Andric#include <algorithm> 2840b57cec5SDimitry Andric#include <cstring> 2850b57cec5SDimitry Andric#include <version> 2860b57cec5SDimitry Andric#include <__split_buffer> 2870b57cec5SDimitry Andric#include <__functional_base> 2880b57cec5SDimitry Andric 2890b57cec5SDimitry Andric#include <__debug> 2900b57cec5SDimitry Andric 2910b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 2920b57cec5SDimitry Andric#pragma GCC system_header 2930b57cec5SDimitry Andric#endif 2940b57cec5SDimitry Andric 2950b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS 2960b57cec5SDimitry Andric#include <__undef_macros> 2970b57cec5SDimitry Andric 2980b57cec5SDimitry Andric 2990b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 3000b57cec5SDimitry Andric 3010b57cec5SDimitry Andrictemplate <bool> 302e40139ffSDimitry Andricclass _LIBCPP_TEMPLATE_VIS __vector_base_common 3030b57cec5SDimitry Andric{ 3040b57cec5SDimitry Andricprotected: 3050b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY __vector_base_common() {} 3060b57cec5SDimitry Andric _LIBCPP_NORETURN void __throw_length_error() const; 3070b57cec5SDimitry Andric _LIBCPP_NORETURN void __throw_out_of_range() const; 3080b57cec5SDimitry Andric}; 3090b57cec5SDimitry Andric 3100b57cec5SDimitry Andrictemplate <bool __b> 3110b57cec5SDimitry Andricvoid 3120b57cec5SDimitry Andric__vector_base_common<__b>::__throw_length_error() const 3130b57cec5SDimitry Andric{ 3140b57cec5SDimitry Andric _VSTD::__throw_length_error("vector"); 3150b57cec5SDimitry Andric} 3160b57cec5SDimitry Andric 3170b57cec5SDimitry Andrictemplate <bool __b> 3180b57cec5SDimitry Andricvoid 3190b57cec5SDimitry Andric__vector_base_common<__b>::__throw_out_of_range() const 3200b57cec5SDimitry Andric{ 3210b57cec5SDimitry Andric _VSTD::__throw_out_of_range("vector"); 3220b57cec5SDimitry Andric} 3230b57cec5SDimitry Andric 3240b57cec5SDimitry Andric_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __vector_base_common<true>) 3250b57cec5SDimitry Andric 3260b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 3270b57cec5SDimitry Andricclass __vector_base 3280b57cec5SDimitry Andric : protected __vector_base_common<true> 3290b57cec5SDimitry Andric{ 3300b57cec5SDimitry Andricpublic: 3310b57cec5SDimitry Andric typedef _Allocator allocator_type; 3320b57cec5SDimitry Andric typedef allocator_traits<allocator_type> __alloc_traits; 3330b57cec5SDimitry Andric typedef typename __alloc_traits::size_type size_type; 3340b57cec5SDimitry Andricprotected: 3350b57cec5SDimitry Andric typedef _Tp value_type; 3360b57cec5SDimitry Andric typedef value_type& reference; 3370b57cec5SDimitry Andric typedef const value_type& const_reference; 3380b57cec5SDimitry Andric typedef typename __alloc_traits::difference_type difference_type; 3390b57cec5SDimitry Andric typedef typename __alloc_traits::pointer pointer; 3400b57cec5SDimitry Andric typedef typename __alloc_traits::const_pointer const_pointer; 3410b57cec5SDimitry Andric typedef pointer iterator; 3420b57cec5SDimitry Andric typedef const_pointer const_iterator; 3430b57cec5SDimitry Andric 3440b57cec5SDimitry Andric pointer __begin_; 3450b57cec5SDimitry Andric pointer __end_; 3460b57cec5SDimitry Andric __compressed_pair<pointer, allocator_type> __end_cap_; 3470b57cec5SDimitry Andric 3480b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3490b57cec5SDimitry Andric allocator_type& __alloc() _NOEXCEPT 3500b57cec5SDimitry Andric {return __end_cap_.second();} 3510b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3520b57cec5SDimitry Andric const allocator_type& __alloc() const _NOEXCEPT 3530b57cec5SDimitry Andric {return __end_cap_.second();} 3540b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3550b57cec5SDimitry Andric pointer& __end_cap() _NOEXCEPT 3560b57cec5SDimitry Andric {return __end_cap_.first();} 3570b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3580b57cec5SDimitry Andric const pointer& __end_cap() const _NOEXCEPT 3590b57cec5SDimitry Andric {return __end_cap_.first();} 3600b57cec5SDimitry Andric 3610b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3620b57cec5SDimitry Andric __vector_base() 3630b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); 3640b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a); 3650b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 3660b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY __vector_base(allocator_type&& __a) _NOEXCEPT; 3670b57cec5SDimitry Andric#endif 3680b57cec5SDimitry Andric ~__vector_base(); 3690b57cec5SDimitry Andric 3700b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3710b57cec5SDimitry Andric void clear() _NOEXCEPT {__destruct_at_end(__begin_);} 3720b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3730b57cec5SDimitry Andric size_type capacity() const _NOEXCEPT 3740b57cec5SDimitry Andric {return static_cast<size_type>(__end_cap() - __begin_);} 3750b57cec5SDimitry Andric 3760b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3770b57cec5SDimitry Andric void __destruct_at_end(pointer __new_last) _NOEXCEPT; 3780b57cec5SDimitry Andric 3790b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3800b57cec5SDimitry Andric void __copy_assign_alloc(const __vector_base& __c) 3810b57cec5SDimitry Andric {__copy_assign_alloc(__c, integral_constant<bool, 3820b57cec5SDimitry Andric __alloc_traits::propagate_on_container_copy_assignment::value>());} 3830b57cec5SDimitry Andric 3840b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3850b57cec5SDimitry Andric void __move_assign_alloc(__vector_base& __c) 3860b57cec5SDimitry Andric _NOEXCEPT_( 3870b57cec5SDimitry Andric !__alloc_traits::propagate_on_container_move_assignment::value || 3880b57cec5SDimitry Andric is_nothrow_move_assignable<allocator_type>::value) 3890b57cec5SDimitry Andric {__move_assign_alloc(__c, integral_constant<bool, 3900b57cec5SDimitry Andric __alloc_traits::propagate_on_container_move_assignment::value>());} 3910b57cec5SDimitry Andricprivate: 3920b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 3930b57cec5SDimitry Andric void __copy_assign_alloc(const __vector_base& __c, true_type) 3940b57cec5SDimitry Andric { 3950b57cec5SDimitry Andric if (__alloc() != __c.__alloc()) 3960b57cec5SDimitry Andric { 3970b57cec5SDimitry Andric clear(); 3980b57cec5SDimitry Andric __alloc_traits::deallocate(__alloc(), __begin_, capacity()); 3990b57cec5SDimitry Andric __begin_ = __end_ = __end_cap() = nullptr; 4000b57cec5SDimitry Andric } 4010b57cec5SDimitry Andric __alloc() = __c.__alloc(); 4020b57cec5SDimitry Andric } 4030b57cec5SDimitry Andric 4040b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4050b57cec5SDimitry Andric void __copy_assign_alloc(const __vector_base&, false_type) 4060b57cec5SDimitry Andric {} 4070b57cec5SDimitry Andric 4080b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4090b57cec5SDimitry Andric void __move_assign_alloc(__vector_base& __c, true_type) 4100b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 4110b57cec5SDimitry Andric { 4120b57cec5SDimitry Andric __alloc() = _VSTD::move(__c.__alloc()); 4130b57cec5SDimitry Andric } 4140b57cec5SDimitry Andric 4150b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4160b57cec5SDimitry Andric void __move_assign_alloc(__vector_base&, false_type) 4170b57cec5SDimitry Andric _NOEXCEPT 4180b57cec5SDimitry Andric {} 4190b57cec5SDimitry Andric}; 4200b57cec5SDimitry Andric 4210b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 4220b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4230b57cec5SDimitry Andricvoid 4240b57cec5SDimitry Andric__vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT 4250b57cec5SDimitry Andric{ 4260b57cec5SDimitry Andric pointer __soon_to_be_end = __end_; 4270b57cec5SDimitry Andric while (__new_last != __soon_to_be_end) 428480093f4SDimitry Andric __alloc_traits::destroy(__alloc(), _VSTD::__to_address(--__soon_to_be_end)); 4290b57cec5SDimitry Andric __end_ = __new_last; 4300b57cec5SDimitry Andric} 4310b57cec5SDimitry Andric 4320b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 4330b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4340b57cec5SDimitry Andric__vector_base<_Tp, _Allocator>::__vector_base() 4350b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 4360b57cec5SDimitry Andric : __begin_(nullptr), 4370b57cec5SDimitry Andric __end_(nullptr), 438480093f4SDimitry Andric __end_cap_(nullptr, __default_init_tag()) 4390b57cec5SDimitry Andric{ 4400b57cec5SDimitry Andric} 4410b57cec5SDimitry Andric 4420b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 4430b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4440b57cec5SDimitry Andric__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a) 4450b57cec5SDimitry Andric : __begin_(nullptr), 4460b57cec5SDimitry Andric __end_(nullptr), 4470b57cec5SDimitry Andric __end_cap_(nullptr, __a) 4480b57cec5SDimitry Andric{ 4490b57cec5SDimitry Andric} 4500b57cec5SDimitry Andric 4510b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 4520b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 4530b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 4540b57cec5SDimitry Andric__vector_base<_Tp, _Allocator>::__vector_base(allocator_type&& __a) _NOEXCEPT 4550b57cec5SDimitry Andric : __begin_(nullptr), 4560b57cec5SDimitry Andric __end_(nullptr), 4570b57cec5SDimitry Andric __end_cap_(nullptr, std::move(__a)) {} 4580b57cec5SDimitry Andric#endif 4590b57cec5SDimitry Andric 4600b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 4610b57cec5SDimitry Andric__vector_base<_Tp, _Allocator>::~__vector_base() 4620b57cec5SDimitry Andric{ 4630b57cec5SDimitry Andric if (__begin_ != nullptr) 4640b57cec5SDimitry Andric { 4650b57cec5SDimitry Andric clear(); 4660b57cec5SDimitry Andric __alloc_traits::deallocate(__alloc(), __begin_, capacity()); 4670b57cec5SDimitry Andric } 4680b57cec5SDimitry Andric} 4690b57cec5SDimitry Andric 4700b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator /* = allocator<_Tp> */> 4710b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector 4720b57cec5SDimitry Andric : private __vector_base<_Tp, _Allocator> 4730b57cec5SDimitry Andric{ 4740b57cec5SDimitry Andricprivate: 4750b57cec5SDimitry Andric typedef __vector_base<_Tp, _Allocator> __base; 4760b57cec5SDimitry Andric typedef allocator<_Tp> __default_allocator_type; 4770b57cec5SDimitry Andricpublic: 4780b57cec5SDimitry Andric typedef vector __self; 4790b57cec5SDimitry Andric typedef _Tp value_type; 4800b57cec5SDimitry Andric typedef _Allocator allocator_type; 4810b57cec5SDimitry Andric typedef typename __base::__alloc_traits __alloc_traits; 4820b57cec5SDimitry Andric typedef typename __base::reference reference; 4830b57cec5SDimitry Andric typedef typename __base::const_reference const_reference; 4840b57cec5SDimitry Andric typedef typename __base::size_type size_type; 4850b57cec5SDimitry Andric typedef typename __base::difference_type difference_type; 4860b57cec5SDimitry Andric typedef typename __base::pointer pointer; 4870b57cec5SDimitry Andric typedef typename __base::const_pointer const_pointer; 4880b57cec5SDimitry Andric typedef __wrap_iter<pointer> iterator; 4890b57cec5SDimitry Andric typedef __wrap_iter<const_pointer> const_iterator; 4900b57cec5SDimitry Andric typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 4910b57cec5SDimitry Andric typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 4920b57cec5SDimitry Andric 4930b57cec5SDimitry Andric static_assert((is_same<typename allocator_type::value_type, value_type>::value), 4940b57cec5SDimitry Andric "Allocator::value_type must be same type as value_type"); 4950b57cec5SDimitry Andric 4960b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 4970b57cec5SDimitry Andric vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 4980b57cec5SDimitry Andric { 4990b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 5000b57cec5SDimitry Andric __get_db()->__insert_c(this); 5010b57cec5SDimitry Andric#endif 5020b57cec5SDimitry Andric } 5030b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) 5040b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 5050b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) 5060b57cec5SDimitry Andric#else 5070b57cec5SDimitry Andric _NOEXCEPT 5080b57cec5SDimitry Andric#endif 5090b57cec5SDimitry Andric : __base(__a) 5100b57cec5SDimitry Andric { 5110b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 5120b57cec5SDimitry Andric __get_db()->__insert_c(this); 5130b57cec5SDimitry Andric#endif 5140b57cec5SDimitry Andric } 5150b57cec5SDimitry Andric explicit vector(size_type __n); 5160b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 5170b57cec5SDimitry Andric explicit vector(size_type __n, const allocator_type& __a); 5180b57cec5SDimitry Andric#endif 5190b57cec5SDimitry Andric vector(size_type __n, const value_type& __x); 5200b57cec5SDimitry Andric vector(size_type __n, const value_type& __x, const allocator_type& __a); 5210b57cec5SDimitry Andric template <class _InputIterator> 5220b57cec5SDimitry Andric vector(_InputIterator __first, 523480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 524480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value && 5250b57cec5SDimitry Andric is_constructible< 5260b57cec5SDimitry Andric value_type, 5270b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 5280b57cec5SDimitry Andric _InputIterator>::type __last); 5290b57cec5SDimitry Andric template <class _InputIterator> 5300b57cec5SDimitry Andric vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 531480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 532480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value && 5330b57cec5SDimitry Andric is_constructible< 5340b57cec5SDimitry Andric value_type, 5350b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value>::type* = 0); 5360b57cec5SDimitry Andric template <class _ForwardIterator> 5370b57cec5SDimitry Andric vector(_ForwardIterator __first, 538480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value && 5390b57cec5SDimitry Andric is_constructible< 5400b57cec5SDimitry Andric value_type, 5410b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 5420b57cec5SDimitry Andric _ForwardIterator>::type __last); 5430b57cec5SDimitry Andric template <class _ForwardIterator> 5440b57cec5SDimitry Andric vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 545480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value && 5460b57cec5SDimitry Andric is_constructible< 5470b57cec5SDimitry Andric value_type, 5480b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0); 5490b57cec5SDimitry Andric 5500b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5510b57cec5SDimitry Andric ~vector() 5520b57cec5SDimitry Andric { 5530b57cec5SDimitry Andric __annotate_delete(); 5540b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 5550b57cec5SDimitry Andric __get_db()->__erase_c(this); 5560b57cec5SDimitry Andric#endif 5570b57cec5SDimitry Andric } 5580b57cec5SDimitry Andric 5590b57cec5SDimitry Andric vector(const vector& __x); 5600b57cec5SDimitry Andric vector(const vector& __x, const allocator_type& __a); 5610b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5620b57cec5SDimitry Andric vector& operator=(const vector& __x); 5630b57cec5SDimitry Andric 5640b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 5650b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5660b57cec5SDimitry Andric vector(initializer_list<value_type> __il); 5670b57cec5SDimitry Andric 5680b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5690b57cec5SDimitry Andric vector(initializer_list<value_type> __il, const allocator_type& __a); 5700b57cec5SDimitry Andric 5710b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5720b57cec5SDimitry Andric vector(vector&& __x) 5730b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 5740b57cec5SDimitry Andric _NOEXCEPT; 5750b57cec5SDimitry Andric#else 5760b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); 5770b57cec5SDimitry Andric#endif 5780b57cec5SDimitry Andric 5790b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5800b57cec5SDimitry Andric vector(vector&& __x, const allocator_type& __a); 5810b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5820b57cec5SDimitry Andric vector& operator=(vector&& __x) 5830b57cec5SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); 5840b57cec5SDimitry Andric 5850b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 5860b57cec5SDimitry Andric vector& operator=(initializer_list<value_type> __il) 5870b57cec5SDimitry Andric {assign(__il.begin(), __il.end()); return *this;} 5880b57cec5SDimitry Andric 5890b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG 5900b57cec5SDimitry Andric 5910b57cec5SDimitry Andric template <class _InputIterator> 5920b57cec5SDimitry Andric typename enable_if 5930b57cec5SDimitry Andric < 594480093f4SDimitry Andric __is_cpp17_input_iterator <_InputIterator>::value && 595480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value && 5960b57cec5SDimitry Andric is_constructible< 5970b57cec5SDimitry Andric value_type, 5980b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 5990b57cec5SDimitry Andric void 6000b57cec5SDimitry Andric >::type 6010b57cec5SDimitry Andric assign(_InputIterator __first, _InputIterator __last); 6020b57cec5SDimitry Andric template <class _ForwardIterator> 6030b57cec5SDimitry Andric typename enable_if 6040b57cec5SDimitry Andric < 605480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value && 6060b57cec5SDimitry Andric is_constructible< 6070b57cec5SDimitry Andric value_type, 6080b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 6090b57cec5SDimitry Andric void 6100b57cec5SDimitry Andric >::type 6110b57cec5SDimitry Andric assign(_ForwardIterator __first, _ForwardIterator __last); 6120b57cec5SDimitry Andric 6130b57cec5SDimitry Andric void assign(size_type __n, const_reference __u); 6140b57cec5SDimitry Andric 6150b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 6160b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6170b57cec5SDimitry Andric void assign(initializer_list<value_type> __il) 6180b57cec5SDimitry Andric {assign(__il.begin(), __il.end());} 6190b57cec5SDimitry Andric#endif 6200b57cec5SDimitry Andric 6210b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6220b57cec5SDimitry Andric allocator_type get_allocator() const _NOEXCEPT 6230b57cec5SDimitry Andric {return this->__alloc();} 6240b57cec5SDimitry Andric 6250b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT; 6260b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT; 6270b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT; 6280b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT; 6290b57cec5SDimitry Andric 6300b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6310b57cec5SDimitry Andric reverse_iterator rbegin() _NOEXCEPT 6320b57cec5SDimitry Andric {return reverse_iterator(end());} 6330b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6340b57cec5SDimitry Andric const_reverse_iterator rbegin() const _NOEXCEPT 6350b57cec5SDimitry Andric {return const_reverse_iterator(end());} 6360b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6370b57cec5SDimitry Andric reverse_iterator rend() _NOEXCEPT 6380b57cec5SDimitry Andric {return reverse_iterator(begin());} 6390b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6400b57cec5SDimitry Andric const_reverse_iterator rend() const _NOEXCEPT 6410b57cec5SDimitry Andric {return const_reverse_iterator(begin());} 6420b57cec5SDimitry Andric 6430b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6440b57cec5SDimitry Andric const_iterator cbegin() const _NOEXCEPT 6450b57cec5SDimitry Andric {return begin();} 6460b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6470b57cec5SDimitry Andric const_iterator cend() const _NOEXCEPT 6480b57cec5SDimitry Andric {return end();} 6490b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6500b57cec5SDimitry Andric const_reverse_iterator crbegin() const _NOEXCEPT 6510b57cec5SDimitry Andric {return rbegin();} 6520b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6530b57cec5SDimitry Andric const_reverse_iterator crend() const _NOEXCEPT 6540b57cec5SDimitry Andric {return rend();} 6550b57cec5SDimitry Andric 6560b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6570b57cec5SDimitry Andric size_type size() const _NOEXCEPT 6580b57cec5SDimitry Andric {return static_cast<size_type>(this->__end_ - this->__begin_);} 6590b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6600b57cec5SDimitry Andric size_type capacity() const _NOEXCEPT 6610b57cec5SDimitry Andric {return __base::capacity();} 6620b57cec5SDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 6630b57cec5SDimitry Andric bool empty() const _NOEXCEPT 6640b57cec5SDimitry Andric {return this->__begin_ == this->__end_;} 6650b57cec5SDimitry Andric size_type max_size() const _NOEXCEPT; 6660b57cec5SDimitry Andric void reserve(size_type __n); 6670b57cec5SDimitry Andric void shrink_to_fit() _NOEXCEPT; 6680b57cec5SDimitry Andric 6690b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) _NOEXCEPT; 6700b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const _NOEXCEPT; 6710b57cec5SDimitry Andric reference at(size_type __n); 6720b57cec5SDimitry Andric const_reference at(size_type __n) const; 6730b57cec5SDimitry Andric 6740b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT 6750b57cec5SDimitry Andric { 6760b57cec5SDimitry Andric _LIBCPP_ASSERT(!empty(), "front() called for empty vector"); 6770b57cec5SDimitry Andric return *this->__begin_; 6780b57cec5SDimitry Andric } 6790b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT 6800b57cec5SDimitry Andric { 6810b57cec5SDimitry Andric _LIBCPP_ASSERT(!empty(), "front() called for empty vector"); 6820b57cec5SDimitry Andric return *this->__begin_; 6830b57cec5SDimitry Andric } 6840b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT 6850b57cec5SDimitry Andric { 6860b57cec5SDimitry Andric _LIBCPP_ASSERT(!empty(), "back() called for empty vector"); 6870b57cec5SDimitry Andric return *(this->__end_ - 1); 6880b57cec5SDimitry Andric } 6890b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT 6900b57cec5SDimitry Andric { 6910b57cec5SDimitry Andric _LIBCPP_ASSERT(!empty(), "back() called for empty vector"); 6920b57cec5SDimitry Andric return *(this->__end_ - 1); 6930b57cec5SDimitry Andric } 6940b57cec5SDimitry Andric 6950b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6960b57cec5SDimitry Andric value_type* data() _NOEXCEPT 697480093f4SDimitry Andric {return _VSTD::__to_address(this->__begin_);} 6980b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 6990b57cec5SDimitry Andric const value_type* data() const _NOEXCEPT 700480093f4SDimitry Andric {return _VSTD::__to_address(this->__begin_);} 7010b57cec5SDimitry Andric 7020b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG 7030b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7040b57cec5SDimitry Andric void __emplace_back(const value_type& __x) { push_back(__x); } 7050b57cec5SDimitry Andric#else 7060b57cec5SDimitry Andric template <class _Arg> 7070b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7080b57cec5SDimitry Andric void __emplace_back(_Arg&& __arg) { 7090b57cec5SDimitry Andric emplace_back(_VSTD::forward<_Arg>(__arg)); 7100b57cec5SDimitry Andric } 7110b57cec5SDimitry Andric#endif 7120b57cec5SDimitry Andric 7130b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x); 7140b57cec5SDimitry Andric 7150b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 7160b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x); 7170b57cec5SDimitry Andric 7180b57cec5SDimitry Andric template <class... _Args> 7190b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7200b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 7210b57cec5SDimitry Andric reference emplace_back(_Args&&... __args); 7220b57cec5SDimitry Andric#else 7230b57cec5SDimitry Andric void emplace_back(_Args&&... __args); 7240b57cec5SDimitry Andric#endif 7250b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG 7260b57cec5SDimitry Andric 7270b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7280b57cec5SDimitry Andric void pop_back(); 7290b57cec5SDimitry Andric 7300b57cec5SDimitry Andric iterator insert(const_iterator __position, const_reference __x); 7310b57cec5SDimitry Andric 7320b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 7330b57cec5SDimitry Andric iterator insert(const_iterator __position, value_type&& __x); 7340b57cec5SDimitry Andric template <class... _Args> 7350b57cec5SDimitry Andric iterator emplace(const_iterator __position, _Args&&... __args); 7360b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG 7370b57cec5SDimitry Andric 7380b57cec5SDimitry Andric iterator insert(const_iterator __position, size_type __n, const_reference __x); 7390b57cec5SDimitry Andric template <class _InputIterator> 7400b57cec5SDimitry Andric typename enable_if 7410b57cec5SDimitry Andric < 742480093f4SDimitry Andric __is_cpp17_input_iterator <_InputIterator>::value && 743480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value && 7440b57cec5SDimitry Andric is_constructible< 7450b57cec5SDimitry Andric value_type, 7460b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 7470b57cec5SDimitry Andric iterator 7480b57cec5SDimitry Andric >::type 7490b57cec5SDimitry Andric insert(const_iterator __position, _InputIterator __first, _InputIterator __last); 7500b57cec5SDimitry Andric template <class _ForwardIterator> 7510b57cec5SDimitry Andric typename enable_if 7520b57cec5SDimitry Andric < 753480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value && 7540b57cec5SDimitry Andric is_constructible< 7550b57cec5SDimitry Andric value_type, 7560b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 7570b57cec5SDimitry Andric iterator 7580b57cec5SDimitry Andric >::type 7590b57cec5SDimitry Andric insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); 7600b57cec5SDimitry Andric 7610b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 7620b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7630b57cec5SDimitry Andric iterator insert(const_iterator __position, initializer_list<value_type> __il) 7640b57cec5SDimitry Andric {return insert(__position, __il.begin(), __il.end());} 7650b57cec5SDimitry Andric#endif 7660b57cec5SDimitry Andric 7670b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); 7680b57cec5SDimitry Andric iterator erase(const_iterator __first, const_iterator __last); 7690b57cec5SDimitry Andric 7700b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 7710b57cec5SDimitry Andric void clear() _NOEXCEPT 7720b57cec5SDimitry Andric { 7730b57cec5SDimitry Andric size_type __old_size = size(); 7740b57cec5SDimitry Andric __base::clear(); 7750b57cec5SDimitry Andric __annotate_shrink(__old_size); 7760b57cec5SDimitry Andric __invalidate_all_iterators(); 7770b57cec5SDimitry Andric } 7780b57cec5SDimitry Andric 7790b57cec5SDimitry Andric void resize(size_type __sz); 7800b57cec5SDimitry Andric void resize(size_type __sz, const_reference __x); 7810b57cec5SDimitry Andric 7820b57cec5SDimitry Andric void swap(vector&) 7830b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 7840b57cec5SDimitry Andric _NOEXCEPT; 7850b57cec5SDimitry Andric#else 7860b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 7870b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value); 7880b57cec5SDimitry Andric#endif 7890b57cec5SDimitry Andric 7900b57cec5SDimitry Andric bool __invariants() const; 7910b57cec5SDimitry Andric 7920b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 7930b57cec5SDimitry Andric 7940b57cec5SDimitry Andric bool __dereferenceable(const const_iterator* __i) const; 7950b57cec5SDimitry Andric bool __decrementable(const const_iterator* __i) const; 7960b57cec5SDimitry Andric bool __addable(const const_iterator* __i, ptrdiff_t __n) const; 7970b57cec5SDimitry Andric bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; 7980b57cec5SDimitry Andric 7990b57cec5SDimitry Andric#endif // _LIBCPP_DEBUG_LEVEL >= 2 8000b57cec5SDimitry Andric 8010b57cec5SDimitry Andricprivate: 8020b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); 8030b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last); 8040b57cec5SDimitry Andric void __vallocate(size_type __n); 8050b57cec5SDimitry Andric void __vdeallocate() _NOEXCEPT; 8060b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; 8070b57cec5SDimitry Andric void __construct_at_end(size_type __n); 8080b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 8090b57cec5SDimitry Andric void __construct_at_end(size_type __n, const_reference __x); 8100b57cec5SDimitry Andric template <class _ForwardIterator> 8110b57cec5SDimitry Andric typename enable_if 8120b57cec5SDimitry Andric < 813480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 8140b57cec5SDimitry Andric void 8150b57cec5SDimitry Andric >::type 8160b57cec5SDimitry Andric __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n); 8170b57cec5SDimitry Andric void __append(size_type __n); 8180b57cec5SDimitry Andric void __append(size_type __n, const_reference __x); 8190b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 8200b57cec5SDimitry Andric iterator __make_iter(pointer __p) _NOEXCEPT; 8210b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 8220b57cec5SDimitry Andric const_iterator __make_iter(const_pointer __p) const _NOEXCEPT; 8230b57cec5SDimitry Andric void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v); 8240b57cec5SDimitry Andric pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p); 8250b57cec5SDimitry Andric void __move_range(pointer __from_s, pointer __from_e, pointer __to); 8260b57cec5SDimitry Andric void __move_assign(vector& __c, true_type) 8270b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); 8280b57cec5SDimitry Andric void __move_assign(vector& __c, false_type) 8290b57cec5SDimitry Andric _NOEXCEPT_(__alloc_traits::is_always_equal::value); 8300b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 8310b57cec5SDimitry Andric void __destruct_at_end(pointer __new_last) _NOEXCEPT 8320b57cec5SDimitry Andric { 8330b57cec5SDimitry Andric __invalidate_iterators_past(__new_last); 8340b57cec5SDimitry Andric size_type __old_size = size(); 8350b57cec5SDimitry Andric __base::__destruct_at_end(__new_last); 8360b57cec5SDimitry Andric __annotate_shrink(__old_size); 8370b57cec5SDimitry Andric } 8380b57cec5SDimitry Andric 8390b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 8400b57cec5SDimitry Andric template <class _Up> 8410b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 8420b57cec5SDimitry Andric inline void __push_back_slow_path(_Up&& __x); 8430b57cec5SDimitry Andric 8440b57cec5SDimitry Andric template <class... _Args> 8450b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 8460b57cec5SDimitry Andric inline void __emplace_back_slow_path(_Args&&... __args); 8470b57cec5SDimitry Andric#else 8480b57cec5SDimitry Andric template <class _Up> 8490b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 8500b57cec5SDimitry Andric inline void __push_back_slow_path(_Up& __x); 8510b57cec5SDimitry Andric#endif 8520b57cec5SDimitry Andric 8530b57cec5SDimitry Andric // The following functions are no-ops outside of AddressSanitizer mode. 8540b57cec5SDimitry Andric // We call annotatations only for the default Allocator because other allocators 8550b57cec5SDimitry Andric // may not meet the AddressSanitizer alignment constraints. 8560b57cec5SDimitry Andric // See the documentation for __sanitizer_annotate_contiguous_container for more details. 8570b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN 8580b57cec5SDimitry Andric void __annotate_contiguous_container(const void *__beg, const void *__end, 8590b57cec5SDimitry Andric const void *__old_mid, 8600b57cec5SDimitry Andric const void *__new_mid) const 8610b57cec5SDimitry Andric { 8620b57cec5SDimitry Andric 8630b57cec5SDimitry Andric if (__beg && is_same<allocator_type, __default_allocator_type>::value) 8640b57cec5SDimitry Andric __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid); 8650b57cec5SDimitry Andric } 8660b57cec5SDimitry Andric#else 8670b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 8680b57cec5SDimitry Andric void __annotate_contiguous_container(const void*, const void*, const void*, 869e40139ffSDimitry Andric const void*) const _NOEXCEPT {} 8700b57cec5SDimitry Andric#endif 8710b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 872e40139ffSDimitry Andric void __annotate_new(size_type __current_size) const _NOEXCEPT { 8730b57cec5SDimitry Andric __annotate_contiguous_container(data(), data() + capacity(), 8740b57cec5SDimitry Andric data() + capacity(), data() + __current_size); 8750b57cec5SDimitry Andric } 8760b57cec5SDimitry Andric 8770b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 878e40139ffSDimitry Andric void __annotate_delete() const _NOEXCEPT { 8790b57cec5SDimitry Andric __annotate_contiguous_container(data(), data() + capacity(), 8800b57cec5SDimitry Andric data() + size(), data() + capacity()); 8810b57cec5SDimitry Andric } 8820b57cec5SDimitry Andric 8830b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 884e40139ffSDimitry Andric void __annotate_increase(size_type __n) const _NOEXCEPT 8850b57cec5SDimitry Andric { 8860b57cec5SDimitry Andric __annotate_contiguous_container(data(), data() + capacity(), 8870b57cec5SDimitry Andric data() + size(), data() + size() + __n); 8880b57cec5SDimitry Andric } 8890b57cec5SDimitry Andric 8900b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 891e40139ffSDimitry Andric void __annotate_shrink(size_type __old_size) const _NOEXCEPT 8920b57cec5SDimitry Andric { 8930b57cec5SDimitry Andric __annotate_contiguous_container(data(), data() + capacity(), 8940b57cec5SDimitry Andric data() + __old_size, data() + size()); 8950b57cec5SDimitry Andric } 8960b57cec5SDimitry Andric 897e40139ffSDimitry Andric struct _ConstructTransaction { 898e40139ffSDimitry Andric explicit _ConstructTransaction(vector &__v, size_type __n) 899e40139ffSDimitry Andric : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) { 900e40139ffSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN 901e40139ffSDimitry Andric __v_.__annotate_increase(__n); 902e40139ffSDimitry Andric#endif 903e40139ffSDimitry Andric } 904e40139ffSDimitry Andric ~_ConstructTransaction() { 905e40139ffSDimitry Andric __v_.__end_ = __pos_; 906e40139ffSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN 907e40139ffSDimitry Andric if (__pos_ != __new_end_) { 908e40139ffSDimitry Andric __v_.__annotate_shrink(__new_end_ - __v_.__begin_); 909e40139ffSDimitry Andric } 910e40139ffSDimitry Andric#endif 911e40139ffSDimitry Andric } 912e40139ffSDimitry Andric 913e40139ffSDimitry Andric vector &__v_; 914e40139ffSDimitry Andric pointer __pos_; 915e40139ffSDimitry Andric const_pointer const __new_end_; 916e40139ffSDimitry Andric 917e40139ffSDimitry Andric private: 918e40139ffSDimitry Andric _ConstructTransaction(_ConstructTransaction const&) = delete; 919e40139ffSDimitry Andric _ConstructTransaction& operator=(_ConstructTransaction const&) = delete; 920e40139ffSDimitry Andric }; 921e40139ffSDimitry Andric 922e40139ffSDimitry Andric template <class ..._Args> 923e40139ffSDimitry Andric _LIBCPP_INLINE_VISIBILITY 924e40139ffSDimitry Andric void __construct_one_at_end(_Args&& ...__args) { 925e40139ffSDimitry Andric _ConstructTransaction __tx(*this, 1); 926480093f4SDimitry Andric __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__tx.__pos_), 927e40139ffSDimitry Andric _VSTD::forward<_Args>(__args)...); 928e40139ffSDimitry Andric ++__tx.__pos_; 929e40139ffSDimitry Andric } 9300b57cec5SDimitry Andric}; 9310b57cec5SDimitry Andric 9320b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES 9330b57cec5SDimitry Andrictemplate<class _InputIterator, 9340b57cec5SDimitry Andric class _Alloc = typename std::allocator<typename iterator_traits<_InputIterator>::value_type>, 9350b57cec5SDimitry Andric class = typename enable_if<__is_allocator<_Alloc>::value, void>::type 9360b57cec5SDimitry Andric > 9370b57cec5SDimitry Andricvector(_InputIterator, _InputIterator) 9380b57cec5SDimitry Andric -> vector<typename iterator_traits<_InputIterator>::value_type, _Alloc>; 9390b57cec5SDimitry Andric 9400b57cec5SDimitry Andrictemplate<class _InputIterator, 9410b57cec5SDimitry Andric class _Alloc, 9420b57cec5SDimitry Andric class = typename enable_if<__is_allocator<_Alloc>::value, void>::type 9430b57cec5SDimitry Andric > 9440b57cec5SDimitry Andricvector(_InputIterator, _InputIterator, _Alloc) 9450b57cec5SDimitry Andric -> vector<typename iterator_traits<_InputIterator>::value_type, _Alloc>; 9460b57cec5SDimitry Andric#endif 9470b57cec5SDimitry Andric 9480b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 9490b57cec5SDimitry Andricvoid 9500b57cec5SDimitry Andricvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v) 9510b57cec5SDimitry Andric{ 952e40139ffSDimitry Andric 9530b57cec5SDimitry Andric __annotate_delete(); 954e40139ffSDimitry Andric __alloc_traits::__construct_backward_with_exception_guarantees( 955e40139ffSDimitry Andric this->__alloc(), this->__begin_, this->__end_, __v.__begin_); 9560b57cec5SDimitry Andric _VSTD::swap(this->__begin_, __v.__begin_); 9570b57cec5SDimitry Andric _VSTD::swap(this->__end_, __v.__end_); 9580b57cec5SDimitry Andric _VSTD::swap(this->__end_cap(), __v.__end_cap()); 9590b57cec5SDimitry Andric __v.__first_ = __v.__begin_; 9600b57cec5SDimitry Andric __annotate_new(size()); 9610b57cec5SDimitry Andric __invalidate_all_iterators(); 9620b57cec5SDimitry Andric} 9630b57cec5SDimitry Andric 9640b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 9650b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::pointer 9660b57cec5SDimitry Andricvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p) 9670b57cec5SDimitry Andric{ 9680b57cec5SDimitry Andric __annotate_delete(); 9690b57cec5SDimitry Andric pointer __r = __v.__begin_; 970e40139ffSDimitry Andric __alloc_traits::__construct_backward_with_exception_guarantees( 971e40139ffSDimitry Andric this->__alloc(), this->__begin_, __p, __v.__begin_); 972e40139ffSDimitry Andric __alloc_traits::__construct_forward_with_exception_guarantees( 973e40139ffSDimitry Andric this->__alloc(), __p, this->__end_, __v.__end_); 9740b57cec5SDimitry Andric _VSTD::swap(this->__begin_, __v.__begin_); 9750b57cec5SDimitry Andric _VSTD::swap(this->__end_, __v.__end_); 9760b57cec5SDimitry Andric _VSTD::swap(this->__end_cap(), __v.__end_cap()); 9770b57cec5SDimitry Andric __v.__first_ = __v.__begin_; 9780b57cec5SDimitry Andric __annotate_new(size()); 9790b57cec5SDimitry Andric __invalidate_all_iterators(); 9800b57cec5SDimitry Andric return __r; 9810b57cec5SDimitry Andric} 9820b57cec5SDimitry Andric 9830b57cec5SDimitry Andric// Allocate space for __n objects 9840b57cec5SDimitry Andric// throws length_error if __n > max_size() 9850b57cec5SDimitry Andric// throws (probably bad_alloc) if memory run out 9860b57cec5SDimitry Andric// Precondition: __begin_ == __end_ == __end_cap() == 0 9870b57cec5SDimitry Andric// Precondition: __n > 0 9880b57cec5SDimitry Andric// Postcondition: capacity() == __n 9890b57cec5SDimitry Andric// Postcondition: size() == 0 9900b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 9910b57cec5SDimitry Andricvoid 9920b57cec5SDimitry Andricvector<_Tp, _Allocator>::__vallocate(size_type __n) 9930b57cec5SDimitry Andric{ 9940b57cec5SDimitry Andric if (__n > max_size()) 9950b57cec5SDimitry Andric this->__throw_length_error(); 9960b57cec5SDimitry Andric this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n); 9970b57cec5SDimitry Andric this->__end_cap() = this->__begin_ + __n; 9980b57cec5SDimitry Andric __annotate_new(0); 9990b57cec5SDimitry Andric} 10000b57cec5SDimitry Andric 10010b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 10020b57cec5SDimitry Andricvoid 10030b57cec5SDimitry Andricvector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT 10040b57cec5SDimitry Andric{ 10050b57cec5SDimitry Andric if (this->__begin_ != nullptr) 10060b57cec5SDimitry Andric { 10070b57cec5SDimitry Andric clear(); 10080b57cec5SDimitry Andric __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity()); 10090b57cec5SDimitry Andric this->__begin_ = this->__end_ = this->__end_cap() = nullptr; 10100b57cec5SDimitry Andric } 10110b57cec5SDimitry Andric} 10120b57cec5SDimitry Andric 10130b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 10140b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::size_type 10150b57cec5SDimitry Andricvector<_Tp, _Allocator>::max_size() const _NOEXCEPT 10160b57cec5SDimitry Andric{ 10170b57cec5SDimitry Andric return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()), 10180b57cec5SDimitry Andric numeric_limits<difference_type>::max()); 10190b57cec5SDimitry Andric} 10200b57cec5SDimitry Andric 10210b57cec5SDimitry Andric// Precondition: __new_size > capacity() 10220b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 10230b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 10240b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::size_type 10250b57cec5SDimitry Andricvector<_Tp, _Allocator>::__recommend(size_type __new_size) const 10260b57cec5SDimitry Andric{ 10270b57cec5SDimitry Andric const size_type __ms = max_size(); 10280b57cec5SDimitry Andric if (__new_size > __ms) 10290b57cec5SDimitry Andric this->__throw_length_error(); 10300b57cec5SDimitry Andric const size_type __cap = capacity(); 10310b57cec5SDimitry Andric if (__cap >= __ms / 2) 10320b57cec5SDimitry Andric return __ms; 10330b57cec5SDimitry Andric return _VSTD::max<size_type>(2*__cap, __new_size); 10340b57cec5SDimitry Andric} 10350b57cec5SDimitry Andric 10360b57cec5SDimitry Andric// Default constructs __n objects starting at __end_ 10370b57cec5SDimitry Andric// throws if construction throws 10380b57cec5SDimitry Andric// Precondition: __n > 0 10390b57cec5SDimitry Andric// Precondition: size() + __n <= capacity() 10400b57cec5SDimitry Andric// Postcondition: size() == size() + __n 10410b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 10420b57cec5SDimitry Andricvoid 10430b57cec5SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(size_type __n) 10440b57cec5SDimitry Andric{ 1045e40139ffSDimitry Andric _ConstructTransaction __tx(*this, __n); 1046*5ffd83dbSDimitry Andric const_pointer __new_end = __tx.__new_end_; 1047*5ffd83dbSDimitry Andric for (pointer __pos = __tx.__pos_; __pos != __new_end; ++__pos, __tx.__pos_ = __pos) { 1048*5ffd83dbSDimitry Andric __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos)); 1049e40139ffSDimitry Andric } 10500b57cec5SDimitry Andric} 10510b57cec5SDimitry Andric 10520b57cec5SDimitry Andric// Copy constructs __n objects starting at __end_ from __x 10530b57cec5SDimitry Andric// throws if construction throws 10540b57cec5SDimitry Andric// Precondition: __n > 0 10550b57cec5SDimitry Andric// Precondition: size() + __n <= capacity() 10560b57cec5SDimitry Andric// Postcondition: size() == old size() + __n 10570b57cec5SDimitry Andric// Postcondition: [i] == __x for all i in [size() - __n, __n) 10580b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 10590b57cec5SDimitry Andricinline 10600b57cec5SDimitry Andricvoid 10610b57cec5SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) 10620b57cec5SDimitry Andric{ 1063e40139ffSDimitry Andric _ConstructTransaction __tx(*this, __n); 1064*5ffd83dbSDimitry Andric const_pointer __new_end = __tx.__new_end_; 1065*5ffd83dbSDimitry Andric for (pointer __pos = __tx.__pos_; __pos != __new_end; ++__pos, __tx.__pos_ = __pos) { 1066*5ffd83dbSDimitry Andric __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos), __x); 1067e40139ffSDimitry Andric } 10680b57cec5SDimitry Andric} 10690b57cec5SDimitry Andric 10700b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 10710b57cec5SDimitry Andrictemplate <class _ForwardIterator> 10720b57cec5SDimitry Andrictypename enable_if 10730b57cec5SDimitry Andric< 1074480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 10750b57cec5SDimitry Andric void 10760b57cec5SDimitry Andric>::type 10770b57cec5SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n) 10780b57cec5SDimitry Andric{ 1079e40139ffSDimitry Andric _ConstructTransaction __tx(*this, __n); 1080e40139ffSDimitry Andric __alloc_traits::__construct_range_forward(this->__alloc(), __first, __last, __tx.__pos_); 10810b57cec5SDimitry Andric} 10820b57cec5SDimitry Andric 10830b57cec5SDimitry Andric// Default constructs __n objects starting at __end_ 10840b57cec5SDimitry Andric// throws if construction throws 10850b57cec5SDimitry Andric// Postcondition: size() == size() + __n 10860b57cec5SDimitry Andric// Exception safety: strong. 10870b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 10880b57cec5SDimitry Andricvoid 10890b57cec5SDimitry Andricvector<_Tp, _Allocator>::__append(size_type __n) 10900b57cec5SDimitry Andric{ 10910b57cec5SDimitry Andric if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) 10920b57cec5SDimitry Andric this->__construct_at_end(__n); 10930b57cec5SDimitry Andric else 10940b57cec5SDimitry Andric { 10950b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 10960b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); 10970b57cec5SDimitry Andric __v.__construct_at_end(__n); 10980b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 10990b57cec5SDimitry Andric } 11000b57cec5SDimitry Andric} 11010b57cec5SDimitry Andric 11020b57cec5SDimitry Andric// Default constructs __n objects starting at __end_ 11030b57cec5SDimitry Andric// throws if construction throws 11040b57cec5SDimitry Andric// Postcondition: size() == size() + __n 11050b57cec5SDimitry Andric// Exception safety: strong. 11060b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11070b57cec5SDimitry Andricvoid 11080b57cec5SDimitry Andricvector<_Tp, _Allocator>::__append(size_type __n, const_reference __x) 11090b57cec5SDimitry Andric{ 11100b57cec5SDimitry Andric if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) 11110b57cec5SDimitry Andric this->__construct_at_end(__n, __x); 11120b57cec5SDimitry Andric else 11130b57cec5SDimitry Andric { 11140b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 11150b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); 11160b57cec5SDimitry Andric __v.__construct_at_end(__n, __x); 11170b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 11180b57cec5SDimitry Andric } 11190b57cec5SDimitry Andric} 11200b57cec5SDimitry Andric 11210b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11220b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n) 11230b57cec5SDimitry Andric{ 11240b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 11250b57cec5SDimitry Andric __get_db()->__insert_c(this); 11260b57cec5SDimitry Andric#endif 11270b57cec5SDimitry Andric if (__n > 0) 11280b57cec5SDimitry Andric { 11290b57cec5SDimitry Andric __vallocate(__n); 11300b57cec5SDimitry Andric __construct_at_end(__n); 11310b57cec5SDimitry Andric } 11320b57cec5SDimitry Andric} 11330b57cec5SDimitry Andric 11340b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 11350b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11360b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a) 11370b57cec5SDimitry Andric : __base(__a) 11380b57cec5SDimitry Andric{ 11390b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 11400b57cec5SDimitry Andric __get_db()->__insert_c(this); 11410b57cec5SDimitry Andric#endif 11420b57cec5SDimitry Andric if (__n > 0) 11430b57cec5SDimitry Andric { 11440b57cec5SDimitry Andric __vallocate(__n); 11450b57cec5SDimitry Andric __construct_at_end(__n); 11460b57cec5SDimitry Andric } 11470b57cec5SDimitry Andric} 11480b57cec5SDimitry Andric#endif 11490b57cec5SDimitry Andric 11500b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11510b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x) 11520b57cec5SDimitry Andric{ 11530b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 11540b57cec5SDimitry Andric __get_db()->__insert_c(this); 11550b57cec5SDimitry Andric#endif 11560b57cec5SDimitry Andric if (__n > 0) 11570b57cec5SDimitry Andric { 11580b57cec5SDimitry Andric __vallocate(__n); 11590b57cec5SDimitry Andric __construct_at_end(__n, __x); 11600b57cec5SDimitry Andric } 11610b57cec5SDimitry Andric} 11620b57cec5SDimitry Andric 11630b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11640b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a) 11650b57cec5SDimitry Andric : __base(__a) 11660b57cec5SDimitry Andric{ 11670b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 11680b57cec5SDimitry Andric __get_db()->__insert_c(this); 11690b57cec5SDimitry Andric#endif 11700b57cec5SDimitry Andric if (__n > 0) 11710b57cec5SDimitry Andric { 11720b57cec5SDimitry Andric __vallocate(__n); 11730b57cec5SDimitry Andric __construct_at_end(__n, __x); 11740b57cec5SDimitry Andric } 11750b57cec5SDimitry Andric} 11760b57cec5SDimitry Andric 11770b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11780b57cec5SDimitry Andrictemplate <class _InputIterator> 11790b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_InputIterator __first, 1180480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 1181480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value && 11820b57cec5SDimitry Andric is_constructible< 11830b57cec5SDimitry Andric value_type, 11840b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 11850b57cec5SDimitry Andric _InputIterator>::type __last) 11860b57cec5SDimitry Andric{ 11870b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 11880b57cec5SDimitry Andric __get_db()->__insert_c(this); 11890b57cec5SDimitry Andric#endif 11900b57cec5SDimitry Andric for (; __first != __last; ++__first) 11910b57cec5SDimitry Andric __emplace_back(*__first); 11920b57cec5SDimitry Andric} 11930b57cec5SDimitry Andric 11940b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11950b57cec5SDimitry Andrictemplate <class _InputIterator> 11960b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 1197480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 1198480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value && 11990b57cec5SDimitry Andric is_constructible< 12000b57cec5SDimitry Andric value_type, 12010b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value>::type*) 12020b57cec5SDimitry Andric : __base(__a) 12030b57cec5SDimitry Andric{ 12040b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 12050b57cec5SDimitry Andric __get_db()->__insert_c(this); 12060b57cec5SDimitry Andric#endif 12070b57cec5SDimitry Andric for (; __first != __last; ++__first) 12080b57cec5SDimitry Andric __emplace_back(*__first); 12090b57cec5SDimitry Andric} 12100b57cec5SDimitry Andric 12110b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 12120b57cec5SDimitry Andrictemplate <class _ForwardIterator> 12130b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_ForwardIterator __first, 1214480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value && 12150b57cec5SDimitry Andric is_constructible< 12160b57cec5SDimitry Andric value_type, 12170b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 12180b57cec5SDimitry Andric _ForwardIterator>::type __last) 12190b57cec5SDimitry Andric{ 12200b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 12210b57cec5SDimitry Andric __get_db()->__insert_c(this); 12220b57cec5SDimitry Andric#endif 12230b57cec5SDimitry Andric size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 12240b57cec5SDimitry Andric if (__n > 0) 12250b57cec5SDimitry Andric { 12260b57cec5SDimitry Andric __vallocate(__n); 12270b57cec5SDimitry Andric __construct_at_end(__first, __last, __n); 12280b57cec5SDimitry Andric } 12290b57cec5SDimitry Andric} 12300b57cec5SDimitry Andric 12310b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 12320b57cec5SDimitry Andrictemplate <class _ForwardIterator> 12330b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 1234480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value && 12350b57cec5SDimitry Andric is_constructible< 12360b57cec5SDimitry Andric value_type, 12370b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value>::type*) 12380b57cec5SDimitry Andric : __base(__a) 12390b57cec5SDimitry Andric{ 12400b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 12410b57cec5SDimitry Andric __get_db()->__insert_c(this); 12420b57cec5SDimitry Andric#endif 12430b57cec5SDimitry Andric size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 12440b57cec5SDimitry Andric if (__n > 0) 12450b57cec5SDimitry Andric { 12460b57cec5SDimitry Andric __vallocate(__n); 12470b57cec5SDimitry Andric __construct_at_end(__first, __last, __n); 12480b57cec5SDimitry Andric } 12490b57cec5SDimitry Andric} 12500b57cec5SDimitry Andric 12510b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 12520b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(const vector& __x) 12530b57cec5SDimitry Andric : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc())) 12540b57cec5SDimitry Andric{ 12550b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 12560b57cec5SDimitry Andric __get_db()->__insert_c(this); 12570b57cec5SDimitry Andric#endif 12580b57cec5SDimitry Andric size_type __n = __x.size(); 12590b57cec5SDimitry Andric if (__n > 0) 12600b57cec5SDimitry Andric { 12610b57cec5SDimitry Andric __vallocate(__n); 12620b57cec5SDimitry Andric __construct_at_end(__x.__begin_, __x.__end_, __n); 12630b57cec5SDimitry Andric } 12640b57cec5SDimitry Andric} 12650b57cec5SDimitry Andric 12660b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 12670b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a) 12680b57cec5SDimitry Andric : __base(__a) 12690b57cec5SDimitry Andric{ 12700b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 12710b57cec5SDimitry Andric __get_db()->__insert_c(this); 12720b57cec5SDimitry Andric#endif 12730b57cec5SDimitry Andric size_type __n = __x.size(); 12740b57cec5SDimitry Andric if (__n > 0) 12750b57cec5SDimitry Andric { 12760b57cec5SDimitry Andric __vallocate(__n); 12770b57cec5SDimitry Andric __construct_at_end(__x.__begin_, __x.__end_, __n); 12780b57cec5SDimitry Andric } 12790b57cec5SDimitry Andric} 12800b57cec5SDimitry Andric 12810b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 12820b57cec5SDimitry Andric 12830b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 12840b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 12850b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(vector&& __x) 12860b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 12870b57cec5SDimitry Andric _NOEXCEPT 12880b57cec5SDimitry Andric#else 12890b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 12900b57cec5SDimitry Andric#endif 12910b57cec5SDimitry Andric : __base(_VSTD::move(__x.__alloc())) 12920b57cec5SDimitry Andric{ 12930b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 12940b57cec5SDimitry Andric __get_db()->__insert_c(this); 12950b57cec5SDimitry Andric __get_db()->swap(this, &__x); 12960b57cec5SDimitry Andric#endif 12970b57cec5SDimitry Andric this->__begin_ = __x.__begin_; 12980b57cec5SDimitry Andric this->__end_ = __x.__end_; 12990b57cec5SDimitry Andric this->__end_cap() = __x.__end_cap(); 13000b57cec5SDimitry Andric __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; 13010b57cec5SDimitry Andric} 13020b57cec5SDimitry Andric 13030b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 13040b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 13050b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a) 13060b57cec5SDimitry Andric : __base(__a) 13070b57cec5SDimitry Andric{ 13080b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 13090b57cec5SDimitry Andric __get_db()->__insert_c(this); 13100b57cec5SDimitry Andric#endif 13110b57cec5SDimitry Andric if (__a == __x.__alloc()) 13120b57cec5SDimitry Andric { 13130b57cec5SDimitry Andric this->__begin_ = __x.__begin_; 13140b57cec5SDimitry Andric this->__end_ = __x.__end_; 13150b57cec5SDimitry Andric this->__end_cap() = __x.__end_cap(); 13160b57cec5SDimitry Andric __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; 13170b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 13180b57cec5SDimitry Andric __get_db()->swap(this, &__x); 13190b57cec5SDimitry Andric#endif 13200b57cec5SDimitry Andric } 13210b57cec5SDimitry Andric else 13220b57cec5SDimitry Andric { 13230b57cec5SDimitry Andric typedef move_iterator<iterator> _Ip; 13240b57cec5SDimitry Andric assign(_Ip(__x.begin()), _Ip(__x.end())); 13250b57cec5SDimitry Andric } 13260b57cec5SDimitry Andric} 13270b57cec5SDimitry Andric 13280b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 13290b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 13300b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il) 13310b57cec5SDimitry Andric{ 13320b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 13330b57cec5SDimitry Andric __get_db()->__insert_c(this); 13340b57cec5SDimitry Andric#endif 13350b57cec5SDimitry Andric if (__il.size() > 0) 13360b57cec5SDimitry Andric { 13370b57cec5SDimitry Andric __vallocate(__il.size()); 13380b57cec5SDimitry Andric __construct_at_end(__il.begin(), __il.end(), __il.size()); 13390b57cec5SDimitry Andric } 13400b57cec5SDimitry Andric} 13410b57cec5SDimitry Andric 13420b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 13430b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 13440b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) 13450b57cec5SDimitry Andric : __base(__a) 13460b57cec5SDimitry Andric{ 13470b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 13480b57cec5SDimitry Andric __get_db()->__insert_c(this); 13490b57cec5SDimitry Andric#endif 13500b57cec5SDimitry Andric if (__il.size() > 0) 13510b57cec5SDimitry Andric { 13520b57cec5SDimitry Andric __vallocate(__il.size()); 13530b57cec5SDimitry Andric __construct_at_end(__il.begin(), __il.end(), __il.size()); 13540b57cec5SDimitry Andric } 13550b57cec5SDimitry Andric} 13560b57cec5SDimitry Andric 13570b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 13580b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 13590b57cec5SDimitry Andricvector<_Tp, _Allocator>& 13600b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator=(vector&& __x) 13610b57cec5SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) 13620b57cec5SDimitry Andric{ 13630b57cec5SDimitry Andric __move_assign(__x, integral_constant<bool, 13640b57cec5SDimitry Andric __alloc_traits::propagate_on_container_move_assignment::value>()); 13650b57cec5SDimitry Andric return *this; 13660b57cec5SDimitry Andric} 13670b57cec5SDimitry Andric 13680b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 13690b57cec5SDimitry Andricvoid 13700b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_assign(vector& __c, false_type) 13710b57cec5SDimitry Andric _NOEXCEPT_(__alloc_traits::is_always_equal::value) 13720b57cec5SDimitry Andric{ 13730b57cec5SDimitry Andric if (__base::__alloc() != __c.__alloc()) 13740b57cec5SDimitry Andric { 13750b57cec5SDimitry Andric typedef move_iterator<iterator> _Ip; 13760b57cec5SDimitry Andric assign(_Ip(__c.begin()), _Ip(__c.end())); 13770b57cec5SDimitry Andric } 13780b57cec5SDimitry Andric else 13790b57cec5SDimitry Andric __move_assign(__c, true_type()); 13800b57cec5SDimitry Andric} 13810b57cec5SDimitry Andric 13820b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 13830b57cec5SDimitry Andricvoid 13840b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_assign(vector& __c, true_type) 13850b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 13860b57cec5SDimitry Andric{ 13870b57cec5SDimitry Andric __vdeallocate(); 13880b57cec5SDimitry Andric __base::__move_assign_alloc(__c); // this can throw 13890b57cec5SDimitry Andric this->__begin_ = __c.__begin_; 13900b57cec5SDimitry Andric this->__end_ = __c.__end_; 13910b57cec5SDimitry Andric this->__end_cap() = __c.__end_cap(); 13920b57cec5SDimitry Andric __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr; 13930b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 13940b57cec5SDimitry Andric __get_db()->swap(this, &__c); 13950b57cec5SDimitry Andric#endif 13960b57cec5SDimitry Andric} 13970b57cec5SDimitry Andric 13980b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG 13990b57cec5SDimitry Andric 14000b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 14010b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 14020b57cec5SDimitry Andricvector<_Tp, _Allocator>& 14030b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator=(const vector& __x) 14040b57cec5SDimitry Andric{ 14050b57cec5SDimitry Andric if (this != &__x) 14060b57cec5SDimitry Andric { 14070b57cec5SDimitry Andric __base::__copy_assign_alloc(__x); 14080b57cec5SDimitry Andric assign(__x.__begin_, __x.__end_); 14090b57cec5SDimitry Andric } 14100b57cec5SDimitry Andric return *this; 14110b57cec5SDimitry Andric} 14120b57cec5SDimitry Andric 14130b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 14140b57cec5SDimitry Andrictemplate <class _InputIterator> 14150b57cec5SDimitry Andrictypename enable_if 14160b57cec5SDimitry Andric< 1417480093f4SDimitry Andric __is_cpp17_input_iterator <_InputIterator>::value && 1418480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value && 14190b57cec5SDimitry Andric is_constructible< 14200b57cec5SDimitry Andric _Tp, 14210b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 14220b57cec5SDimitry Andric void 14230b57cec5SDimitry Andric>::type 14240b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last) 14250b57cec5SDimitry Andric{ 14260b57cec5SDimitry Andric clear(); 14270b57cec5SDimitry Andric for (; __first != __last; ++__first) 14280b57cec5SDimitry Andric __emplace_back(*__first); 14290b57cec5SDimitry Andric} 14300b57cec5SDimitry Andric 14310b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 14320b57cec5SDimitry Andrictemplate <class _ForwardIterator> 14330b57cec5SDimitry Andrictypename enable_if 14340b57cec5SDimitry Andric< 1435480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value && 14360b57cec5SDimitry Andric is_constructible< 14370b57cec5SDimitry Andric _Tp, 14380b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 14390b57cec5SDimitry Andric void 14400b57cec5SDimitry Andric>::type 14410b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) 14420b57cec5SDimitry Andric{ 14430b57cec5SDimitry Andric size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last)); 14440b57cec5SDimitry Andric if (__new_size <= capacity()) 14450b57cec5SDimitry Andric { 14460b57cec5SDimitry Andric _ForwardIterator __mid = __last; 14470b57cec5SDimitry Andric bool __growing = false; 14480b57cec5SDimitry Andric if (__new_size > size()) 14490b57cec5SDimitry Andric { 14500b57cec5SDimitry Andric __growing = true; 14510b57cec5SDimitry Andric __mid = __first; 14520b57cec5SDimitry Andric _VSTD::advance(__mid, size()); 14530b57cec5SDimitry Andric } 14540b57cec5SDimitry Andric pointer __m = _VSTD::copy(__first, __mid, this->__begin_); 14550b57cec5SDimitry Andric if (__growing) 14560b57cec5SDimitry Andric __construct_at_end(__mid, __last, __new_size - size()); 14570b57cec5SDimitry Andric else 14580b57cec5SDimitry Andric this->__destruct_at_end(__m); 14590b57cec5SDimitry Andric } 14600b57cec5SDimitry Andric else 14610b57cec5SDimitry Andric { 14620b57cec5SDimitry Andric __vdeallocate(); 14630b57cec5SDimitry Andric __vallocate(__recommend(__new_size)); 14640b57cec5SDimitry Andric __construct_at_end(__first, __last, __new_size); 14650b57cec5SDimitry Andric } 14660b57cec5SDimitry Andric __invalidate_all_iterators(); 14670b57cec5SDimitry Andric} 14680b57cec5SDimitry Andric 14690b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 14700b57cec5SDimitry Andricvoid 14710b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(size_type __n, const_reference __u) 14720b57cec5SDimitry Andric{ 14730b57cec5SDimitry Andric if (__n <= capacity()) 14740b57cec5SDimitry Andric { 14750b57cec5SDimitry Andric size_type __s = size(); 14760b57cec5SDimitry Andric _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u); 14770b57cec5SDimitry Andric if (__n > __s) 14780b57cec5SDimitry Andric __construct_at_end(__n - __s, __u); 14790b57cec5SDimitry Andric else 14800b57cec5SDimitry Andric this->__destruct_at_end(this->__begin_ + __n); 14810b57cec5SDimitry Andric } 14820b57cec5SDimitry Andric else 14830b57cec5SDimitry Andric { 14840b57cec5SDimitry Andric __vdeallocate(); 14850b57cec5SDimitry Andric __vallocate(__recommend(static_cast<size_type>(__n))); 14860b57cec5SDimitry Andric __construct_at_end(__n, __u); 14870b57cec5SDimitry Andric } 14880b57cec5SDimitry Andric __invalidate_all_iterators(); 14890b57cec5SDimitry Andric} 14900b57cec5SDimitry Andric 14910b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 14920b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 14930b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 14940b57cec5SDimitry Andricvector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT 14950b57cec5SDimitry Andric{ 14960b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 14970b57cec5SDimitry Andric return iterator(this, __p); 14980b57cec5SDimitry Andric#else 14990b57cec5SDimitry Andric return iterator(__p); 15000b57cec5SDimitry Andric#endif 15010b57cec5SDimitry Andric} 15020b57cec5SDimitry Andric 15030b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 15040b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 15050b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_iterator 15060b57cec5SDimitry Andricvector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT 15070b57cec5SDimitry Andric{ 15080b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 15090b57cec5SDimitry Andric return const_iterator(this, __p); 15100b57cec5SDimitry Andric#else 15110b57cec5SDimitry Andric return const_iterator(__p); 15120b57cec5SDimitry Andric#endif 15130b57cec5SDimitry Andric} 15140b57cec5SDimitry Andric 15150b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 15160b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 15170b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 15180b57cec5SDimitry Andricvector<_Tp, _Allocator>::begin() _NOEXCEPT 15190b57cec5SDimitry Andric{ 15200b57cec5SDimitry Andric return __make_iter(this->__begin_); 15210b57cec5SDimitry Andric} 15220b57cec5SDimitry Andric 15230b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 15240b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 15250b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_iterator 15260b57cec5SDimitry Andricvector<_Tp, _Allocator>::begin() const _NOEXCEPT 15270b57cec5SDimitry Andric{ 15280b57cec5SDimitry Andric return __make_iter(this->__begin_); 15290b57cec5SDimitry Andric} 15300b57cec5SDimitry Andric 15310b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 15320b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 15330b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 15340b57cec5SDimitry Andricvector<_Tp, _Allocator>::end() _NOEXCEPT 15350b57cec5SDimitry Andric{ 15360b57cec5SDimitry Andric return __make_iter(this->__end_); 15370b57cec5SDimitry Andric} 15380b57cec5SDimitry Andric 15390b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 15400b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 15410b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_iterator 15420b57cec5SDimitry Andricvector<_Tp, _Allocator>::end() const _NOEXCEPT 15430b57cec5SDimitry Andric{ 15440b57cec5SDimitry Andric return __make_iter(this->__end_); 15450b57cec5SDimitry Andric} 15460b57cec5SDimitry Andric 15470b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 15480b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 15490b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference 15500b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT 15510b57cec5SDimitry Andric{ 15520b57cec5SDimitry Andric _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); 15530b57cec5SDimitry Andric return this->__begin_[__n]; 15540b57cec5SDimitry Andric} 15550b57cec5SDimitry Andric 15560b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 15570b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 15580b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_reference 15590b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT 15600b57cec5SDimitry Andric{ 15610b57cec5SDimitry Andric _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); 15620b57cec5SDimitry Andric return this->__begin_[__n]; 15630b57cec5SDimitry Andric} 15640b57cec5SDimitry Andric 15650b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 15660b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference 15670b57cec5SDimitry Andricvector<_Tp, _Allocator>::at(size_type __n) 15680b57cec5SDimitry Andric{ 15690b57cec5SDimitry Andric if (__n >= size()) 15700b57cec5SDimitry Andric this->__throw_out_of_range(); 15710b57cec5SDimitry Andric return this->__begin_[__n]; 15720b57cec5SDimitry Andric} 15730b57cec5SDimitry Andric 15740b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 15750b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_reference 15760b57cec5SDimitry Andricvector<_Tp, _Allocator>::at(size_type __n) const 15770b57cec5SDimitry Andric{ 15780b57cec5SDimitry Andric if (__n >= size()) 15790b57cec5SDimitry Andric this->__throw_out_of_range(); 15800b57cec5SDimitry Andric return this->__begin_[__n]; 15810b57cec5SDimitry Andric} 15820b57cec5SDimitry Andric 15830b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 15840b57cec5SDimitry Andricvoid 15850b57cec5SDimitry Andricvector<_Tp, _Allocator>::reserve(size_type __n) 15860b57cec5SDimitry Andric{ 15870b57cec5SDimitry Andric if (__n > capacity()) 15880b57cec5SDimitry Andric { 15890b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 15900b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__n, size(), __a); 15910b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 15920b57cec5SDimitry Andric } 15930b57cec5SDimitry Andric} 15940b57cec5SDimitry Andric 15950b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 15960b57cec5SDimitry Andricvoid 15970b57cec5SDimitry Andricvector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT 15980b57cec5SDimitry Andric{ 15990b57cec5SDimitry Andric if (capacity() > size()) 16000b57cec5SDimitry Andric { 16010b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 16020b57cec5SDimitry Andric try 16030b57cec5SDimitry Andric { 16040b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 16050b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 16060b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(size(), size(), __a); 16070b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 16080b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 16090b57cec5SDimitry Andric } 16100b57cec5SDimitry Andric catch (...) 16110b57cec5SDimitry Andric { 16120b57cec5SDimitry Andric } 16130b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 16140b57cec5SDimitry Andric } 16150b57cec5SDimitry Andric} 16160b57cec5SDimitry Andric 16170b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16180b57cec5SDimitry Andrictemplate <class _Up> 16190b57cec5SDimitry Andricvoid 16200b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 16210b57cec5SDimitry Andricvector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x) 16220b57cec5SDimitry Andric#else 16230b57cec5SDimitry Andricvector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x) 16240b57cec5SDimitry Andric#endif 16250b57cec5SDimitry Andric{ 16260b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 16270b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); 16280b57cec5SDimitry Andric // __v.push_back(_VSTD::forward<_Up>(__x)); 1629480093f4SDimitry Andric __alloc_traits::construct(__a, _VSTD::__to_address(__v.__end_), _VSTD::forward<_Up>(__x)); 16300b57cec5SDimitry Andric __v.__end_++; 16310b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 16320b57cec5SDimitry Andric} 16330b57cec5SDimitry Andric 16340b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16350b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 16360b57cec5SDimitry Andricvoid 16370b57cec5SDimitry Andricvector<_Tp, _Allocator>::push_back(const_reference __x) 16380b57cec5SDimitry Andric{ 16390b57cec5SDimitry Andric if (this->__end_ != this->__end_cap()) 16400b57cec5SDimitry Andric { 1641e40139ffSDimitry Andric __construct_one_at_end(__x); 16420b57cec5SDimitry Andric } 16430b57cec5SDimitry Andric else 16440b57cec5SDimitry Andric __push_back_slow_path(__x); 16450b57cec5SDimitry Andric} 16460b57cec5SDimitry Andric 16470b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 16480b57cec5SDimitry Andric 16490b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16500b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 16510b57cec5SDimitry Andricvoid 16520b57cec5SDimitry Andricvector<_Tp, _Allocator>::push_back(value_type&& __x) 16530b57cec5SDimitry Andric{ 16540b57cec5SDimitry Andric if (this->__end_ < this->__end_cap()) 16550b57cec5SDimitry Andric { 1656e40139ffSDimitry Andric __construct_one_at_end(_VSTD::move(__x)); 16570b57cec5SDimitry Andric } 16580b57cec5SDimitry Andric else 16590b57cec5SDimitry Andric __push_back_slow_path(_VSTD::move(__x)); 16600b57cec5SDimitry Andric} 16610b57cec5SDimitry Andric 16620b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16630b57cec5SDimitry Andrictemplate <class... _Args> 16640b57cec5SDimitry Andricvoid 16650b57cec5SDimitry Andricvector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args) 16660b57cec5SDimitry Andric{ 16670b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 16680b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); 16690b57cec5SDimitry Andric// __v.emplace_back(_VSTD::forward<_Args>(__args)...); 1670480093f4SDimitry Andric __alloc_traits::construct(__a, _VSTD::__to_address(__v.__end_), _VSTD::forward<_Args>(__args)...); 16710b57cec5SDimitry Andric __v.__end_++; 16720b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 16730b57cec5SDimitry Andric} 16740b57cec5SDimitry Andric 16750b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16760b57cec5SDimitry Andrictemplate <class... _Args> 16770b57cec5SDimitry Andricinline 16780b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 16790b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference 16800b57cec5SDimitry Andric#else 16810b57cec5SDimitry Andricvoid 16820b57cec5SDimitry Andric#endif 16830b57cec5SDimitry Andricvector<_Tp, _Allocator>::emplace_back(_Args&&... __args) 16840b57cec5SDimitry Andric{ 16850b57cec5SDimitry Andric if (this->__end_ < this->__end_cap()) 16860b57cec5SDimitry Andric { 1687e40139ffSDimitry Andric __construct_one_at_end(_VSTD::forward<_Args>(__args)...); 16880b57cec5SDimitry Andric } 16890b57cec5SDimitry Andric else 16900b57cec5SDimitry Andric __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...); 16910b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 16920b57cec5SDimitry Andric return this->back(); 16930b57cec5SDimitry Andric#endif 16940b57cec5SDimitry Andric} 16950b57cec5SDimitry Andric 16960b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG 16970b57cec5SDimitry Andric 16980b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16990b57cec5SDimitry Andricinline 17000b57cec5SDimitry Andricvoid 17010b57cec5SDimitry Andricvector<_Tp, _Allocator>::pop_back() 17020b57cec5SDimitry Andric{ 17030b57cec5SDimitry Andric _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector"); 17040b57cec5SDimitry Andric this->__destruct_at_end(this->__end_ - 1); 17050b57cec5SDimitry Andric} 17060b57cec5SDimitry Andric 17070b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 17080b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 17090b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 17100b57cec5SDimitry Andricvector<_Tp, _Allocator>::erase(const_iterator __position) 17110b57cec5SDimitry Andric{ 17120b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 17130b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 17140b57cec5SDimitry Andric "vector::erase(iterator) called with an iterator not" 17150b57cec5SDimitry Andric " referring to this vector"); 17160b57cec5SDimitry Andric#endif 17170b57cec5SDimitry Andric _LIBCPP_ASSERT(__position != end(), 17180b57cec5SDimitry Andric "vector::erase(iterator) called with a non-dereferenceable iterator"); 17190b57cec5SDimitry Andric difference_type __ps = __position - cbegin(); 17200b57cec5SDimitry Andric pointer __p = this->__begin_ + __ps; 17210b57cec5SDimitry Andric this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p)); 17220b57cec5SDimitry Andric this->__invalidate_iterators_past(__p-1); 17230b57cec5SDimitry Andric iterator __r = __make_iter(__p); 17240b57cec5SDimitry Andric return __r; 17250b57cec5SDimitry Andric} 17260b57cec5SDimitry Andric 17270b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 17280b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 17290b57cec5SDimitry Andricvector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) 17300b57cec5SDimitry Andric{ 17310b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 17320b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, 17330b57cec5SDimitry Andric "vector::erase(iterator, iterator) called with an iterator not" 17340b57cec5SDimitry Andric " referring to this vector"); 17350b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this, 17360b57cec5SDimitry Andric "vector::erase(iterator, iterator) called with an iterator not" 17370b57cec5SDimitry Andric " referring to this vector"); 17380b57cec5SDimitry Andric#endif 17390b57cec5SDimitry Andric _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range"); 17400b57cec5SDimitry Andric pointer __p = this->__begin_ + (__first - begin()); 17410b57cec5SDimitry Andric if (__first != __last) { 17420b57cec5SDimitry Andric this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p)); 17430b57cec5SDimitry Andric this->__invalidate_iterators_past(__p - 1); 17440b57cec5SDimitry Andric } 17450b57cec5SDimitry Andric iterator __r = __make_iter(__p); 17460b57cec5SDimitry Andric return __r; 17470b57cec5SDimitry Andric} 17480b57cec5SDimitry Andric 17490b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 17500b57cec5SDimitry Andricvoid 17510b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to) 17520b57cec5SDimitry Andric{ 17530b57cec5SDimitry Andric pointer __old_last = this->__end_; 17540b57cec5SDimitry Andric difference_type __n = __old_last - __to; 1755e40139ffSDimitry Andric { 1756e40139ffSDimitry Andric pointer __i = __from_s + __n; 1757e40139ffSDimitry Andric _ConstructTransaction __tx(*this, __from_e - __i); 1758*5ffd83dbSDimitry Andric for (pointer __pos = __tx.__pos_; __i < __from_e; 1759*5ffd83dbSDimitry Andric ++__i, ++__pos, __tx.__pos_ = __pos) { 17600b57cec5SDimitry Andric __alloc_traits::construct(this->__alloc(), 1761*5ffd83dbSDimitry Andric _VSTD::__to_address(__pos), 17620b57cec5SDimitry Andric _VSTD::move(*__i)); 1763e40139ffSDimitry Andric } 1764e40139ffSDimitry Andric } 17650b57cec5SDimitry Andric _VSTD::move_backward(__from_s, __from_s + __n, __old_last); 17660b57cec5SDimitry Andric} 17670b57cec5SDimitry Andric 17680b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 17690b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 17700b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) 17710b57cec5SDimitry Andric{ 17720b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 17730b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 17740b57cec5SDimitry Andric "vector::insert(iterator, x) called with an iterator not" 17750b57cec5SDimitry Andric " referring to this vector"); 17760b57cec5SDimitry Andric#endif 17770b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 17780b57cec5SDimitry Andric if (this->__end_ < this->__end_cap()) 17790b57cec5SDimitry Andric { 17800b57cec5SDimitry Andric if (__p == this->__end_) 17810b57cec5SDimitry Andric { 1782e40139ffSDimitry Andric __construct_one_at_end(__x); 17830b57cec5SDimitry Andric } 17840b57cec5SDimitry Andric else 17850b57cec5SDimitry Andric { 17860b57cec5SDimitry Andric __move_range(__p, this->__end_, __p + 1); 17870b57cec5SDimitry Andric const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); 17880b57cec5SDimitry Andric if (__p <= __xr && __xr < this->__end_) 17890b57cec5SDimitry Andric ++__xr; 17900b57cec5SDimitry Andric *__p = *__xr; 17910b57cec5SDimitry Andric } 17920b57cec5SDimitry Andric } 17930b57cec5SDimitry Andric else 17940b57cec5SDimitry Andric { 17950b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 17960b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 17970b57cec5SDimitry Andric __v.push_back(__x); 17980b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 17990b57cec5SDimitry Andric } 18000b57cec5SDimitry Andric return __make_iter(__p); 18010b57cec5SDimitry Andric} 18020b57cec5SDimitry Andric 18030b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 18040b57cec5SDimitry Andric 18050b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 18060b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 18070b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) 18080b57cec5SDimitry Andric{ 18090b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 18100b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 18110b57cec5SDimitry Andric "vector::insert(iterator, x) called with an iterator not" 18120b57cec5SDimitry Andric " referring to this vector"); 18130b57cec5SDimitry Andric#endif 18140b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 18150b57cec5SDimitry Andric if (this->__end_ < this->__end_cap()) 18160b57cec5SDimitry Andric { 18170b57cec5SDimitry Andric if (__p == this->__end_) 18180b57cec5SDimitry Andric { 1819e40139ffSDimitry Andric __construct_one_at_end(_VSTD::move(__x)); 18200b57cec5SDimitry Andric } 18210b57cec5SDimitry Andric else 18220b57cec5SDimitry Andric { 18230b57cec5SDimitry Andric __move_range(__p, this->__end_, __p + 1); 18240b57cec5SDimitry Andric *__p = _VSTD::move(__x); 18250b57cec5SDimitry Andric } 18260b57cec5SDimitry Andric } 18270b57cec5SDimitry Andric else 18280b57cec5SDimitry Andric { 18290b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 18300b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 18310b57cec5SDimitry Andric __v.push_back(_VSTD::move(__x)); 18320b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 18330b57cec5SDimitry Andric } 18340b57cec5SDimitry Andric return __make_iter(__p); 18350b57cec5SDimitry Andric} 18360b57cec5SDimitry Andric 18370b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 18380b57cec5SDimitry Andrictemplate <class... _Args> 18390b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 18400b57cec5SDimitry Andricvector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) 18410b57cec5SDimitry Andric{ 18420b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 18430b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 18440b57cec5SDimitry Andric "vector::emplace(iterator, x) called with an iterator not" 18450b57cec5SDimitry Andric " referring to this vector"); 18460b57cec5SDimitry Andric#endif 18470b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 18480b57cec5SDimitry Andric if (this->__end_ < this->__end_cap()) 18490b57cec5SDimitry Andric { 18500b57cec5SDimitry Andric if (__p == this->__end_) 18510b57cec5SDimitry Andric { 1852e40139ffSDimitry Andric __construct_one_at_end(_VSTD::forward<_Args>(__args)...); 18530b57cec5SDimitry Andric } 18540b57cec5SDimitry Andric else 18550b57cec5SDimitry Andric { 18560b57cec5SDimitry Andric __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...); 18570b57cec5SDimitry Andric __move_range(__p, this->__end_, __p + 1); 18580b57cec5SDimitry Andric *__p = _VSTD::move(__tmp.get()); 18590b57cec5SDimitry Andric } 18600b57cec5SDimitry Andric } 18610b57cec5SDimitry Andric else 18620b57cec5SDimitry Andric { 18630b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 18640b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 18650b57cec5SDimitry Andric __v.emplace_back(_VSTD::forward<_Args>(__args)...); 18660b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 18670b57cec5SDimitry Andric } 18680b57cec5SDimitry Andric return __make_iter(__p); 18690b57cec5SDimitry Andric} 18700b57cec5SDimitry Andric 18710b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG 18720b57cec5SDimitry Andric 18730b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 18740b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 18750b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x) 18760b57cec5SDimitry Andric{ 18770b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 18780b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 18790b57cec5SDimitry Andric "vector::insert(iterator, n, x) called with an iterator not" 18800b57cec5SDimitry Andric " referring to this vector"); 18810b57cec5SDimitry Andric#endif 18820b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 18830b57cec5SDimitry Andric if (__n > 0) 18840b57cec5SDimitry Andric { 18850b57cec5SDimitry Andric if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_)) 18860b57cec5SDimitry Andric { 18870b57cec5SDimitry Andric size_type __old_n = __n; 18880b57cec5SDimitry Andric pointer __old_last = this->__end_; 18890b57cec5SDimitry Andric if (__n > static_cast<size_type>(this->__end_ - __p)) 18900b57cec5SDimitry Andric { 18910b57cec5SDimitry Andric size_type __cx = __n - (this->__end_ - __p); 18920b57cec5SDimitry Andric __construct_at_end(__cx, __x); 18930b57cec5SDimitry Andric __n -= __cx; 18940b57cec5SDimitry Andric } 18950b57cec5SDimitry Andric if (__n > 0) 18960b57cec5SDimitry Andric { 18970b57cec5SDimitry Andric __move_range(__p, __old_last, __p + __old_n); 18980b57cec5SDimitry Andric const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); 18990b57cec5SDimitry Andric if (__p <= __xr && __xr < this->__end_) 19000b57cec5SDimitry Andric __xr += __old_n; 19010b57cec5SDimitry Andric _VSTD::fill_n(__p, __n, *__xr); 19020b57cec5SDimitry Andric } 19030b57cec5SDimitry Andric } 19040b57cec5SDimitry Andric else 19050b57cec5SDimitry Andric { 19060b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 19070b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); 19080b57cec5SDimitry Andric __v.__construct_at_end(__n, __x); 19090b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 19100b57cec5SDimitry Andric } 19110b57cec5SDimitry Andric } 19120b57cec5SDimitry Andric return __make_iter(__p); 19130b57cec5SDimitry Andric} 19140b57cec5SDimitry Andric 19150b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 19160b57cec5SDimitry Andrictemplate <class _InputIterator> 19170b57cec5SDimitry Andrictypename enable_if 19180b57cec5SDimitry Andric< 1919480093f4SDimitry Andric __is_cpp17_input_iterator <_InputIterator>::value && 1920480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value && 19210b57cec5SDimitry Andric is_constructible< 19220b57cec5SDimitry Andric _Tp, 19230b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 19240b57cec5SDimitry Andric typename vector<_Tp, _Allocator>::iterator 19250b57cec5SDimitry Andric>::type 19260b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) 19270b57cec5SDimitry Andric{ 19280b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 19290b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 19300b57cec5SDimitry Andric "vector::insert(iterator, range) called with an iterator not" 19310b57cec5SDimitry Andric " referring to this vector"); 19320b57cec5SDimitry Andric#endif 19330b57cec5SDimitry Andric difference_type __off = __position - begin(); 19340b57cec5SDimitry Andric pointer __p = this->__begin_ + __off; 19350b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 19360b57cec5SDimitry Andric pointer __old_last = this->__end_; 19370b57cec5SDimitry Andric for (; this->__end_ != this->__end_cap() && __first != __last; ++__first) 19380b57cec5SDimitry Andric { 1939e40139ffSDimitry Andric __construct_one_at_end(*__first); 19400b57cec5SDimitry Andric } 19410b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__a); 19420b57cec5SDimitry Andric if (__first != __last) 19430b57cec5SDimitry Andric { 19440b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 19450b57cec5SDimitry Andric try 19460b57cec5SDimitry Andric { 19470b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 19480b57cec5SDimitry Andric __v.__construct_at_end(__first, __last); 19490b57cec5SDimitry Andric difference_type __old_size = __old_last - this->__begin_; 19500b57cec5SDimitry Andric difference_type __old_p = __p - this->__begin_; 19510b57cec5SDimitry Andric reserve(__recommend(size() + __v.size())); 19520b57cec5SDimitry Andric __p = this->__begin_ + __old_p; 19530b57cec5SDimitry Andric __old_last = this->__begin_ + __old_size; 19540b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 19550b57cec5SDimitry Andric } 19560b57cec5SDimitry Andric catch (...) 19570b57cec5SDimitry Andric { 19580b57cec5SDimitry Andric erase(__make_iter(__old_last), end()); 19590b57cec5SDimitry Andric throw; 19600b57cec5SDimitry Andric } 19610b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 19620b57cec5SDimitry Andric } 19630b57cec5SDimitry Andric __p = _VSTD::rotate(__p, __old_last, this->__end_); 1964*5ffd83dbSDimitry Andric insert(__make_iter(__p), _VSTD::make_move_iterator(__v.begin()), 1965*5ffd83dbSDimitry Andric _VSTD::make_move_iterator(__v.end())); 19660b57cec5SDimitry Andric return begin() + __off; 19670b57cec5SDimitry Andric} 19680b57cec5SDimitry Andric 19690b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 19700b57cec5SDimitry Andrictemplate <class _ForwardIterator> 19710b57cec5SDimitry Andrictypename enable_if 19720b57cec5SDimitry Andric< 1973480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value && 19740b57cec5SDimitry Andric is_constructible< 19750b57cec5SDimitry Andric _Tp, 19760b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 19770b57cec5SDimitry Andric typename vector<_Tp, _Allocator>::iterator 19780b57cec5SDimitry Andric>::type 19790b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) 19800b57cec5SDimitry Andric{ 19810b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 19820b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this, 19830b57cec5SDimitry Andric "vector::insert(iterator, range) called with an iterator not" 19840b57cec5SDimitry Andric " referring to this vector"); 19850b57cec5SDimitry Andric#endif 19860b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 19870b57cec5SDimitry Andric difference_type __n = _VSTD::distance(__first, __last); 19880b57cec5SDimitry Andric if (__n > 0) 19890b57cec5SDimitry Andric { 19900b57cec5SDimitry Andric if (__n <= this->__end_cap() - this->__end_) 19910b57cec5SDimitry Andric { 19920b57cec5SDimitry Andric size_type __old_n = __n; 19930b57cec5SDimitry Andric pointer __old_last = this->__end_; 19940b57cec5SDimitry Andric _ForwardIterator __m = __last; 19950b57cec5SDimitry Andric difference_type __dx = this->__end_ - __p; 19960b57cec5SDimitry Andric if (__n > __dx) 19970b57cec5SDimitry Andric { 19980b57cec5SDimitry Andric __m = __first; 19990b57cec5SDimitry Andric difference_type __diff = this->__end_ - __p; 20000b57cec5SDimitry Andric _VSTD::advance(__m, __diff); 20010b57cec5SDimitry Andric __construct_at_end(__m, __last, __n - __diff); 20020b57cec5SDimitry Andric __n = __dx; 20030b57cec5SDimitry Andric } 20040b57cec5SDimitry Andric if (__n > 0) 20050b57cec5SDimitry Andric { 20060b57cec5SDimitry Andric __move_range(__p, __old_last, __p + __old_n); 20070b57cec5SDimitry Andric _VSTD::copy(__first, __m, __p); 20080b57cec5SDimitry Andric } 20090b57cec5SDimitry Andric } 20100b57cec5SDimitry Andric else 20110b57cec5SDimitry Andric { 20120b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 20130b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); 20140b57cec5SDimitry Andric __v.__construct_at_end(__first, __last); 20150b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 20160b57cec5SDimitry Andric } 20170b57cec5SDimitry Andric } 20180b57cec5SDimitry Andric return __make_iter(__p); 20190b57cec5SDimitry Andric} 20200b57cec5SDimitry Andric 20210b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 20220b57cec5SDimitry Andricvoid 20230b57cec5SDimitry Andricvector<_Tp, _Allocator>::resize(size_type __sz) 20240b57cec5SDimitry Andric{ 20250b57cec5SDimitry Andric size_type __cs = size(); 20260b57cec5SDimitry Andric if (__cs < __sz) 20270b57cec5SDimitry Andric this->__append(__sz - __cs); 20280b57cec5SDimitry Andric else if (__cs > __sz) 20290b57cec5SDimitry Andric this->__destruct_at_end(this->__begin_ + __sz); 20300b57cec5SDimitry Andric} 20310b57cec5SDimitry Andric 20320b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 20330b57cec5SDimitry Andricvoid 20340b57cec5SDimitry Andricvector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x) 20350b57cec5SDimitry Andric{ 20360b57cec5SDimitry Andric size_type __cs = size(); 20370b57cec5SDimitry Andric if (__cs < __sz) 20380b57cec5SDimitry Andric this->__append(__sz - __cs, __x); 20390b57cec5SDimitry Andric else if (__cs > __sz) 20400b57cec5SDimitry Andric this->__destruct_at_end(this->__begin_ + __sz); 20410b57cec5SDimitry Andric} 20420b57cec5SDimitry Andric 20430b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 20440b57cec5SDimitry Andricvoid 20450b57cec5SDimitry Andricvector<_Tp, _Allocator>::swap(vector& __x) 20460b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 20470b57cec5SDimitry Andric _NOEXCEPT 20480b57cec5SDimitry Andric#else 20490b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 20500b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value) 20510b57cec5SDimitry Andric#endif 20520b57cec5SDimitry Andric{ 20530b57cec5SDimitry Andric _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value || 20540b57cec5SDimitry Andric this->__alloc() == __x.__alloc(), 20550b57cec5SDimitry Andric "vector::swap: Either propagate_on_container_swap must be true" 20560b57cec5SDimitry Andric " or the allocators must compare equal"); 20570b57cec5SDimitry Andric _VSTD::swap(this->__begin_, __x.__begin_); 20580b57cec5SDimitry Andric _VSTD::swap(this->__end_, __x.__end_); 20590b57cec5SDimitry Andric _VSTD::swap(this->__end_cap(), __x.__end_cap()); 20600b57cec5SDimitry Andric __swap_allocator(this->__alloc(), __x.__alloc(), 20610b57cec5SDimitry Andric integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>()); 20620b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 20630b57cec5SDimitry Andric __get_db()->swap(this, &__x); 20640b57cec5SDimitry Andric#endif // _LIBCPP_DEBUG_LEVEL >= 2 20650b57cec5SDimitry Andric} 20660b57cec5SDimitry Andric 20670b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 20680b57cec5SDimitry Andricbool 20690b57cec5SDimitry Andricvector<_Tp, _Allocator>::__invariants() const 20700b57cec5SDimitry Andric{ 20710b57cec5SDimitry Andric if (this->__begin_ == nullptr) 20720b57cec5SDimitry Andric { 20730b57cec5SDimitry Andric if (this->__end_ != nullptr || this->__end_cap() != nullptr) 20740b57cec5SDimitry Andric return false; 20750b57cec5SDimitry Andric } 20760b57cec5SDimitry Andric else 20770b57cec5SDimitry Andric { 20780b57cec5SDimitry Andric if (this->__begin_ > this->__end_) 20790b57cec5SDimitry Andric return false; 20800b57cec5SDimitry Andric if (this->__begin_ == this->__end_cap()) 20810b57cec5SDimitry Andric return false; 20820b57cec5SDimitry Andric if (this->__end_ > this->__end_cap()) 20830b57cec5SDimitry Andric return false; 20840b57cec5SDimitry Andric } 20850b57cec5SDimitry Andric return true; 20860b57cec5SDimitry Andric} 20870b57cec5SDimitry Andric 20880b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 20890b57cec5SDimitry Andric 20900b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 20910b57cec5SDimitry Andricbool 20920b57cec5SDimitry Andricvector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const 20930b57cec5SDimitry Andric{ 20940b57cec5SDimitry Andric return this->__begin_ <= __i->base() && __i->base() < this->__end_; 20950b57cec5SDimitry Andric} 20960b57cec5SDimitry Andric 20970b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 20980b57cec5SDimitry Andricbool 20990b57cec5SDimitry Andricvector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const 21000b57cec5SDimitry Andric{ 21010b57cec5SDimitry Andric return this->__begin_ < __i->base() && __i->base() <= this->__end_; 21020b57cec5SDimitry Andric} 21030b57cec5SDimitry Andric 21040b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 21050b57cec5SDimitry Andricbool 21060b57cec5SDimitry Andricvector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const 21070b57cec5SDimitry Andric{ 21080b57cec5SDimitry Andric const_pointer __p = __i->base() + __n; 21090b57cec5SDimitry Andric return this->__begin_ <= __p && __p <= this->__end_; 21100b57cec5SDimitry Andric} 21110b57cec5SDimitry Andric 21120b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 21130b57cec5SDimitry Andricbool 21140b57cec5SDimitry Andricvector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const 21150b57cec5SDimitry Andric{ 21160b57cec5SDimitry Andric const_pointer __p = __i->base() + __n; 21170b57cec5SDimitry Andric return this->__begin_ <= __p && __p < this->__end_; 21180b57cec5SDimitry Andric} 21190b57cec5SDimitry Andric 21200b57cec5SDimitry Andric#endif // _LIBCPP_DEBUG_LEVEL >= 2 21210b57cec5SDimitry Andric 21220b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 21230b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 21240b57cec5SDimitry Andricvoid 21250b57cec5SDimitry Andricvector<_Tp, _Allocator>::__invalidate_all_iterators() 21260b57cec5SDimitry Andric{ 21270b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 21280b57cec5SDimitry Andric __get_db()->__invalidate_all(this); 21290b57cec5SDimitry Andric#endif // _LIBCPP_DEBUG_LEVEL >= 2 21300b57cec5SDimitry Andric} 21310b57cec5SDimitry Andric 21320b57cec5SDimitry Andric 21330b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 21340b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 21350b57cec5SDimitry Andricvoid 21360b57cec5SDimitry Andricvector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) { 21370b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 21380b57cec5SDimitry Andric __c_node* __c = __get_db()->__find_c_and_lock(this); 21390b57cec5SDimitry Andric for (__i_node** __p = __c->end_; __p != __c->beg_; ) { 21400b57cec5SDimitry Andric --__p; 21410b57cec5SDimitry Andric const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); 21420b57cec5SDimitry Andric if (__i->base() > __new_last) { 21430b57cec5SDimitry Andric (*__p)->__c_ = nullptr; 21440b57cec5SDimitry Andric if (--__c->end_ != __p) 21450b57cec5SDimitry Andric memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); 21460b57cec5SDimitry Andric } 21470b57cec5SDimitry Andric } 21480b57cec5SDimitry Andric __get_db()->unlock(); 21490b57cec5SDimitry Andric#else 21500b57cec5SDimitry Andric ((void)__new_last); 21510b57cec5SDimitry Andric#endif 21520b57cec5SDimitry Andric} 21530b57cec5SDimitry Andric 21540b57cec5SDimitry Andric// vector<bool> 21550b57cec5SDimitry Andric 21560b57cec5SDimitry Andrictemplate <class _Allocator> class vector<bool, _Allocator>; 21570b57cec5SDimitry Andric 21580b57cec5SDimitry Andrictemplate <class _Allocator> struct hash<vector<bool, _Allocator> >; 21590b57cec5SDimitry Andric 21600b57cec5SDimitry Andrictemplate <class _Allocator> 21610b57cec5SDimitry Andricstruct __has_storage_type<vector<bool, _Allocator> > 21620b57cec5SDimitry Andric{ 21630b57cec5SDimitry Andric static const bool value = true; 21640b57cec5SDimitry Andric}; 21650b57cec5SDimitry Andric 21660b57cec5SDimitry Andrictemplate <class _Allocator> 21670b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> 21680b57cec5SDimitry Andric : private __vector_base_common<true> 21690b57cec5SDimitry Andric{ 21700b57cec5SDimitry Andricpublic: 21710b57cec5SDimitry Andric typedef vector __self; 21720b57cec5SDimitry Andric typedef bool value_type; 21730b57cec5SDimitry Andric typedef _Allocator allocator_type; 21740b57cec5SDimitry Andric typedef allocator_traits<allocator_type> __alloc_traits; 21750b57cec5SDimitry Andric typedef typename __alloc_traits::size_type size_type; 21760b57cec5SDimitry Andric typedef typename __alloc_traits::difference_type difference_type; 21770b57cec5SDimitry Andric typedef size_type __storage_type; 21780b57cec5SDimitry Andric typedef __bit_iterator<vector, false> pointer; 21790b57cec5SDimitry Andric typedef __bit_iterator<vector, true> const_pointer; 21800b57cec5SDimitry Andric typedef pointer iterator; 21810b57cec5SDimitry Andric typedef const_pointer const_iterator; 21820b57cec5SDimitry Andric typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 21830b57cec5SDimitry Andric typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 21840b57cec5SDimitry Andric 21850b57cec5SDimitry Andricprivate: 21860b57cec5SDimitry Andric typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator; 21870b57cec5SDimitry Andric typedef allocator_traits<__storage_allocator> __storage_traits; 21880b57cec5SDimitry Andric typedef typename __storage_traits::pointer __storage_pointer; 21890b57cec5SDimitry Andric typedef typename __storage_traits::const_pointer __const_storage_pointer; 21900b57cec5SDimitry Andric 21910b57cec5SDimitry Andric __storage_pointer __begin_; 21920b57cec5SDimitry Andric size_type __size_; 21930b57cec5SDimitry Andric __compressed_pair<size_type, __storage_allocator> __cap_alloc_; 21940b57cec5SDimitry Andricpublic: 21950b57cec5SDimitry Andric typedef __bit_reference<vector> reference; 21960b57cec5SDimitry Andric typedef __bit_const_reference<vector> const_reference; 21970b57cec5SDimitry Andricprivate: 21980b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 21990b57cec5SDimitry Andric size_type& __cap() _NOEXCEPT 22000b57cec5SDimitry Andric {return __cap_alloc_.first();} 22010b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22020b57cec5SDimitry Andric const size_type& __cap() const _NOEXCEPT 22030b57cec5SDimitry Andric {return __cap_alloc_.first();} 22040b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22050b57cec5SDimitry Andric __storage_allocator& __alloc() _NOEXCEPT 22060b57cec5SDimitry Andric {return __cap_alloc_.second();} 22070b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22080b57cec5SDimitry Andric const __storage_allocator& __alloc() const _NOEXCEPT 22090b57cec5SDimitry Andric {return __cap_alloc_.second();} 22100b57cec5SDimitry Andric 22110b57cec5SDimitry Andric static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 22120b57cec5SDimitry Andric 22130b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22140b57cec5SDimitry Andric static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT 22150b57cec5SDimitry Andric {return __n * __bits_per_word;} 22160b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22170b57cec5SDimitry Andric static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT 22180b57cec5SDimitry Andric {return (__n - 1) / __bits_per_word + 1;} 22190b57cec5SDimitry Andric 22200b57cec5SDimitry Andricpublic: 22210b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22220b57cec5SDimitry Andric vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); 22230b57cec5SDimitry Andric 22240b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) 22250b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 22260b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value); 22270b57cec5SDimitry Andric#else 22280b57cec5SDimitry Andric _NOEXCEPT; 22290b57cec5SDimitry Andric#endif 22300b57cec5SDimitry Andric ~vector(); 22310b57cec5SDimitry Andric explicit vector(size_type __n); 22320b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 22330b57cec5SDimitry Andric explicit vector(size_type __n, const allocator_type& __a); 22340b57cec5SDimitry Andric#endif 22350b57cec5SDimitry Andric vector(size_type __n, const value_type& __v); 22360b57cec5SDimitry Andric vector(size_type __n, const value_type& __v, const allocator_type& __a); 22370b57cec5SDimitry Andric template <class _InputIterator> 22380b57cec5SDimitry Andric vector(_InputIterator __first, _InputIterator __last, 2239480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 2240480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value>::type* = 0); 22410b57cec5SDimitry Andric template <class _InputIterator> 22420b57cec5SDimitry Andric vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 2243480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 2244480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value>::type* = 0); 22450b57cec5SDimitry Andric template <class _ForwardIterator> 22460b57cec5SDimitry Andric vector(_ForwardIterator __first, _ForwardIterator __last, 2247480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0); 22480b57cec5SDimitry Andric template <class _ForwardIterator> 22490b57cec5SDimitry Andric vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 2250480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0); 22510b57cec5SDimitry Andric 22520b57cec5SDimitry Andric vector(const vector& __v); 22530b57cec5SDimitry Andric vector(const vector& __v, const allocator_type& __a); 22540b57cec5SDimitry Andric vector& operator=(const vector& __v); 22550b57cec5SDimitry Andric 22560b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 22570b57cec5SDimitry Andric vector(initializer_list<value_type> __il); 22580b57cec5SDimitry Andric vector(initializer_list<value_type> __il, const allocator_type& __a); 22590b57cec5SDimitry Andric 22600b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22610b57cec5SDimitry Andric vector(vector&& __v) 22620b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 22630b57cec5SDimitry Andric _NOEXCEPT; 22640b57cec5SDimitry Andric#else 22650b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); 22660b57cec5SDimitry Andric#endif 22670b57cec5SDimitry Andric vector(vector&& __v, const allocator_type& __a); 22680b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22690b57cec5SDimitry Andric vector& operator=(vector&& __v) 22700b57cec5SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); 22710b57cec5SDimitry Andric 22720b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22730b57cec5SDimitry Andric vector& operator=(initializer_list<value_type> __il) 22740b57cec5SDimitry Andric {assign(__il.begin(), __il.end()); return *this;} 22750b57cec5SDimitry Andric 22760b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG 22770b57cec5SDimitry Andric 22780b57cec5SDimitry Andric template <class _InputIterator> 22790b57cec5SDimitry Andric typename enable_if 22800b57cec5SDimitry Andric < 2281480093f4SDimitry Andric __is_cpp17_input_iterator<_InputIterator>::value && 2282480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value, 22830b57cec5SDimitry Andric void 22840b57cec5SDimitry Andric >::type 22850b57cec5SDimitry Andric assign(_InputIterator __first, _InputIterator __last); 22860b57cec5SDimitry Andric template <class _ForwardIterator> 22870b57cec5SDimitry Andric typename enable_if 22880b57cec5SDimitry Andric < 2289480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 22900b57cec5SDimitry Andric void 22910b57cec5SDimitry Andric >::type 22920b57cec5SDimitry Andric assign(_ForwardIterator __first, _ForwardIterator __last); 22930b57cec5SDimitry Andric 22940b57cec5SDimitry Andric void assign(size_type __n, const value_type& __x); 22950b57cec5SDimitry Andric 22960b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 22970b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 22980b57cec5SDimitry Andric void assign(initializer_list<value_type> __il) 22990b57cec5SDimitry Andric {assign(__il.begin(), __il.end());} 23000b57cec5SDimitry Andric#endif 23010b57cec5SDimitry Andric 23020b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT 23030b57cec5SDimitry Andric {return allocator_type(this->__alloc());} 23040b57cec5SDimitry Andric 23050b57cec5SDimitry Andric size_type max_size() const _NOEXCEPT; 23060b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23070b57cec5SDimitry Andric size_type capacity() const _NOEXCEPT 23080b57cec5SDimitry Andric {return __internal_cap_to_external(__cap());} 23090b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23100b57cec5SDimitry Andric size_type size() const _NOEXCEPT 23110b57cec5SDimitry Andric {return __size_;} 23120b57cec5SDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 23130b57cec5SDimitry Andric bool empty() const _NOEXCEPT 23140b57cec5SDimitry Andric {return __size_ == 0;} 23150b57cec5SDimitry Andric void reserve(size_type __n); 23160b57cec5SDimitry Andric void shrink_to_fit() _NOEXCEPT; 23170b57cec5SDimitry Andric 23180b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23190b57cec5SDimitry Andric iterator begin() _NOEXCEPT 23200b57cec5SDimitry Andric {return __make_iter(0);} 23210b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23220b57cec5SDimitry Andric const_iterator begin() const _NOEXCEPT 23230b57cec5SDimitry Andric {return __make_iter(0);} 23240b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23250b57cec5SDimitry Andric iterator end() _NOEXCEPT 23260b57cec5SDimitry Andric {return __make_iter(__size_);} 23270b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23280b57cec5SDimitry Andric const_iterator end() const _NOEXCEPT 23290b57cec5SDimitry Andric {return __make_iter(__size_);} 23300b57cec5SDimitry Andric 23310b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23320b57cec5SDimitry Andric reverse_iterator rbegin() _NOEXCEPT 23330b57cec5SDimitry Andric {return reverse_iterator(end());} 23340b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23350b57cec5SDimitry Andric const_reverse_iterator rbegin() const _NOEXCEPT 23360b57cec5SDimitry Andric {return const_reverse_iterator(end());} 23370b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23380b57cec5SDimitry Andric reverse_iterator rend() _NOEXCEPT 23390b57cec5SDimitry Andric {return reverse_iterator(begin());} 23400b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23410b57cec5SDimitry Andric const_reverse_iterator rend() const _NOEXCEPT 23420b57cec5SDimitry Andric {return const_reverse_iterator(begin());} 23430b57cec5SDimitry Andric 23440b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23450b57cec5SDimitry Andric const_iterator cbegin() const _NOEXCEPT 23460b57cec5SDimitry Andric {return __make_iter(0);} 23470b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23480b57cec5SDimitry Andric const_iterator cend() const _NOEXCEPT 23490b57cec5SDimitry Andric {return __make_iter(__size_);} 23500b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23510b57cec5SDimitry Andric const_reverse_iterator crbegin() const _NOEXCEPT 23520b57cec5SDimitry Andric {return rbegin();} 23530b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 23540b57cec5SDimitry Andric const_reverse_iterator crend() const _NOEXCEPT 23550b57cec5SDimitry Andric {return rend();} 23560b57cec5SDimitry Andric 23570b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);} 23580b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);} 23590b57cec5SDimitry Andric reference at(size_type __n); 23600b57cec5SDimitry Andric const_reference at(size_type __n) const; 23610b57cec5SDimitry Andric 23620b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);} 23630b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);} 23640b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);} 23650b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);} 23660b57cec5SDimitry Andric 23670b57cec5SDimitry Andric void push_back(const value_type& __x); 23680b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 23690b57cec5SDimitry Andric template <class... _Args> 23700b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 23710b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY reference emplace_back(_Args&&... __args) 23720b57cec5SDimitry Andric#else 23730b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args) 23740b57cec5SDimitry Andric#endif 23750b57cec5SDimitry Andric { 23760b57cec5SDimitry Andric push_back ( value_type ( _VSTD::forward<_Args>(__args)... )); 23770b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 23780b57cec5SDimitry Andric return this->back(); 23790b57cec5SDimitry Andric#endif 23800b57cec5SDimitry Andric } 23810b57cec5SDimitry Andric#endif 23820b57cec5SDimitry Andric 23830b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;} 23840b57cec5SDimitry Andric 23850b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 23860b57cec5SDimitry Andric template <class... _Args> 23870b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args) 23880b57cec5SDimitry Andric { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); } 23890b57cec5SDimitry Andric#endif 23900b57cec5SDimitry Andric 23910b57cec5SDimitry Andric iterator insert(const_iterator __position, const value_type& __x); 23920b57cec5SDimitry Andric iterator insert(const_iterator __position, size_type __n, const value_type& __x); 23930b57cec5SDimitry Andric iterator insert(const_iterator __position, size_type __n, const_reference __x); 23940b57cec5SDimitry Andric template <class _InputIterator> 23950b57cec5SDimitry Andric typename enable_if 23960b57cec5SDimitry Andric < 2397480093f4SDimitry Andric __is_cpp17_input_iterator <_InputIterator>::value && 2398480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value, 23990b57cec5SDimitry Andric iterator 24000b57cec5SDimitry Andric >::type 24010b57cec5SDimitry Andric insert(const_iterator __position, _InputIterator __first, _InputIterator __last); 24020b57cec5SDimitry Andric template <class _ForwardIterator> 24030b57cec5SDimitry Andric typename enable_if 24040b57cec5SDimitry Andric < 2405480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 24060b57cec5SDimitry Andric iterator 24070b57cec5SDimitry Andric >::type 24080b57cec5SDimitry Andric insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); 24090b57cec5SDimitry Andric 24100b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 24110b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 24120b57cec5SDimitry Andric iterator insert(const_iterator __position, initializer_list<value_type> __il) 24130b57cec5SDimitry Andric {return insert(__position, __il.begin(), __il.end());} 24140b57cec5SDimitry Andric#endif 24150b57cec5SDimitry Andric 24160b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); 24170b57cec5SDimitry Andric iterator erase(const_iterator __first, const_iterator __last); 24180b57cec5SDimitry Andric 24190b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 24200b57cec5SDimitry Andric void clear() _NOEXCEPT {__size_ = 0;} 24210b57cec5SDimitry Andric 24220b57cec5SDimitry Andric void swap(vector&) 24230b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 24240b57cec5SDimitry Andric _NOEXCEPT; 24250b57cec5SDimitry Andric#else 24260b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 24270b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value); 24280b57cec5SDimitry Andric#endif 24290b57cec5SDimitry Andric static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); } 24300b57cec5SDimitry Andric 24310b57cec5SDimitry Andric void resize(size_type __sz, value_type __x = false); 24320b57cec5SDimitry Andric void flip() _NOEXCEPT; 24330b57cec5SDimitry Andric 24340b57cec5SDimitry Andric bool __invariants() const; 24350b57cec5SDimitry Andric 24360b57cec5SDimitry Andricprivate: 24370b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); 24380b57cec5SDimitry Andric void __vallocate(size_type __n); 24390b57cec5SDimitry Andric void __vdeallocate() _NOEXCEPT; 24400b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 24410b57cec5SDimitry Andric static size_type __align_it(size_type __new_size) _NOEXCEPT 24420b57cec5SDimitry Andric {return __new_size + (__bits_per_word-1) & ~((size_type)__bits_per_word-1);} 24430b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; 24440b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x); 24450b57cec5SDimitry Andric template <class _ForwardIterator> 24460b57cec5SDimitry Andric typename enable_if 24470b57cec5SDimitry Andric < 2448480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 24490b57cec5SDimitry Andric void 24500b57cec5SDimitry Andric >::type 24510b57cec5SDimitry Andric __construct_at_end(_ForwardIterator __first, _ForwardIterator __last); 24520b57cec5SDimitry Andric void __append(size_type __n, const_reference __x); 24530b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 24540b57cec5SDimitry Andric reference __make_ref(size_type __pos) _NOEXCEPT 24550b57cec5SDimitry Andric {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 24560b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 24570b57cec5SDimitry Andric const_reference __make_ref(size_type __pos) const _NOEXCEPT 24580b57cec5SDimitry Andric {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 24590b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 24600b57cec5SDimitry Andric iterator __make_iter(size_type __pos) _NOEXCEPT 24610b57cec5SDimitry Andric {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));} 24620b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 24630b57cec5SDimitry Andric const_iterator __make_iter(size_type __pos) const _NOEXCEPT 24640b57cec5SDimitry Andric {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));} 24650b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 24660b57cec5SDimitry Andric iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT 24670b57cec5SDimitry Andric {return begin() + (__p - cbegin());} 24680b57cec5SDimitry Andric 24690b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 24700b57cec5SDimitry Andric void __copy_assign_alloc(const vector& __v) 24710b57cec5SDimitry Andric {__copy_assign_alloc(__v, integral_constant<bool, 24720b57cec5SDimitry Andric __storage_traits::propagate_on_container_copy_assignment::value>());} 24730b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 24740b57cec5SDimitry Andric void __copy_assign_alloc(const vector& __c, true_type) 24750b57cec5SDimitry Andric { 24760b57cec5SDimitry Andric if (__alloc() != __c.__alloc()) 24770b57cec5SDimitry Andric __vdeallocate(); 24780b57cec5SDimitry Andric __alloc() = __c.__alloc(); 24790b57cec5SDimitry Andric } 24800b57cec5SDimitry Andric 24810b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 24820b57cec5SDimitry Andric void __copy_assign_alloc(const vector&, false_type) 24830b57cec5SDimitry Andric {} 24840b57cec5SDimitry Andric 24850b57cec5SDimitry Andric void __move_assign(vector& __c, false_type); 24860b57cec5SDimitry Andric void __move_assign(vector& __c, true_type) 24870b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); 24880b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 24890b57cec5SDimitry Andric void __move_assign_alloc(vector& __c) 24900b57cec5SDimitry Andric _NOEXCEPT_( 24910b57cec5SDimitry Andric !__storage_traits::propagate_on_container_move_assignment::value || 24920b57cec5SDimitry Andric is_nothrow_move_assignable<allocator_type>::value) 24930b57cec5SDimitry Andric {__move_assign_alloc(__c, integral_constant<bool, 24940b57cec5SDimitry Andric __storage_traits::propagate_on_container_move_assignment::value>());} 24950b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 24960b57cec5SDimitry Andric void __move_assign_alloc(vector& __c, true_type) 24970b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 24980b57cec5SDimitry Andric { 24990b57cec5SDimitry Andric __alloc() = _VSTD::move(__c.__alloc()); 25000b57cec5SDimitry Andric } 25010b57cec5SDimitry Andric 25020b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 25030b57cec5SDimitry Andric void __move_assign_alloc(vector&, false_type) 25040b57cec5SDimitry Andric _NOEXCEPT 25050b57cec5SDimitry Andric {} 25060b57cec5SDimitry Andric 25070b57cec5SDimitry Andric size_t __hash_code() const _NOEXCEPT; 25080b57cec5SDimitry Andric 25090b57cec5SDimitry Andric friend class __bit_reference<vector>; 25100b57cec5SDimitry Andric friend class __bit_const_reference<vector>; 25110b57cec5SDimitry Andric friend class __bit_iterator<vector, false>; 25120b57cec5SDimitry Andric friend class __bit_iterator<vector, true>; 25130b57cec5SDimitry Andric friend struct __bit_array<vector>; 25140b57cec5SDimitry Andric friend struct _LIBCPP_TEMPLATE_VIS hash<vector>; 25150b57cec5SDimitry Andric}; 25160b57cec5SDimitry Andric 25170b57cec5SDimitry Andrictemplate <class _Allocator> 25180b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 25190b57cec5SDimitry Andricvoid 25200b57cec5SDimitry Andricvector<bool, _Allocator>::__invalidate_all_iterators() 25210b57cec5SDimitry Andric{ 25220b57cec5SDimitry Andric} 25230b57cec5SDimitry Andric 25240b57cec5SDimitry Andric// Allocate space for __n objects 25250b57cec5SDimitry Andric// throws length_error if __n > max_size() 25260b57cec5SDimitry Andric// throws (probably bad_alloc) if memory run out 25270b57cec5SDimitry Andric// Precondition: __begin_ == __end_ == __cap() == 0 25280b57cec5SDimitry Andric// Precondition: __n > 0 25290b57cec5SDimitry Andric// Postcondition: capacity() == __n 25300b57cec5SDimitry Andric// Postcondition: size() == 0 25310b57cec5SDimitry Andrictemplate <class _Allocator> 25320b57cec5SDimitry Andricvoid 25330b57cec5SDimitry Andricvector<bool, _Allocator>::__vallocate(size_type __n) 25340b57cec5SDimitry Andric{ 25350b57cec5SDimitry Andric if (__n > max_size()) 25360b57cec5SDimitry Andric this->__throw_length_error(); 25370b57cec5SDimitry Andric __n = __external_cap_to_internal(__n); 25380b57cec5SDimitry Andric this->__begin_ = __storage_traits::allocate(this->__alloc(), __n); 25390b57cec5SDimitry Andric this->__size_ = 0; 25400b57cec5SDimitry Andric this->__cap() = __n; 25410b57cec5SDimitry Andric} 25420b57cec5SDimitry Andric 25430b57cec5SDimitry Andrictemplate <class _Allocator> 25440b57cec5SDimitry Andricvoid 25450b57cec5SDimitry Andricvector<bool, _Allocator>::__vdeallocate() _NOEXCEPT 25460b57cec5SDimitry Andric{ 25470b57cec5SDimitry Andric if (this->__begin_ != nullptr) 25480b57cec5SDimitry Andric { 25490b57cec5SDimitry Andric __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap()); 25500b57cec5SDimitry Andric __invalidate_all_iterators(); 25510b57cec5SDimitry Andric this->__begin_ = nullptr; 25520b57cec5SDimitry Andric this->__size_ = this->__cap() = 0; 25530b57cec5SDimitry Andric } 25540b57cec5SDimitry Andric} 25550b57cec5SDimitry Andric 25560b57cec5SDimitry Andrictemplate <class _Allocator> 25570b57cec5SDimitry Andrictypename vector<bool, _Allocator>::size_type 25580b57cec5SDimitry Andricvector<bool, _Allocator>::max_size() const _NOEXCEPT 25590b57cec5SDimitry Andric{ 25600b57cec5SDimitry Andric size_type __amax = __storage_traits::max_size(__alloc()); 25610b57cec5SDimitry Andric size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always 25620b57cec5SDimitry Andric if (__nmax / __bits_per_word <= __amax) 25630b57cec5SDimitry Andric return __nmax; 25640b57cec5SDimitry Andric return __internal_cap_to_external(__amax); 25650b57cec5SDimitry Andric} 25660b57cec5SDimitry Andric 25670b57cec5SDimitry Andric// Precondition: __new_size > capacity() 25680b57cec5SDimitry Andrictemplate <class _Allocator> 25690b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 25700b57cec5SDimitry Andrictypename vector<bool, _Allocator>::size_type 25710b57cec5SDimitry Andricvector<bool, _Allocator>::__recommend(size_type __new_size) const 25720b57cec5SDimitry Andric{ 25730b57cec5SDimitry Andric const size_type __ms = max_size(); 25740b57cec5SDimitry Andric if (__new_size > __ms) 25750b57cec5SDimitry Andric this->__throw_length_error(); 25760b57cec5SDimitry Andric const size_type __cap = capacity(); 25770b57cec5SDimitry Andric if (__cap >= __ms / 2) 25780b57cec5SDimitry Andric return __ms; 25790b57cec5SDimitry Andric return _VSTD::max(2*__cap, __align_it(__new_size)); 25800b57cec5SDimitry Andric} 25810b57cec5SDimitry Andric 25820b57cec5SDimitry Andric// Default constructs __n objects starting at __end_ 25830b57cec5SDimitry Andric// Precondition: __n > 0 25840b57cec5SDimitry Andric// Precondition: size() + __n <= capacity() 25850b57cec5SDimitry Andric// Postcondition: size() == size() + __n 25860b57cec5SDimitry Andrictemplate <class _Allocator> 25870b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 25880b57cec5SDimitry Andricvoid 25890b57cec5SDimitry Andricvector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x) 25900b57cec5SDimitry Andric{ 25910b57cec5SDimitry Andric size_type __old_size = this->__size_; 25920b57cec5SDimitry Andric this->__size_ += __n; 25930b57cec5SDimitry Andric if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) 25940b57cec5SDimitry Andric { 25950b57cec5SDimitry Andric if (this->__size_ <= __bits_per_word) 25960b57cec5SDimitry Andric this->__begin_[0] = __storage_type(0); 25970b57cec5SDimitry Andric else 25980b57cec5SDimitry Andric this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0); 25990b57cec5SDimitry Andric } 26000b57cec5SDimitry Andric _VSTD::fill_n(__make_iter(__old_size), __n, __x); 26010b57cec5SDimitry Andric} 26020b57cec5SDimitry Andric 26030b57cec5SDimitry Andrictemplate <class _Allocator> 26040b57cec5SDimitry Andrictemplate <class _ForwardIterator> 26050b57cec5SDimitry Andrictypename enable_if 26060b57cec5SDimitry Andric< 2607480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 26080b57cec5SDimitry Andric void 26090b57cec5SDimitry Andric>::type 26100b57cec5SDimitry Andricvector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last) 26110b57cec5SDimitry Andric{ 26120b57cec5SDimitry Andric size_type __old_size = this->__size_; 26130b57cec5SDimitry Andric this->__size_ += _VSTD::distance(__first, __last); 26140b57cec5SDimitry Andric if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) 26150b57cec5SDimitry Andric { 26160b57cec5SDimitry Andric if (this->__size_ <= __bits_per_word) 26170b57cec5SDimitry Andric this->__begin_[0] = __storage_type(0); 26180b57cec5SDimitry Andric else 26190b57cec5SDimitry Andric this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0); 26200b57cec5SDimitry Andric } 26210b57cec5SDimitry Andric _VSTD::copy(__first, __last, __make_iter(__old_size)); 26220b57cec5SDimitry Andric} 26230b57cec5SDimitry Andric 26240b57cec5SDimitry Andrictemplate <class _Allocator> 26250b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 26260b57cec5SDimitry Andricvector<bool, _Allocator>::vector() 26270b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 26280b57cec5SDimitry Andric : __begin_(nullptr), 26290b57cec5SDimitry Andric __size_(0), 2630480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 26310b57cec5SDimitry Andric{ 26320b57cec5SDimitry Andric} 26330b57cec5SDimitry Andric 26340b57cec5SDimitry Andrictemplate <class _Allocator> 26350b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 26360b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const allocator_type& __a) 26370b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 26380b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) 26390b57cec5SDimitry Andric#else 26400b57cec5SDimitry Andric _NOEXCEPT 26410b57cec5SDimitry Andric#endif 26420b57cec5SDimitry Andric : __begin_(nullptr), 26430b57cec5SDimitry Andric __size_(0), 26440b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 26450b57cec5SDimitry Andric{ 26460b57cec5SDimitry Andric} 26470b57cec5SDimitry Andric 26480b57cec5SDimitry Andrictemplate <class _Allocator> 26490b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n) 26500b57cec5SDimitry Andric : __begin_(nullptr), 26510b57cec5SDimitry Andric __size_(0), 2652480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 26530b57cec5SDimitry Andric{ 26540b57cec5SDimitry Andric if (__n > 0) 26550b57cec5SDimitry Andric { 26560b57cec5SDimitry Andric __vallocate(__n); 26570b57cec5SDimitry Andric __construct_at_end(__n, false); 26580b57cec5SDimitry Andric } 26590b57cec5SDimitry Andric} 26600b57cec5SDimitry Andric 26610b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 26620b57cec5SDimitry Andrictemplate <class _Allocator> 26630b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a) 26640b57cec5SDimitry Andric : __begin_(nullptr), 26650b57cec5SDimitry Andric __size_(0), 26660b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 26670b57cec5SDimitry Andric{ 26680b57cec5SDimitry Andric if (__n > 0) 26690b57cec5SDimitry Andric { 26700b57cec5SDimitry Andric __vallocate(__n); 26710b57cec5SDimitry Andric __construct_at_end(__n, false); 26720b57cec5SDimitry Andric } 26730b57cec5SDimitry Andric} 26740b57cec5SDimitry Andric#endif 26750b57cec5SDimitry Andric 26760b57cec5SDimitry Andrictemplate <class _Allocator> 26770b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const value_type& __x) 26780b57cec5SDimitry Andric : __begin_(nullptr), 26790b57cec5SDimitry Andric __size_(0), 2680480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 26810b57cec5SDimitry Andric{ 26820b57cec5SDimitry Andric if (__n > 0) 26830b57cec5SDimitry Andric { 26840b57cec5SDimitry Andric __vallocate(__n); 26850b57cec5SDimitry Andric __construct_at_end(__n, __x); 26860b57cec5SDimitry Andric } 26870b57cec5SDimitry Andric} 26880b57cec5SDimitry Andric 26890b57cec5SDimitry Andrictemplate <class _Allocator> 26900b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a) 26910b57cec5SDimitry Andric : __begin_(nullptr), 26920b57cec5SDimitry Andric __size_(0), 26930b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 26940b57cec5SDimitry Andric{ 26950b57cec5SDimitry Andric if (__n > 0) 26960b57cec5SDimitry Andric { 26970b57cec5SDimitry Andric __vallocate(__n); 26980b57cec5SDimitry Andric __construct_at_end(__n, __x); 26990b57cec5SDimitry Andric } 27000b57cec5SDimitry Andric} 27010b57cec5SDimitry Andric 27020b57cec5SDimitry Andrictemplate <class _Allocator> 27030b57cec5SDimitry Andrictemplate <class _InputIterator> 27040b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, 2705480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 2706480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value>::type*) 27070b57cec5SDimitry Andric : __begin_(nullptr), 27080b57cec5SDimitry Andric __size_(0), 2709480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 27100b57cec5SDimitry Andric{ 27110b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 27120b57cec5SDimitry Andric try 27130b57cec5SDimitry Andric { 27140b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 27150b57cec5SDimitry Andric for (; __first != __last; ++__first) 27160b57cec5SDimitry Andric push_back(*__first); 27170b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 27180b57cec5SDimitry Andric } 27190b57cec5SDimitry Andric catch (...) 27200b57cec5SDimitry Andric { 27210b57cec5SDimitry Andric if (__begin_ != nullptr) 27220b57cec5SDimitry Andric __storage_traits::deallocate(__alloc(), __begin_, __cap()); 27230b57cec5SDimitry Andric __invalidate_all_iterators(); 27240b57cec5SDimitry Andric throw; 27250b57cec5SDimitry Andric } 27260b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 27270b57cec5SDimitry Andric} 27280b57cec5SDimitry Andric 27290b57cec5SDimitry Andrictemplate <class _Allocator> 27300b57cec5SDimitry Andrictemplate <class _InputIterator> 27310b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 2732480093f4SDimitry Andric typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && 2733480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value>::type*) 27340b57cec5SDimitry Andric : __begin_(nullptr), 27350b57cec5SDimitry Andric __size_(0), 27360b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 27370b57cec5SDimitry Andric{ 27380b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 27390b57cec5SDimitry Andric try 27400b57cec5SDimitry Andric { 27410b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 27420b57cec5SDimitry Andric for (; __first != __last; ++__first) 27430b57cec5SDimitry Andric push_back(*__first); 27440b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 27450b57cec5SDimitry Andric } 27460b57cec5SDimitry Andric catch (...) 27470b57cec5SDimitry Andric { 27480b57cec5SDimitry Andric if (__begin_ != nullptr) 27490b57cec5SDimitry Andric __storage_traits::deallocate(__alloc(), __begin_, __cap()); 27500b57cec5SDimitry Andric __invalidate_all_iterators(); 27510b57cec5SDimitry Andric throw; 27520b57cec5SDimitry Andric } 27530b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 27540b57cec5SDimitry Andric} 27550b57cec5SDimitry Andric 27560b57cec5SDimitry Andrictemplate <class _Allocator> 27570b57cec5SDimitry Andrictemplate <class _ForwardIterator> 27580b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, 2759480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*) 27600b57cec5SDimitry Andric : __begin_(nullptr), 27610b57cec5SDimitry Andric __size_(0), 2762480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 27630b57cec5SDimitry Andric{ 27640b57cec5SDimitry Andric size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 27650b57cec5SDimitry Andric if (__n > 0) 27660b57cec5SDimitry Andric { 27670b57cec5SDimitry Andric __vallocate(__n); 27680b57cec5SDimitry Andric __construct_at_end(__first, __last); 27690b57cec5SDimitry Andric } 27700b57cec5SDimitry Andric} 27710b57cec5SDimitry Andric 27720b57cec5SDimitry Andrictemplate <class _Allocator> 27730b57cec5SDimitry Andrictemplate <class _ForwardIterator> 27740b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 2775480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*) 27760b57cec5SDimitry Andric : __begin_(nullptr), 27770b57cec5SDimitry Andric __size_(0), 27780b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 27790b57cec5SDimitry Andric{ 27800b57cec5SDimitry Andric size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 27810b57cec5SDimitry Andric if (__n > 0) 27820b57cec5SDimitry Andric { 27830b57cec5SDimitry Andric __vallocate(__n); 27840b57cec5SDimitry Andric __construct_at_end(__first, __last); 27850b57cec5SDimitry Andric } 27860b57cec5SDimitry Andric} 27870b57cec5SDimitry Andric 27880b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 27890b57cec5SDimitry Andric 27900b57cec5SDimitry Andrictemplate <class _Allocator> 27910b57cec5SDimitry Andricvector<bool, _Allocator>::vector(initializer_list<value_type> __il) 27920b57cec5SDimitry Andric : __begin_(nullptr), 27930b57cec5SDimitry Andric __size_(0), 2794480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 27950b57cec5SDimitry Andric{ 27960b57cec5SDimitry Andric size_type __n = static_cast<size_type>(__il.size()); 27970b57cec5SDimitry Andric if (__n > 0) 27980b57cec5SDimitry Andric { 27990b57cec5SDimitry Andric __vallocate(__n); 28000b57cec5SDimitry Andric __construct_at_end(__il.begin(), __il.end()); 28010b57cec5SDimitry Andric } 28020b57cec5SDimitry Andric} 28030b57cec5SDimitry Andric 28040b57cec5SDimitry Andrictemplate <class _Allocator> 28050b57cec5SDimitry Andricvector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) 28060b57cec5SDimitry Andric : __begin_(nullptr), 28070b57cec5SDimitry Andric __size_(0), 28080b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 28090b57cec5SDimitry Andric{ 28100b57cec5SDimitry Andric size_type __n = static_cast<size_type>(__il.size()); 28110b57cec5SDimitry Andric if (__n > 0) 28120b57cec5SDimitry Andric { 28130b57cec5SDimitry Andric __vallocate(__n); 28140b57cec5SDimitry Andric __construct_at_end(__il.begin(), __il.end()); 28150b57cec5SDimitry Andric } 28160b57cec5SDimitry Andric} 28170b57cec5SDimitry Andric 28180b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 28190b57cec5SDimitry Andric 28200b57cec5SDimitry Andrictemplate <class _Allocator> 28210b57cec5SDimitry Andricvector<bool, _Allocator>::~vector() 28220b57cec5SDimitry Andric{ 28230b57cec5SDimitry Andric if (__begin_ != nullptr) 28240b57cec5SDimitry Andric __storage_traits::deallocate(__alloc(), __begin_, __cap()); 28250b57cec5SDimitry Andric __invalidate_all_iterators(); 28260b57cec5SDimitry Andric} 28270b57cec5SDimitry Andric 28280b57cec5SDimitry Andrictemplate <class _Allocator> 28290b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const vector& __v) 28300b57cec5SDimitry Andric : __begin_(nullptr), 28310b57cec5SDimitry Andric __size_(0), 28320b57cec5SDimitry Andric __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc())) 28330b57cec5SDimitry Andric{ 28340b57cec5SDimitry Andric if (__v.size() > 0) 28350b57cec5SDimitry Andric { 28360b57cec5SDimitry Andric __vallocate(__v.size()); 28370b57cec5SDimitry Andric __construct_at_end(__v.begin(), __v.end()); 28380b57cec5SDimitry Andric } 28390b57cec5SDimitry Andric} 28400b57cec5SDimitry Andric 28410b57cec5SDimitry Andrictemplate <class _Allocator> 28420b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a) 28430b57cec5SDimitry Andric : __begin_(nullptr), 28440b57cec5SDimitry Andric __size_(0), 28450b57cec5SDimitry Andric __cap_alloc_(0, __a) 28460b57cec5SDimitry Andric{ 28470b57cec5SDimitry Andric if (__v.size() > 0) 28480b57cec5SDimitry Andric { 28490b57cec5SDimitry Andric __vallocate(__v.size()); 28500b57cec5SDimitry Andric __construct_at_end(__v.begin(), __v.end()); 28510b57cec5SDimitry Andric } 28520b57cec5SDimitry Andric} 28530b57cec5SDimitry Andric 28540b57cec5SDimitry Andrictemplate <class _Allocator> 28550b57cec5SDimitry Andricvector<bool, _Allocator>& 28560b57cec5SDimitry Andricvector<bool, _Allocator>::operator=(const vector& __v) 28570b57cec5SDimitry Andric{ 28580b57cec5SDimitry Andric if (this != &__v) 28590b57cec5SDimitry Andric { 28600b57cec5SDimitry Andric __copy_assign_alloc(__v); 28610b57cec5SDimitry Andric if (__v.__size_) 28620b57cec5SDimitry Andric { 28630b57cec5SDimitry Andric if (__v.__size_ > capacity()) 28640b57cec5SDimitry Andric { 28650b57cec5SDimitry Andric __vdeallocate(); 28660b57cec5SDimitry Andric __vallocate(__v.__size_); 28670b57cec5SDimitry Andric } 28680b57cec5SDimitry Andric _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_); 28690b57cec5SDimitry Andric } 28700b57cec5SDimitry Andric __size_ = __v.__size_; 28710b57cec5SDimitry Andric } 28720b57cec5SDimitry Andric return *this; 28730b57cec5SDimitry Andric} 28740b57cec5SDimitry Andric 28750b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 28760b57cec5SDimitry Andric 28770b57cec5SDimitry Andrictemplate <class _Allocator> 28780b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY vector<bool, _Allocator>::vector(vector&& __v) 28790b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 28800b57cec5SDimitry Andric _NOEXCEPT 28810b57cec5SDimitry Andric#else 28820b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 28830b57cec5SDimitry Andric#endif 28840b57cec5SDimitry Andric : __begin_(__v.__begin_), 28850b57cec5SDimitry Andric __size_(__v.__size_), 28860b57cec5SDimitry Andric __cap_alloc_(std::move(__v.__cap_alloc_)) { 28870b57cec5SDimitry Andric __v.__begin_ = nullptr; 28880b57cec5SDimitry Andric __v.__size_ = 0; 28890b57cec5SDimitry Andric __v.__cap() = 0; 28900b57cec5SDimitry Andric} 28910b57cec5SDimitry Andric 28920b57cec5SDimitry Andrictemplate <class _Allocator> 28930b57cec5SDimitry Andricvector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a) 28940b57cec5SDimitry Andric : __begin_(nullptr), 28950b57cec5SDimitry Andric __size_(0), 28960b57cec5SDimitry Andric __cap_alloc_(0, __a) 28970b57cec5SDimitry Andric{ 28980b57cec5SDimitry Andric if (__a == allocator_type(__v.__alloc())) 28990b57cec5SDimitry Andric { 29000b57cec5SDimitry Andric this->__begin_ = __v.__begin_; 29010b57cec5SDimitry Andric this->__size_ = __v.__size_; 29020b57cec5SDimitry Andric this->__cap() = __v.__cap(); 29030b57cec5SDimitry Andric __v.__begin_ = nullptr; 29040b57cec5SDimitry Andric __v.__cap() = __v.__size_ = 0; 29050b57cec5SDimitry Andric } 29060b57cec5SDimitry Andric else if (__v.size() > 0) 29070b57cec5SDimitry Andric { 29080b57cec5SDimitry Andric __vallocate(__v.size()); 29090b57cec5SDimitry Andric __construct_at_end(__v.begin(), __v.end()); 29100b57cec5SDimitry Andric } 29110b57cec5SDimitry Andric} 29120b57cec5SDimitry Andric 29130b57cec5SDimitry Andrictemplate <class _Allocator> 29140b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 29150b57cec5SDimitry Andricvector<bool, _Allocator>& 29160b57cec5SDimitry Andricvector<bool, _Allocator>::operator=(vector&& __v) 29170b57cec5SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) 29180b57cec5SDimitry Andric{ 29190b57cec5SDimitry Andric __move_assign(__v, integral_constant<bool, 29200b57cec5SDimitry Andric __storage_traits::propagate_on_container_move_assignment::value>()); 29210b57cec5SDimitry Andric return *this; 29220b57cec5SDimitry Andric} 29230b57cec5SDimitry Andric 29240b57cec5SDimitry Andrictemplate <class _Allocator> 29250b57cec5SDimitry Andricvoid 29260b57cec5SDimitry Andricvector<bool, _Allocator>::__move_assign(vector& __c, false_type) 29270b57cec5SDimitry Andric{ 29280b57cec5SDimitry Andric if (__alloc() != __c.__alloc()) 29290b57cec5SDimitry Andric assign(__c.begin(), __c.end()); 29300b57cec5SDimitry Andric else 29310b57cec5SDimitry Andric __move_assign(__c, true_type()); 29320b57cec5SDimitry Andric} 29330b57cec5SDimitry Andric 29340b57cec5SDimitry Andrictemplate <class _Allocator> 29350b57cec5SDimitry Andricvoid 29360b57cec5SDimitry Andricvector<bool, _Allocator>::__move_assign(vector& __c, true_type) 29370b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 29380b57cec5SDimitry Andric{ 29390b57cec5SDimitry Andric __vdeallocate(); 29400b57cec5SDimitry Andric __move_assign_alloc(__c); 29410b57cec5SDimitry Andric this->__begin_ = __c.__begin_; 29420b57cec5SDimitry Andric this->__size_ = __c.__size_; 29430b57cec5SDimitry Andric this->__cap() = __c.__cap(); 29440b57cec5SDimitry Andric __c.__begin_ = nullptr; 29450b57cec5SDimitry Andric __c.__cap() = __c.__size_ = 0; 29460b57cec5SDimitry Andric} 29470b57cec5SDimitry Andric 29480b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG 29490b57cec5SDimitry Andric 29500b57cec5SDimitry Andrictemplate <class _Allocator> 29510b57cec5SDimitry Andricvoid 29520b57cec5SDimitry Andricvector<bool, _Allocator>::assign(size_type __n, const value_type& __x) 29530b57cec5SDimitry Andric{ 29540b57cec5SDimitry Andric __size_ = 0; 29550b57cec5SDimitry Andric if (__n > 0) 29560b57cec5SDimitry Andric { 29570b57cec5SDimitry Andric size_type __c = capacity(); 29580b57cec5SDimitry Andric if (__n <= __c) 29590b57cec5SDimitry Andric __size_ = __n; 29600b57cec5SDimitry Andric else 29610b57cec5SDimitry Andric { 29620b57cec5SDimitry Andric vector __v(__alloc()); 29630b57cec5SDimitry Andric __v.reserve(__recommend(__n)); 29640b57cec5SDimitry Andric __v.__size_ = __n; 29650b57cec5SDimitry Andric swap(__v); 29660b57cec5SDimitry Andric } 29670b57cec5SDimitry Andric _VSTD::fill_n(begin(), __n, __x); 29680b57cec5SDimitry Andric } 29690b57cec5SDimitry Andric __invalidate_all_iterators(); 29700b57cec5SDimitry Andric} 29710b57cec5SDimitry Andric 29720b57cec5SDimitry Andrictemplate <class _Allocator> 29730b57cec5SDimitry Andrictemplate <class _InputIterator> 29740b57cec5SDimitry Andrictypename enable_if 29750b57cec5SDimitry Andric< 2976480093f4SDimitry Andric __is_cpp17_input_iterator<_InputIterator>::value && 2977480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value, 29780b57cec5SDimitry Andric void 29790b57cec5SDimitry Andric>::type 29800b57cec5SDimitry Andricvector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last) 29810b57cec5SDimitry Andric{ 29820b57cec5SDimitry Andric clear(); 29830b57cec5SDimitry Andric for (; __first != __last; ++__first) 29840b57cec5SDimitry Andric push_back(*__first); 29850b57cec5SDimitry Andric} 29860b57cec5SDimitry Andric 29870b57cec5SDimitry Andrictemplate <class _Allocator> 29880b57cec5SDimitry Andrictemplate <class _ForwardIterator> 29890b57cec5SDimitry Andrictypename enable_if 29900b57cec5SDimitry Andric< 2991480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 29920b57cec5SDimitry Andric void 29930b57cec5SDimitry Andric>::type 29940b57cec5SDimitry Andricvector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) 29950b57cec5SDimitry Andric{ 29960b57cec5SDimitry Andric clear(); 29970b57cec5SDimitry Andric difference_type __ns = _VSTD::distance(__first, __last); 29980b57cec5SDimitry Andric _LIBCPP_ASSERT(__ns >= 0, "invalid range specified"); 29990b57cec5SDimitry Andric const size_t __n = static_cast<size_type>(__ns); 30000b57cec5SDimitry Andric if (__n) 30010b57cec5SDimitry Andric { 30020b57cec5SDimitry Andric if (__n > capacity()) 30030b57cec5SDimitry Andric { 30040b57cec5SDimitry Andric __vdeallocate(); 30050b57cec5SDimitry Andric __vallocate(__n); 30060b57cec5SDimitry Andric } 30070b57cec5SDimitry Andric __construct_at_end(__first, __last); 30080b57cec5SDimitry Andric } 30090b57cec5SDimitry Andric} 30100b57cec5SDimitry Andric 30110b57cec5SDimitry Andrictemplate <class _Allocator> 30120b57cec5SDimitry Andricvoid 30130b57cec5SDimitry Andricvector<bool, _Allocator>::reserve(size_type __n) 30140b57cec5SDimitry Andric{ 30150b57cec5SDimitry Andric if (__n > capacity()) 30160b57cec5SDimitry Andric { 30170b57cec5SDimitry Andric vector __v(this->__alloc()); 30180b57cec5SDimitry Andric __v.__vallocate(__n); 30190b57cec5SDimitry Andric __v.__construct_at_end(this->begin(), this->end()); 30200b57cec5SDimitry Andric swap(__v); 30210b57cec5SDimitry Andric __invalidate_all_iterators(); 30220b57cec5SDimitry Andric } 30230b57cec5SDimitry Andric} 30240b57cec5SDimitry Andric 30250b57cec5SDimitry Andrictemplate <class _Allocator> 30260b57cec5SDimitry Andricvoid 30270b57cec5SDimitry Andricvector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT 30280b57cec5SDimitry Andric{ 30290b57cec5SDimitry Andric if (__external_cap_to_internal(size()) > __cap()) 30300b57cec5SDimitry Andric { 30310b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 30320b57cec5SDimitry Andric try 30330b57cec5SDimitry Andric { 30340b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 30350b57cec5SDimitry Andric vector(*this, allocator_type(__alloc())).swap(*this); 30360b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 30370b57cec5SDimitry Andric } 30380b57cec5SDimitry Andric catch (...) 30390b57cec5SDimitry Andric { 30400b57cec5SDimitry Andric } 30410b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 30420b57cec5SDimitry Andric } 30430b57cec5SDimitry Andric} 30440b57cec5SDimitry Andric 30450b57cec5SDimitry Andrictemplate <class _Allocator> 30460b57cec5SDimitry Andrictypename vector<bool, _Allocator>::reference 30470b57cec5SDimitry Andricvector<bool, _Allocator>::at(size_type __n) 30480b57cec5SDimitry Andric{ 30490b57cec5SDimitry Andric if (__n >= size()) 30500b57cec5SDimitry Andric this->__throw_out_of_range(); 30510b57cec5SDimitry Andric return (*this)[__n]; 30520b57cec5SDimitry Andric} 30530b57cec5SDimitry Andric 30540b57cec5SDimitry Andrictemplate <class _Allocator> 30550b57cec5SDimitry Andrictypename vector<bool, _Allocator>::const_reference 30560b57cec5SDimitry Andricvector<bool, _Allocator>::at(size_type __n) const 30570b57cec5SDimitry Andric{ 30580b57cec5SDimitry Andric if (__n >= size()) 30590b57cec5SDimitry Andric this->__throw_out_of_range(); 30600b57cec5SDimitry Andric return (*this)[__n]; 30610b57cec5SDimitry Andric} 30620b57cec5SDimitry Andric 30630b57cec5SDimitry Andrictemplate <class _Allocator> 30640b57cec5SDimitry Andricvoid 30650b57cec5SDimitry Andricvector<bool, _Allocator>::push_back(const value_type& __x) 30660b57cec5SDimitry Andric{ 30670b57cec5SDimitry Andric if (this->__size_ == this->capacity()) 30680b57cec5SDimitry Andric reserve(__recommend(this->__size_ + 1)); 30690b57cec5SDimitry Andric ++this->__size_; 30700b57cec5SDimitry Andric back() = __x; 30710b57cec5SDimitry Andric} 30720b57cec5SDimitry Andric 30730b57cec5SDimitry Andrictemplate <class _Allocator> 30740b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator 30750b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x) 30760b57cec5SDimitry Andric{ 30770b57cec5SDimitry Andric iterator __r; 30780b57cec5SDimitry Andric if (size() < capacity()) 30790b57cec5SDimitry Andric { 30800b57cec5SDimitry Andric const_iterator __old_end = end(); 30810b57cec5SDimitry Andric ++__size_; 30820b57cec5SDimitry Andric _VSTD::copy_backward(__position, __old_end, end()); 30830b57cec5SDimitry Andric __r = __const_iterator_cast(__position); 30840b57cec5SDimitry Andric } 30850b57cec5SDimitry Andric else 30860b57cec5SDimitry Andric { 30870b57cec5SDimitry Andric vector __v(__alloc()); 30880b57cec5SDimitry Andric __v.reserve(__recommend(__size_ + 1)); 30890b57cec5SDimitry Andric __v.__size_ = __size_ + 1; 30900b57cec5SDimitry Andric __r = _VSTD::copy(cbegin(), __position, __v.begin()); 30910b57cec5SDimitry Andric _VSTD::copy_backward(__position, cend(), __v.end()); 30920b57cec5SDimitry Andric swap(__v); 30930b57cec5SDimitry Andric } 30940b57cec5SDimitry Andric *__r = __x; 30950b57cec5SDimitry Andric return __r; 30960b57cec5SDimitry Andric} 30970b57cec5SDimitry Andric 30980b57cec5SDimitry Andrictemplate <class _Allocator> 30990b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator 31000b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x) 31010b57cec5SDimitry Andric{ 31020b57cec5SDimitry Andric iterator __r; 31030b57cec5SDimitry Andric size_type __c = capacity(); 31040b57cec5SDimitry Andric if (__n <= __c && size() <= __c - __n) 31050b57cec5SDimitry Andric { 31060b57cec5SDimitry Andric const_iterator __old_end = end(); 31070b57cec5SDimitry Andric __size_ += __n; 31080b57cec5SDimitry Andric _VSTD::copy_backward(__position, __old_end, end()); 31090b57cec5SDimitry Andric __r = __const_iterator_cast(__position); 31100b57cec5SDimitry Andric } 31110b57cec5SDimitry Andric else 31120b57cec5SDimitry Andric { 31130b57cec5SDimitry Andric vector __v(__alloc()); 31140b57cec5SDimitry Andric __v.reserve(__recommend(__size_ + __n)); 31150b57cec5SDimitry Andric __v.__size_ = __size_ + __n; 31160b57cec5SDimitry Andric __r = _VSTD::copy(cbegin(), __position, __v.begin()); 31170b57cec5SDimitry Andric _VSTD::copy_backward(__position, cend(), __v.end()); 31180b57cec5SDimitry Andric swap(__v); 31190b57cec5SDimitry Andric } 31200b57cec5SDimitry Andric _VSTD::fill_n(__r, __n, __x); 31210b57cec5SDimitry Andric return __r; 31220b57cec5SDimitry Andric} 31230b57cec5SDimitry Andric 31240b57cec5SDimitry Andrictemplate <class _Allocator> 31250b57cec5SDimitry Andrictemplate <class _InputIterator> 31260b57cec5SDimitry Andrictypename enable_if 31270b57cec5SDimitry Andric< 3128480093f4SDimitry Andric __is_cpp17_input_iterator <_InputIterator>::value && 3129480093f4SDimitry Andric !__is_cpp17_forward_iterator<_InputIterator>::value, 31300b57cec5SDimitry Andric typename vector<bool, _Allocator>::iterator 31310b57cec5SDimitry Andric>::type 31320b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) 31330b57cec5SDimitry Andric{ 31340b57cec5SDimitry Andric difference_type __off = __position - begin(); 31350b57cec5SDimitry Andric iterator __p = __const_iterator_cast(__position); 31360b57cec5SDimitry Andric iterator __old_end = end(); 31370b57cec5SDimitry Andric for (; size() != capacity() && __first != __last; ++__first) 31380b57cec5SDimitry Andric { 31390b57cec5SDimitry Andric ++this->__size_; 31400b57cec5SDimitry Andric back() = *__first; 31410b57cec5SDimitry Andric } 31420b57cec5SDimitry Andric vector __v(__alloc()); 31430b57cec5SDimitry Andric if (__first != __last) 31440b57cec5SDimitry Andric { 31450b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 31460b57cec5SDimitry Andric try 31470b57cec5SDimitry Andric { 31480b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 31490b57cec5SDimitry Andric __v.assign(__first, __last); 31500b57cec5SDimitry Andric difference_type __old_size = static_cast<difference_type>(__old_end - begin()); 31510b57cec5SDimitry Andric difference_type __old_p = __p - begin(); 31520b57cec5SDimitry Andric reserve(__recommend(size() + __v.size())); 31530b57cec5SDimitry Andric __p = begin() + __old_p; 31540b57cec5SDimitry Andric __old_end = begin() + __old_size; 31550b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 31560b57cec5SDimitry Andric } 31570b57cec5SDimitry Andric catch (...) 31580b57cec5SDimitry Andric { 31590b57cec5SDimitry Andric erase(__old_end, end()); 31600b57cec5SDimitry Andric throw; 31610b57cec5SDimitry Andric } 31620b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 31630b57cec5SDimitry Andric } 31640b57cec5SDimitry Andric __p = _VSTD::rotate(__p, __old_end, end()); 31650b57cec5SDimitry Andric insert(__p, __v.begin(), __v.end()); 31660b57cec5SDimitry Andric return begin() + __off; 31670b57cec5SDimitry Andric} 31680b57cec5SDimitry Andric 31690b57cec5SDimitry Andrictemplate <class _Allocator> 31700b57cec5SDimitry Andrictemplate <class _ForwardIterator> 31710b57cec5SDimitry Andrictypename enable_if 31720b57cec5SDimitry Andric< 3173480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 31740b57cec5SDimitry Andric typename vector<bool, _Allocator>::iterator 31750b57cec5SDimitry Andric>::type 31760b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) 31770b57cec5SDimitry Andric{ 31780b57cec5SDimitry Andric const difference_type __n_signed = _VSTD::distance(__first, __last); 31790b57cec5SDimitry Andric _LIBCPP_ASSERT(__n_signed >= 0, "invalid range specified"); 31800b57cec5SDimitry Andric const size_type __n = static_cast<size_type>(__n_signed); 31810b57cec5SDimitry Andric iterator __r; 31820b57cec5SDimitry Andric size_type __c = capacity(); 31830b57cec5SDimitry Andric if (__n <= __c && size() <= __c - __n) 31840b57cec5SDimitry Andric { 31850b57cec5SDimitry Andric const_iterator __old_end = end(); 31860b57cec5SDimitry Andric __size_ += __n; 31870b57cec5SDimitry Andric _VSTD::copy_backward(__position, __old_end, end()); 31880b57cec5SDimitry Andric __r = __const_iterator_cast(__position); 31890b57cec5SDimitry Andric } 31900b57cec5SDimitry Andric else 31910b57cec5SDimitry Andric { 31920b57cec5SDimitry Andric vector __v(__alloc()); 31930b57cec5SDimitry Andric __v.reserve(__recommend(__size_ + __n)); 31940b57cec5SDimitry Andric __v.__size_ = __size_ + __n; 31950b57cec5SDimitry Andric __r = _VSTD::copy(cbegin(), __position, __v.begin()); 31960b57cec5SDimitry Andric _VSTD::copy_backward(__position, cend(), __v.end()); 31970b57cec5SDimitry Andric swap(__v); 31980b57cec5SDimitry Andric } 31990b57cec5SDimitry Andric _VSTD::copy(__first, __last, __r); 32000b57cec5SDimitry Andric return __r; 32010b57cec5SDimitry Andric} 32020b57cec5SDimitry Andric 32030b57cec5SDimitry Andrictemplate <class _Allocator> 32040b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 32050b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator 32060b57cec5SDimitry Andricvector<bool, _Allocator>::erase(const_iterator __position) 32070b57cec5SDimitry Andric{ 32080b57cec5SDimitry Andric iterator __r = __const_iterator_cast(__position); 32090b57cec5SDimitry Andric _VSTD::copy(__position + 1, this->cend(), __r); 32100b57cec5SDimitry Andric --__size_; 32110b57cec5SDimitry Andric return __r; 32120b57cec5SDimitry Andric} 32130b57cec5SDimitry Andric 32140b57cec5SDimitry Andrictemplate <class _Allocator> 32150b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator 32160b57cec5SDimitry Andricvector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last) 32170b57cec5SDimitry Andric{ 32180b57cec5SDimitry Andric iterator __r = __const_iterator_cast(__first); 32190b57cec5SDimitry Andric difference_type __d = __last - __first; 32200b57cec5SDimitry Andric _VSTD::copy(__last, this->cend(), __r); 32210b57cec5SDimitry Andric __size_ -= __d; 32220b57cec5SDimitry Andric return __r; 32230b57cec5SDimitry Andric} 32240b57cec5SDimitry Andric 32250b57cec5SDimitry Andrictemplate <class _Allocator> 32260b57cec5SDimitry Andricvoid 32270b57cec5SDimitry Andricvector<bool, _Allocator>::swap(vector& __x) 32280b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 32290b57cec5SDimitry Andric _NOEXCEPT 32300b57cec5SDimitry Andric#else 32310b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 32320b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value) 32330b57cec5SDimitry Andric#endif 32340b57cec5SDimitry Andric{ 32350b57cec5SDimitry Andric _VSTD::swap(this->__begin_, __x.__begin_); 32360b57cec5SDimitry Andric _VSTD::swap(this->__size_, __x.__size_); 32370b57cec5SDimitry Andric _VSTD::swap(this->__cap(), __x.__cap()); 32380b57cec5SDimitry Andric __swap_allocator(this->__alloc(), __x.__alloc(), 32390b57cec5SDimitry Andric integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>()); 32400b57cec5SDimitry Andric} 32410b57cec5SDimitry Andric 32420b57cec5SDimitry Andrictemplate <class _Allocator> 32430b57cec5SDimitry Andricvoid 32440b57cec5SDimitry Andricvector<bool, _Allocator>::resize(size_type __sz, value_type __x) 32450b57cec5SDimitry Andric{ 32460b57cec5SDimitry Andric size_type __cs = size(); 32470b57cec5SDimitry Andric if (__cs < __sz) 32480b57cec5SDimitry Andric { 32490b57cec5SDimitry Andric iterator __r; 32500b57cec5SDimitry Andric size_type __c = capacity(); 32510b57cec5SDimitry Andric size_type __n = __sz - __cs; 32520b57cec5SDimitry Andric if (__n <= __c && __cs <= __c - __n) 32530b57cec5SDimitry Andric { 32540b57cec5SDimitry Andric __r = end(); 32550b57cec5SDimitry Andric __size_ += __n; 32560b57cec5SDimitry Andric } 32570b57cec5SDimitry Andric else 32580b57cec5SDimitry Andric { 32590b57cec5SDimitry Andric vector __v(__alloc()); 32600b57cec5SDimitry Andric __v.reserve(__recommend(__size_ + __n)); 32610b57cec5SDimitry Andric __v.__size_ = __size_ + __n; 32620b57cec5SDimitry Andric __r = _VSTD::copy(cbegin(), cend(), __v.begin()); 32630b57cec5SDimitry Andric swap(__v); 32640b57cec5SDimitry Andric } 32650b57cec5SDimitry Andric _VSTD::fill_n(__r, __n, __x); 32660b57cec5SDimitry Andric } 32670b57cec5SDimitry Andric else 32680b57cec5SDimitry Andric __size_ = __sz; 32690b57cec5SDimitry Andric} 32700b57cec5SDimitry Andric 32710b57cec5SDimitry Andrictemplate <class _Allocator> 32720b57cec5SDimitry Andricvoid 32730b57cec5SDimitry Andricvector<bool, _Allocator>::flip() _NOEXCEPT 32740b57cec5SDimitry Andric{ 32750b57cec5SDimitry Andric // do middle whole words 32760b57cec5SDimitry Andric size_type __n = __size_; 32770b57cec5SDimitry Andric __storage_pointer __p = __begin_; 32780b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 32790b57cec5SDimitry Andric *__p = ~*__p; 32800b57cec5SDimitry Andric // do last partial word 32810b57cec5SDimitry Andric if (__n > 0) 32820b57cec5SDimitry Andric { 32830b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 32840b57cec5SDimitry Andric __storage_type __b = *__p & __m; 32850b57cec5SDimitry Andric *__p &= ~__m; 32860b57cec5SDimitry Andric *__p |= ~__b & __m; 32870b57cec5SDimitry Andric } 32880b57cec5SDimitry Andric} 32890b57cec5SDimitry Andric 32900b57cec5SDimitry Andrictemplate <class _Allocator> 32910b57cec5SDimitry Andricbool 32920b57cec5SDimitry Andricvector<bool, _Allocator>::__invariants() const 32930b57cec5SDimitry Andric{ 32940b57cec5SDimitry Andric if (this->__begin_ == nullptr) 32950b57cec5SDimitry Andric { 32960b57cec5SDimitry Andric if (this->__size_ != 0 || this->__cap() != 0) 32970b57cec5SDimitry Andric return false; 32980b57cec5SDimitry Andric } 32990b57cec5SDimitry Andric else 33000b57cec5SDimitry Andric { 33010b57cec5SDimitry Andric if (this->__cap() == 0) 33020b57cec5SDimitry Andric return false; 33030b57cec5SDimitry Andric if (this->__size_ > this->capacity()) 33040b57cec5SDimitry Andric return false; 33050b57cec5SDimitry Andric } 33060b57cec5SDimitry Andric return true; 33070b57cec5SDimitry Andric} 33080b57cec5SDimitry Andric 33090b57cec5SDimitry Andrictemplate <class _Allocator> 33100b57cec5SDimitry Andricsize_t 33110b57cec5SDimitry Andricvector<bool, _Allocator>::__hash_code() const _NOEXCEPT 33120b57cec5SDimitry Andric{ 33130b57cec5SDimitry Andric size_t __h = 0; 33140b57cec5SDimitry Andric // do middle whole words 33150b57cec5SDimitry Andric size_type __n = __size_; 33160b57cec5SDimitry Andric __storage_pointer __p = __begin_; 33170b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 33180b57cec5SDimitry Andric __h ^= *__p; 33190b57cec5SDimitry Andric // do last partial word 33200b57cec5SDimitry Andric if (__n > 0) 33210b57cec5SDimitry Andric { 33220b57cec5SDimitry Andric const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 33230b57cec5SDimitry Andric __h ^= *__p & __m; 33240b57cec5SDimitry Andric } 33250b57cec5SDimitry Andric return __h; 33260b57cec5SDimitry Andric} 33270b57cec5SDimitry Andric 33280b57cec5SDimitry Andrictemplate <class _Allocator> 33290b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> > 33300b57cec5SDimitry Andric : public unary_function<vector<bool, _Allocator>, size_t> 33310b57cec5SDimitry Andric{ 33320b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 33330b57cec5SDimitry Andric size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT 33340b57cec5SDimitry Andric {return __vec.__hash_code();} 33350b57cec5SDimitry Andric}; 33360b57cec5SDimitry Andric 33370b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 33380b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 33390b57cec5SDimitry Andricbool 33400b57cec5SDimitry Andricoperator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 33410b57cec5SDimitry Andric{ 33420b57cec5SDimitry Andric const typename vector<_Tp, _Allocator>::size_type __sz = __x.size(); 33430b57cec5SDimitry Andric return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); 33440b57cec5SDimitry Andric} 33450b57cec5SDimitry Andric 33460b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 33470b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 33480b57cec5SDimitry Andricbool 33490b57cec5SDimitry Andricoperator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 33500b57cec5SDimitry Andric{ 33510b57cec5SDimitry Andric return !(__x == __y); 33520b57cec5SDimitry Andric} 33530b57cec5SDimitry Andric 33540b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 33550b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 33560b57cec5SDimitry Andricbool 33570b57cec5SDimitry Andricoperator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 33580b57cec5SDimitry Andric{ 33590b57cec5SDimitry Andric return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); 33600b57cec5SDimitry Andric} 33610b57cec5SDimitry Andric 33620b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 33630b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 33640b57cec5SDimitry Andricbool 33650b57cec5SDimitry Andricoperator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 33660b57cec5SDimitry Andric{ 33670b57cec5SDimitry Andric return __y < __x; 33680b57cec5SDimitry Andric} 33690b57cec5SDimitry Andric 33700b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 33710b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 33720b57cec5SDimitry Andricbool 33730b57cec5SDimitry Andricoperator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 33740b57cec5SDimitry Andric{ 33750b57cec5SDimitry Andric return !(__x < __y); 33760b57cec5SDimitry Andric} 33770b57cec5SDimitry Andric 33780b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 33790b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 33800b57cec5SDimitry Andricbool 33810b57cec5SDimitry Andricoperator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 33820b57cec5SDimitry Andric{ 33830b57cec5SDimitry Andric return !(__y < __x); 33840b57cec5SDimitry Andric} 33850b57cec5SDimitry Andric 33860b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 33870b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 33880b57cec5SDimitry Andricvoid 33890b57cec5SDimitry Andricswap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) 33900b57cec5SDimitry Andric _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 33910b57cec5SDimitry Andric{ 33920b57cec5SDimitry Andric __x.swap(__y); 33930b57cec5SDimitry Andric} 33940b57cec5SDimitry Andric 33950b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17 33960b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Up> 3397*5ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type 3398*5ffd83dbSDimitry Andricerase(vector<_Tp, _Allocator>& __c, const _Up& __v) { 3399*5ffd83dbSDimitry Andric auto __old_size = __c.size(); 3400*5ffd83dbSDimitry Andric __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end()); 3401*5ffd83dbSDimitry Andric return __old_size - __c.size(); 3402*5ffd83dbSDimitry Andric} 34030b57cec5SDimitry Andric 34040b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Predicate> 3405*5ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type 3406*5ffd83dbSDimitry Andricerase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) { 3407*5ffd83dbSDimitry Andric auto __old_size = __c.size(); 3408*5ffd83dbSDimitry Andric __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end()); 3409*5ffd83dbSDimitry Andric return __old_size - __c.size(); 3410*5ffd83dbSDimitry Andric} 34110b57cec5SDimitry Andric#endif 34120b57cec5SDimitry Andric 34130b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 34140b57cec5SDimitry Andric 34150b57cec5SDimitry Andric_LIBCPP_POP_MACROS 34160b57cec5SDimitry Andric 34170b57cec5SDimitry Andric#endif // _LIBCPP_VECTOR 3418