10b57cec5SDimitry Andric// -*- C++ -*- 2349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 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; 147fe6060f1SDimitry Andric reference& operator=(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()) 248349cc55cSDimitry Andric -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17 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> 2645ffd83dbSDimitry Andrictypename vector<T, Allocator>::size_type 2655ffd83dbSDimitry Andricerase(vector<T, Allocator>& c, const U& value); // C++20 2660b57cec5SDimitry Andrictemplate <class T, class Allocator, class Predicate> 2675ffd83dbSDimitry Andrictypename vector<T, Allocator>::size_type 2685ffd83dbSDimitry Andricerase_if(vector<T, Allocator>& c, Predicate pred); // C++20 2690b57cec5SDimitry Andric 2700b57cec5SDimitry Andric} // std 2710b57cec5SDimitry Andric 2720b57cec5SDimitry Andric*/ 2730b57cec5SDimitry Andric 27481ad6265SDimitry Andric#include <__algorithm/copy.h> 27581ad6265SDimitry Andric#include <__algorithm/equal.h> 27681ad6265SDimitry Andric#include <__algorithm/fill_n.h> 27781ad6265SDimitry Andric#include <__algorithm/lexicographical_compare.h> 27881ad6265SDimitry Andric#include <__algorithm/remove.h> 27981ad6265SDimitry Andric#include <__algorithm/remove_if.h> 28081ad6265SDimitry Andric#include <__algorithm/rotate.h> 28181ad6265SDimitry Andric#include <__algorithm/unwrap_iter.h> 28281ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler 2830b57cec5SDimitry Andric#include <__bit_reference> 28404eeddc0SDimitry Andric#include <__config> 285fe6060f1SDimitry Andric#include <__debug> 28681ad6265SDimitry Andric#include <__format/enable_insertable.h> 28781ad6265SDimitry Andric#include <__functional/hash.h> 28881ad6265SDimitry Andric#include <__functional/unary_function.h> 28981ad6265SDimitry Andric#include <__iterator/advance.h> 290349cc55cSDimitry Andric#include <__iterator/iterator_traits.h> 29181ad6265SDimitry Andric#include <__iterator/reverse_iterator.h> 292fe6060f1SDimitry Andric#include <__iterator/wrap_iter.h> 29381ad6265SDimitry Andric#include <__memory/allocate_at_least.h> 294972a253aSDimitry Andric#include <__memory/pointer_traits.h> 295972a253aSDimitry Andric#include <__memory/swap_allocator.h> 296fe6060f1SDimitry Andric#include <__split_buffer> 297fe6060f1SDimitry Andric#include <__utility/forward.h> 29881ad6265SDimitry Andric#include <__utility/move.h> 29981ad6265SDimitry Andric#include <__utility/swap.h> 3000b57cec5SDimitry Andric#include <climits> 30169ade1e0SDimitry Andric#include <cstdlib> 302fe6060f1SDimitry Andric#include <cstring> 303fe6060f1SDimitry Andric#include <iosfwd> // for forward declaration of vector 304fe6060f1SDimitry Andric#include <limits> 3050b57cec5SDimitry Andric#include <memory> 3060b57cec5SDimitry Andric#include <stdexcept> 307fe6060f1SDimitry Andric#include <type_traits> 3080b57cec5SDimitry Andric#include <version> 3090b57cec5SDimitry Andric 31081ad6265SDimitry Andric#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES 31181ad6265SDimitry Andric# include <algorithm> 31281ad6265SDimitry Andric# include <typeinfo> 31381ad6265SDimitry Andric# include <utility> 31481ad6265SDimitry Andric#endif 31581ad6265SDimitry Andric 31681ad6265SDimitry Andric// standard-mandated includes 31781ad6265SDimitry Andric 31881ad6265SDimitry Andric// [iterator.range] 31981ad6265SDimitry Andric#include <__iterator/access.h> 32081ad6265SDimitry Andric#include <__iterator/data.h> 32181ad6265SDimitry Andric#include <__iterator/empty.h> 32281ad6265SDimitry Andric#include <__iterator/reverse_access.h> 32381ad6265SDimitry Andric#include <__iterator/size.h> 32481ad6265SDimitry Andric 32581ad6265SDimitry Andric// [vector.syn] 32681ad6265SDimitry Andric#include <compare> 32781ad6265SDimitry Andric#include <initializer_list> 32881ad6265SDimitry Andric 3290b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 3300b57cec5SDimitry Andric# pragma GCC system_header 3310b57cec5SDimitry Andric#endif 3320b57cec5SDimitry Andric 3330b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS 3340b57cec5SDimitry Andric#include <__undef_macros> 3350b57cec5SDimitry Andric 3360b57cec5SDimitry Andric 3370b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 3380b57cec5SDimitry Andric 3390b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator /* = allocator<_Tp> */> 3400b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector 3410b57cec5SDimitry Andric{ 3420b57cec5SDimitry Andricprivate: 3430b57cec5SDimitry Andric typedef allocator<_Tp> __default_allocator_type; 3440b57cec5SDimitry Andricpublic: 3450b57cec5SDimitry Andric typedef vector __self; 3460b57cec5SDimitry Andric typedef _Tp value_type; 3470b57cec5SDimitry Andric typedef _Allocator allocator_type; 348349cc55cSDimitry Andric typedef allocator_traits<allocator_type> __alloc_traits; 349349cc55cSDimitry Andric typedef value_type& reference; 350349cc55cSDimitry Andric typedef const value_type& const_reference; 3514824e7fdSDimitry Andric typedef typename __alloc_traits::size_type size_type; 352349cc55cSDimitry Andric typedef typename __alloc_traits::difference_type difference_type; 353349cc55cSDimitry Andric typedef typename __alloc_traits::pointer pointer; 354349cc55cSDimitry Andric typedef typename __alloc_traits::const_pointer const_pointer; 3550b57cec5SDimitry Andric typedef __wrap_iter<pointer> iterator; 3560b57cec5SDimitry Andric typedef __wrap_iter<const_pointer> const_iterator; 3570b57cec5SDimitry Andric typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 3580b57cec5SDimitry Andric typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 3590b57cec5SDimitry Andric 3600b57cec5SDimitry Andric static_assert((is_same<typename allocator_type::value_type, value_type>::value), 3610b57cec5SDimitry Andric "Allocator::value_type must be same type as value_type"); 3620b57cec5SDimitry Andric 363*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 3640b57cec5SDimitry Andric vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 3650b57cec5SDimitry Andric { 36604eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 3670b57cec5SDimitry Andric } 368*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) 3690b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 3700b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) 3710b57cec5SDimitry Andric#else 3720b57cec5SDimitry Andric _NOEXCEPT 3730b57cec5SDimitry Andric#endif 374d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 3750b57cec5SDimitry Andric { 37604eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 3770b57cec5SDimitry Andric } 378*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit vector(size_type __n); 3790b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 380*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit vector(size_type __n, const allocator_type& __a); 3810b57cec5SDimitry Andric#endif 382*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(size_type __n, const value_type& __x); 3834824e7fdSDimitry Andric 3844824e7fdSDimitry Andric template <class = __enable_if_t<__is_allocator<_Allocator>::value> > 385*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 3864824e7fdSDimitry Andric vector(size_type __n, const value_type& __x, const allocator_type& __a) 387d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 3884824e7fdSDimitry Andric { 38904eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 3904824e7fdSDimitry Andric if (__n > 0) 3914824e7fdSDimitry Andric { 3924824e7fdSDimitry Andric __vallocate(__n); 3934824e7fdSDimitry Andric __construct_at_end(__n, __x); 3944824e7fdSDimitry Andric } 3954824e7fdSDimitry Andric } 3964824e7fdSDimitry Andric 3970b57cec5SDimitry Andric template <class _InputIterator> 398*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 3990b57cec5SDimitry Andric vector(_InputIterator __first, 400753f127fSDimitry Andric typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value && 4010b57cec5SDimitry Andric is_constructible< 4020b57cec5SDimitry Andric value_type, 4030b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 4040b57cec5SDimitry Andric _InputIterator>::type __last); 4050b57cec5SDimitry Andric template <class _InputIterator> 406*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 4070b57cec5SDimitry Andric vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 408753f127fSDimitry Andric typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value && 4090b57cec5SDimitry Andric is_constructible< 4100b57cec5SDimitry Andric value_type, 4110b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value>::type* = 0); 4120b57cec5SDimitry Andric template <class _ForwardIterator> 413*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 4140b57cec5SDimitry Andric vector(_ForwardIterator __first, 415480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value && 4160b57cec5SDimitry Andric is_constructible< 4170b57cec5SDimitry Andric value_type, 4180b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 4190b57cec5SDimitry Andric _ForwardIterator>::type __last); 4200b57cec5SDimitry Andric template <class _ForwardIterator> 421*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 4220b57cec5SDimitry Andric vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 423480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value && 4240b57cec5SDimitry Andric is_constructible< 4250b57cec5SDimitry Andric value_type, 4260b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0); 4270b57cec5SDimitry Andric 428*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 4290b57cec5SDimitry Andric ~vector() 4300b57cec5SDimitry Andric { 4310b57cec5SDimitry Andric __annotate_delete(); 43281ad6265SDimitry Andric std::__debug_db_erase_c(this); 433349cc55cSDimitry Andric 434349cc55cSDimitry Andric if (this->__begin_ != nullptr) 435349cc55cSDimitry Andric { 436349cc55cSDimitry Andric __clear(); 437349cc55cSDimitry Andric __alloc_traits::deallocate(__alloc(), this->__begin_, capacity()); 438349cc55cSDimitry Andric } 4390b57cec5SDimitry Andric } 4400b57cec5SDimitry Andric 441*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(const vector& __x); 442*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(const vector& __x, const __type_identity_t<allocator_type>& __a); 443*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 4440b57cec5SDimitry Andric vector& operator=(const vector& __x); 4450b57cec5SDimitry Andric 4460b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 447*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 4480b57cec5SDimitry Andric vector(initializer_list<value_type> __il); 4490b57cec5SDimitry Andric 450*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 4510b57cec5SDimitry Andric vector(initializer_list<value_type> __il, const allocator_type& __a); 4520b57cec5SDimitry Andric 453*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 45481ad6265SDimitry Andric vector& operator=(initializer_list<value_type> __il) 45581ad6265SDimitry Andric {assign(__il.begin(), __il.end()); return *this;} 45681ad6265SDimitry Andric#endif // !_LIBCPP_CXX03_LANG 45781ad6265SDimitry Andric 458*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 4590b57cec5SDimitry Andric vector(vector&& __x) 4600b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 46181ad6265SDimitry Andric noexcept; 4620b57cec5SDimitry Andric#else 4630b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); 4640b57cec5SDimitry Andric#endif 4650b57cec5SDimitry Andric 466*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 46781ad6265SDimitry Andric vector(vector&& __x, const __type_identity_t<allocator_type>& __a); 468*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 4690b57cec5SDimitry Andric vector& operator=(vector&& __x) 4700b57cec5SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); 4710b57cec5SDimitry Andric 4720b57cec5SDimitry Andric template <class _InputIterator> 473*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value && 4740b57cec5SDimitry Andric is_constructible< 4750b57cec5SDimitry Andric value_type, 4760b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 4770b57cec5SDimitry Andric void 4780b57cec5SDimitry Andric >::type 4790b57cec5SDimitry Andric assign(_InputIterator __first, _InputIterator __last); 4800b57cec5SDimitry Andric template <class _ForwardIterator> 481*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 4820b57cec5SDimitry Andric typename enable_if 4830b57cec5SDimitry Andric < 484480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value && 4850b57cec5SDimitry Andric is_constructible< 4860b57cec5SDimitry Andric value_type, 4870b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 4880b57cec5SDimitry Andric void 4890b57cec5SDimitry Andric >::type 4900b57cec5SDimitry Andric assign(_ForwardIterator __first, _ForwardIterator __last); 4910b57cec5SDimitry Andric 492*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void assign(size_type __n, const_reference __u); 4930b57cec5SDimitry Andric 4940b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 495*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 4960b57cec5SDimitry Andric void assign(initializer_list<value_type> __il) 4970b57cec5SDimitry Andric {assign(__il.begin(), __il.end());} 4980b57cec5SDimitry Andric#endif 4990b57cec5SDimitry Andric 500*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 5010b57cec5SDimitry Andric allocator_type get_allocator() const _NOEXCEPT 5020b57cec5SDimitry Andric {return this->__alloc();} 5030b57cec5SDimitry Andric 504*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT; 505*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT; 506*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT; 507*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT; 5080b57cec5SDimitry Andric 509*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 5100b57cec5SDimitry Andric reverse_iterator rbegin() _NOEXCEPT 5110b57cec5SDimitry Andric {return reverse_iterator(end());} 512*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 5130b57cec5SDimitry Andric const_reverse_iterator rbegin() const _NOEXCEPT 5140b57cec5SDimitry Andric {return const_reverse_iterator(end());} 515*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 5160b57cec5SDimitry Andric reverse_iterator rend() _NOEXCEPT 5170b57cec5SDimitry Andric {return reverse_iterator(begin());} 518*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 5190b57cec5SDimitry Andric const_reverse_iterator rend() const _NOEXCEPT 5200b57cec5SDimitry Andric {return const_reverse_iterator(begin());} 5210b57cec5SDimitry Andric 522*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 5230b57cec5SDimitry Andric const_iterator cbegin() const _NOEXCEPT 5240b57cec5SDimitry Andric {return begin();} 525*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 5260b57cec5SDimitry Andric const_iterator cend() const _NOEXCEPT 5270b57cec5SDimitry Andric {return end();} 528*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 5290b57cec5SDimitry Andric const_reverse_iterator crbegin() const _NOEXCEPT 5300b57cec5SDimitry Andric {return rbegin();} 531*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 5320b57cec5SDimitry Andric const_reverse_iterator crend() const _NOEXCEPT 5330b57cec5SDimitry Andric {return rend();} 5340b57cec5SDimitry Andric 535*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 5360b57cec5SDimitry Andric size_type size() const _NOEXCEPT 5370b57cec5SDimitry Andric {return static_cast<size_type>(this->__end_ - this->__begin_);} 538*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 5390b57cec5SDimitry Andric size_type capacity() const _NOEXCEPT 540349cc55cSDimitry Andric {return static_cast<size_type>(__end_cap() - this->__begin_);} 541*61cfbce3SDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 5420b57cec5SDimitry Andric bool empty() const _NOEXCEPT 5430b57cec5SDimitry Andric {return this->__begin_ == this->__end_;} 544*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type max_size() const _NOEXCEPT; 545*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void reserve(size_type __n); 546*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void shrink_to_fit() _NOEXCEPT; 5470b57cec5SDimitry Andric 548*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) _NOEXCEPT; 549*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const _NOEXCEPT; 550*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 reference at(size_type __n); 551*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference at(size_type __n) const; 5520b57cec5SDimitry Andric 553*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT 5540b57cec5SDimitry Andric { 555fe6060f1SDimitry Andric _LIBCPP_ASSERT(!empty(), "front() called on an empty vector"); 5560b57cec5SDimitry Andric return *this->__begin_; 5570b57cec5SDimitry Andric } 558*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT 5590b57cec5SDimitry Andric { 560fe6060f1SDimitry Andric _LIBCPP_ASSERT(!empty(), "front() called on an empty vector"); 5610b57cec5SDimitry Andric return *this->__begin_; 5620b57cec5SDimitry Andric } 563*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT 5640b57cec5SDimitry Andric { 565fe6060f1SDimitry Andric _LIBCPP_ASSERT(!empty(), "back() called on an empty vector"); 5660b57cec5SDimitry Andric return *(this->__end_ - 1); 5670b57cec5SDimitry Andric } 568*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT 5690b57cec5SDimitry Andric { 570fe6060f1SDimitry Andric _LIBCPP_ASSERT(!empty(), "back() called on an empty vector"); 5710b57cec5SDimitry Andric return *(this->__end_ - 1); 5720b57cec5SDimitry Andric } 5730b57cec5SDimitry Andric 574*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 5750b57cec5SDimitry Andric value_type* data() _NOEXCEPT 576480093f4SDimitry Andric {return _VSTD::__to_address(this->__begin_);} 577*61cfbce3SDimitry Andric 578*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 5790b57cec5SDimitry Andric const value_type* data() const _NOEXCEPT 580480093f4SDimitry Andric {return _VSTD::__to_address(this->__begin_);} 5810b57cec5SDimitry Andric 582*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x); 5830b57cec5SDimitry Andric 584*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x); 5850b57cec5SDimitry Andric 5860b57cec5SDimitry Andric template <class... _Args> 587*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 5880b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 5890b57cec5SDimitry Andric reference emplace_back(_Args&&... __args); 5900b57cec5SDimitry Andric#else 5910b57cec5SDimitry Andric void emplace_back(_Args&&... __args); 5920b57cec5SDimitry Andric#endif 5930b57cec5SDimitry Andric 594*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 5950b57cec5SDimitry Andric void pop_back(); 5960b57cec5SDimitry Andric 597*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator insert(const_iterator __position, const_reference __x); 5980b57cec5SDimitry Andric 599*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator insert(const_iterator __position, value_type&& __x); 6000b57cec5SDimitry Andric template <class... _Args> 601*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator emplace(const_iterator __position, _Args&&... __args); 6020b57cec5SDimitry Andric 603*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator insert(const_iterator __position, size_type __n, const_reference __x); 6040b57cec5SDimitry Andric template <class _InputIterator> 605*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value && 6060b57cec5SDimitry Andric is_constructible< 6070b57cec5SDimitry Andric value_type, 6080b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 6090b57cec5SDimitry Andric iterator 6100b57cec5SDimitry Andric >::type 6110b57cec5SDimitry Andric insert(const_iterator __position, _InputIterator __first, _InputIterator __last); 6120b57cec5SDimitry Andric template <class _ForwardIterator> 613*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 6140b57cec5SDimitry Andric typename enable_if 6150b57cec5SDimitry Andric < 616480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value && 6170b57cec5SDimitry Andric is_constructible< 6180b57cec5SDimitry Andric value_type, 6190b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 6200b57cec5SDimitry Andric iterator 6210b57cec5SDimitry Andric >::type 6220b57cec5SDimitry Andric insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); 6230b57cec5SDimitry Andric 6240b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 625*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 6260b57cec5SDimitry Andric iterator insert(const_iterator __position, initializer_list<value_type> __il) 6270b57cec5SDimitry Andric {return insert(__position, __il.begin(), __il.end());} 6280b57cec5SDimitry Andric#endif 6290b57cec5SDimitry Andric 630*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); 631*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator erase(const_iterator __first, const_iterator __last); 6320b57cec5SDimitry Andric 633*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 6340b57cec5SDimitry Andric void clear() _NOEXCEPT 6350b57cec5SDimitry Andric { 6360b57cec5SDimitry Andric size_type __old_size = size(); 637349cc55cSDimitry Andric __clear(); 6380b57cec5SDimitry Andric __annotate_shrink(__old_size); 63981ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 6400b57cec5SDimitry Andric } 6410b57cec5SDimitry Andric 642*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void resize(size_type __sz); 643*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void resize(size_type __sz, const_reference __x); 6440b57cec5SDimitry Andric 645*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void swap(vector&) 6460b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 6470b57cec5SDimitry Andric _NOEXCEPT; 6480b57cec5SDimitry Andric#else 6490b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 6500b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value); 6510b57cec5SDimitry Andric#endif 6520b57cec5SDimitry Andric 653*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 bool __invariants() const; 6540b57cec5SDimitry Andric 65581ad6265SDimitry Andric#ifdef _LIBCPP_ENABLE_DEBUG_MODE 6560b57cec5SDimitry Andric 6570b57cec5SDimitry Andric bool __dereferenceable(const const_iterator* __i) const; 6580b57cec5SDimitry Andric bool __decrementable(const const_iterator* __i) const; 6590b57cec5SDimitry Andric bool __addable(const const_iterator* __i, ptrdiff_t __n) const; 6600b57cec5SDimitry Andric bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; 6610b57cec5SDimitry Andric 66281ad6265SDimitry Andric#endif // _LIBCPP_ENABLE_DEBUG_MODE 6630b57cec5SDimitry Andric 6640b57cec5SDimitry Andricprivate: 665d56accc7SDimitry Andric pointer __begin_ = nullptr; 666d56accc7SDimitry Andric pointer __end_ = nullptr; 667d56accc7SDimitry Andric __compressed_pair<pointer, allocator_type> __end_cap_ = 668d56accc7SDimitry Andric __compressed_pair<pointer, allocator_type>(nullptr, __default_init_tag()); 669d56accc7SDimitry Andric 6700b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last); 67181ad6265SDimitry Andric 67281ad6265SDimitry Andric // Allocate space for __n objects 67381ad6265SDimitry Andric // throws length_error if __n > max_size() 67481ad6265SDimitry Andric // throws (probably bad_alloc) if memory run out 67581ad6265SDimitry Andric // Precondition: __begin_ == __end_ == __end_cap() == 0 67681ad6265SDimitry Andric // Precondition: __n > 0 67781ad6265SDimitry Andric // Postcondition: capacity() >= __n 67881ad6265SDimitry Andric // Postcondition: size() == 0 679*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) { 68081ad6265SDimitry Andric if (__n > max_size()) 68181ad6265SDimitry Andric __throw_length_error(); 68281ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __n); 68381ad6265SDimitry Andric __begin_ = __allocation.ptr; 68481ad6265SDimitry Andric __end_ = __allocation.ptr; 68581ad6265SDimitry Andric __end_cap() = __begin_ + __allocation.count; 68681ad6265SDimitry Andric __annotate_new(0); 68781ad6265SDimitry Andric } 68881ad6265SDimitry Andric 689*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void __vdeallocate() _NOEXCEPT; 690*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; 691*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void __construct_at_end(size_type __n); 692*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 6930b57cec5SDimitry Andric void __construct_at_end(size_type __n, const_reference __x); 6940b57cec5SDimitry Andric template <class _ForwardIterator> 695*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 6960b57cec5SDimitry Andric typename enable_if 6970b57cec5SDimitry Andric < 698480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 6990b57cec5SDimitry Andric void 7000b57cec5SDimitry Andric >::type 7010b57cec5SDimitry Andric __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n); 702*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void __append(size_type __n); 703*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void __append(size_type __n, const_reference __x); 704*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 7050b57cec5SDimitry Andric iterator __make_iter(pointer __p) _NOEXCEPT; 706*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 7070b57cec5SDimitry Andric const_iterator __make_iter(const_pointer __p) const _NOEXCEPT; 708*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v); 709*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p); 710*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void __move_range(pointer __from_s, pointer __from_e, pointer __to); 711*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void __move_assign(vector& __c, true_type) 7120b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); 713*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void __move_assign(vector& __c, false_type) 7140b57cec5SDimitry Andric _NOEXCEPT_(__alloc_traits::is_always_equal::value); 715*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 7160b57cec5SDimitry Andric void __destruct_at_end(pointer __new_last) _NOEXCEPT 7170b57cec5SDimitry Andric { 718*61cfbce3SDimitry Andric if (!__libcpp_is_constant_evaluated()) 7190b57cec5SDimitry Andric __invalidate_iterators_past(__new_last); 7200b57cec5SDimitry Andric size_type __old_size = size(); 721349cc55cSDimitry Andric __base_destruct_at_end(__new_last); 7220b57cec5SDimitry Andric __annotate_shrink(__old_size); 7230b57cec5SDimitry Andric } 7240b57cec5SDimitry Andric 7250b57cec5SDimitry Andric template <class _Up> 726*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 7270b57cec5SDimitry Andric inline void __push_back_slow_path(_Up&& __x); 7280b57cec5SDimitry Andric 7290b57cec5SDimitry Andric template <class... _Args> 730*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 7310b57cec5SDimitry Andric inline void __emplace_back_slow_path(_Args&&... __args); 7320b57cec5SDimitry Andric 7330b57cec5SDimitry Andric // The following functions are no-ops outside of AddressSanitizer mode. 7340b57cec5SDimitry Andric // We call annotatations only for the default Allocator because other allocators 7350b57cec5SDimitry Andric // may not meet the AddressSanitizer alignment constraints. 7360b57cec5SDimitry Andric // See the documentation for __sanitizer_annotate_contiguous_container for more details. 7370b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN 738*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 7390b57cec5SDimitry Andric void __annotate_contiguous_container(const void *__beg, const void *__end, 7400b57cec5SDimitry Andric const void *__old_mid, 7410b57cec5SDimitry Andric const void *__new_mid) const 7420b57cec5SDimitry Andric { 7430b57cec5SDimitry Andric 744*61cfbce3SDimitry Andric if (!__libcpp_is_constant_evaluated() && __beg && is_same<allocator_type, __default_allocator_type>::value) 7450b57cec5SDimitry Andric __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid); 7460b57cec5SDimitry Andric } 7470b57cec5SDimitry Andric#else 748*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 7490b57cec5SDimitry Andric void __annotate_contiguous_container(const void*, const void*, const void*, 750e40139ffSDimitry Andric const void*) const _NOEXCEPT {} 7510b57cec5SDimitry Andric#endif 752*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 753e40139ffSDimitry Andric void __annotate_new(size_type __current_size) const _NOEXCEPT { 7540b57cec5SDimitry Andric __annotate_contiguous_container(data(), data() + capacity(), 7550b57cec5SDimitry Andric data() + capacity(), data() + __current_size); 7560b57cec5SDimitry Andric } 7570b57cec5SDimitry Andric 758*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 759e40139ffSDimitry Andric void __annotate_delete() const _NOEXCEPT { 7600b57cec5SDimitry Andric __annotate_contiguous_container(data(), data() + capacity(), 7610b57cec5SDimitry Andric data() + size(), data() + capacity()); 7620b57cec5SDimitry Andric } 7630b57cec5SDimitry Andric 764*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 765e40139ffSDimitry Andric void __annotate_increase(size_type __n) const _NOEXCEPT 7660b57cec5SDimitry Andric { 7670b57cec5SDimitry Andric __annotate_contiguous_container(data(), data() + capacity(), 7680b57cec5SDimitry Andric data() + size(), data() + size() + __n); 7690b57cec5SDimitry Andric } 7700b57cec5SDimitry Andric 771*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 772e40139ffSDimitry Andric void __annotate_shrink(size_type __old_size) const _NOEXCEPT 7730b57cec5SDimitry Andric { 7740b57cec5SDimitry Andric __annotate_contiguous_container(data(), data() + capacity(), 7750b57cec5SDimitry Andric data() + __old_size, data() + size()); 7760b57cec5SDimitry Andric } 7770b57cec5SDimitry Andric 778e40139ffSDimitry Andric struct _ConstructTransaction { 779*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 780e40139ffSDimitry Andric explicit _ConstructTransaction(vector &__v, size_type __n) 781e40139ffSDimitry Andric : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) { 782e40139ffSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN 783e40139ffSDimitry Andric __v_.__annotate_increase(__n); 784e40139ffSDimitry Andric#endif 785e40139ffSDimitry Andric } 786*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 ~_ConstructTransaction() { 787e40139ffSDimitry Andric __v_.__end_ = __pos_; 788e40139ffSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN 789e40139ffSDimitry Andric if (__pos_ != __new_end_) { 790e40139ffSDimitry Andric __v_.__annotate_shrink(__new_end_ - __v_.__begin_); 791e40139ffSDimitry Andric } 792e40139ffSDimitry Andric#endif 793e40139ffSDimitry Andric } 794e40139ffSDimitry Andric 795e40139ffSDimitry Andric vector &__v_; 796e40139ffSDimitry Andric pointer __pos_; 797e40139ffSDimitry Andric const_pointer const __new_end_; 798e40139ffSDimitry Andric 799e40139ffSDimitry Andric private: 800e40139ffSDimitry Andric _ConstructTransaction(_ConstructTransaction const&) = delete; 801e40139ffSDimitry Andric _ConstructTransaction& operator=(_ConstructTransaction const&) = delete; 802e40139ffSDimitry Andric }; 803e40139ffSDimitry Andric 804e40139ffSDimitry Andric template <class ..._Args> 805*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 806e40139ffSDimitry Andric void __construct_one_at_end(_Args&& ...__args) { 807e40139ffSDimitry Andric _ConstructTransaction __tx(*this, 1); 808480093f4SDimitry Andric __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__tx.__pos_), 809e40139ffSDimitry Andric _VSTD::forward<_Args>(__args)...); 810e40139ffSDimitry Andric ++__tx.__pos_; 811e40139ffSDimitry Andric } 812349cc55cSDimitry Andric 813*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 814349cc55cSDimitry Andric allocator_type& __alloc() _NOEXCEPT 815349cc55cSDimitry Andric {return this->__end_cap_.second();} 816*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 817349cc55cSDimitry Andric const allocator_type& __alloc() const _NOEXCEPT 818349cc55cSDimitry Andric {return this->__end_cap_.second();} 819*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 820349cc55cSDimitry Andric pointer& __end_cap() _NOEXCEPT 821349cc55cSDimitry Andric {return this->__end_cap_.first();} 822*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 823349cc55cSDimitry Andric const pointer& __end_cap() const _NOEXCEPT 824349cc55cSDimitry Andric {return this->__end_cap_.first();} 825349cc55cSDimitry Andric 826*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 827349cc55cSDimitry Andric void __clear() _NOEXCEPT {__base_destruct_at_end(this->__begin_);} 828349cc55cSDimitry Andric 829*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 830349cc55cSDimitry Andric void __base_destruct_at_end(pointer __new_last) _NOEXCEPT { 831349cc55cSDimitry Andric pointer __soon_to_be_end = this->__end_; 832349cc55cSDimitry Andric while (__new_last != __soon_to_be_end) 833349cc55cSDimitry Andric __alloc_traits::destroy(__alloc(), _VSTD::__to_address(--__soon_to_be_end)); 834349cc55cSDimitry Andric this->__end_ = __new_last; 835349cc55cSDimitry Andric } 836349cc55cSDimitry Andric 837*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 838349cc55cSDimitry Andric void __copy_assign_alloc(const vector& __c) 839349cc55cSDimitry Andric {__copy_assign_alloc(__c, integral_constant<bool, 840349cc55cSDimitry Andric __alloc_traits::propagate_on_container_copy_assignment::value>());} 841349cc55cSDimitry Andric 842*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 843349cc55cSDimitry Andric void __move_assign_alloc(vector& __c) 844349cc55cSDimitry Andric _NOEXCEPT_( 845349cc55cSDimitry Andric !__alloc_traits::propagate_on_container_move_assignment::value || 846349cc55cSDimitry Andric is_nothrow_move_assignable<allocator_type>::value) 847349cc55cSDimitry Andric {__move_assign_alloc(__c, integral_constant<bool, 848349cc55cSDimitry Andric __alloc_traits::propagate_on_container_move_assignment::value>());} 849349cc55cSDimitry Andric 850349cc55cSDimitry Andric _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI 851349cc55cSDimitry Andric void __throw_length_error() const { 852d56accc7SDimitry Andric _VSTD::__throw_length_error("vector"); 853349cc55cSDimitry Andric } 854349cc55cSDimitry Andric 855349cc55cSDimitry Andric _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI 856349cc55cSDimitry Andric void __throw_out_of_range() const { 857d56accc7SDimitry Andric _VSTD::__throw_out_of_range("vector"); 858349cc55cSDimitry Andric } 859349cc55cSDimitry Andric 860*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 861349cc55cSDimitry Andric void __copy_assign_alloc(const vector& __c, true_type) 862349cc55cSDimitry Andric { 863349cc55cSDimitry Andric if (__alloc() != __c.__alloc()) 864349cc55cSDimitry Andric { 865349cc55cSDimitry Andric __clear(); 866349cc55cSDimitry Andric __alloc_traits::deallocate(__alloc(), this->__begin_, capacity()); 867349cc55cSDimitry Andric this->__begin_ = this->__end_ = __end_cap() = nullptr; 868349cc55cSDimitry Andric } 869349cc55cSDimitry Andric __alloc() = __c.__alloc(); 870349cc55cSDimitry Andric } 871349cc55cSDimitry Andric 872*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 873349cc55cSDimitry Andric void __copy_assign_alloc(const vector&, false_type) 874349cc55cSDimitry Andric {} 875349cc55cSDimitry Andric 876*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 877349cc55cSDimitry Andric void __move_assign_alloc(vector& __c, true_type) 878349cc55cSDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 879349cc55cSDimitry Andric { 880349cc55cSDimitry Andric __alloc() = _VSTD::move(__c.__alloc()); 881349cc55cSDimitry Andric } 882349cc55cSDimitry Andric 883*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 884349cc55cSDimitry Andric void __move_assign_alloc(vector&, false_type) 885349cc55cSDimitry Andric _NOEXCEPT 886349cc55cSDimitry Andric {} 8870b57cec5SDimitry Andric}; 8880b57cec5SDimitry Andric 889349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17 8900b57cec5SDimitry Andrictemplate<class _InputIterator, 891fe6060f1SDimitry Andric class _Alloc = allocator<__iter_value_type<_InputIterator>>, 892349cc55cSDimitry Andric class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 893349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Alloc>::value> 8940b57cec5SDimitry Andric > 8950b57cec5SDimitry Andricvector(_InputIterator, _InputIterator) 896fe6060f1SDimitry Andric -> vector<__iter_value_type<_InputIterator>, _Alloc>; 8970b57cec5SDimitry Andric 8980b57cec5SDimitry Andrictemplate<class _InputIterator, 8990b57cec5SDimitry Andric class _Alloc, 900349cc55cSDimitry Andric class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 901349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Alloc>::value> 9020b57cec5SDimitry Andric > 9030b57cec5SDimitry Andricvector(_InputIterator, _InputIterator, _Alloc) 904fe6060f1SDimitry Andric -> vector<__iter_value_type<_InputIterator>, _Alloc>; 9050b57cec5SDimitry Andric#endif 9060b57cec5SDimitry Andric 9070b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 908*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 9090b57cec5SDimitry Andricvoid 9100b57cec5SDimitry Andricvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v) 9110b57cec5SDimitry Andric{ 9120b57cec5SDimitry Andric __annotate_delete(); 913972a253aSDimitry Andric using _RevIter = std::reverse_iterator<pointer>; 914972a253aSDimitry Andric __v.__begin_ = std::__uninitialized_allocator_move_if_noexcept( 915972a253aSDimitry Andric __alloc(), _RevIter(__end_), _RevIter(__begin_), _RevIter(__v.__begin_)) 916972a253aSDimitry Andric .base(); 9170b57cec5SDimitry Andric _VSTD::swap(this->__begin_, __v.__begin_); 9180b57cec5SDimitry Andric _VSTD::swap(this->__end_, __v.__end_); 9190b57cec5SDimitry Andric _VSTD::swap(this->__end_cap(), __v.__end_cap()); 9200b57cec5SDimitry Andric __v.__first_ = __v.__begin_; 9210b57cec5SDimitry Andric __annotate_new(size()); 92281ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 9230b57cec5SDimitry Andric} 9240b57cec5SDimitry Andric 9250b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 926*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 9270b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::pointer 9280b57cec5SDimitry Andricvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p) 9290b57cec5SDimitry Andric{ 9300b57cec5SDimitry Andric __annotate_delete(); 9310b57cec5SDimitry Andric pointer __r = __v.__begin_; 932972a253aSDimitry Andric using _RevIter = std::reverse_iterator<pointer>; 933972a253aSDimitry Andric __v.__begin_ = std::__uninitialized_allocator_move_if_noexcept( 934972a253aSDimitry Andric __alloc(), _RevIter(__p), _RevIter(__begin_), _RevIter(__v.__begin_)) 935972a253aSDimitry Andric .base(); 936972a253aSDimitry Andric __v.__end_ = std::__uninitialized_allocator_move_if_noexcept(__alloc(), __p, __end_, __v.__end_); 9370b57cec5SDimitry Andric _VSTD::swap(this->__begin_, __v.__begin_); 9380b57cec5SDimitry Andric _VSTD::swap(this->__end_, __v.__end_); 9390b57cec5SDimitry Andric _VSTD::swap(this->__end_cap(), __v.__end_cap()); 9400b57cec5SDimitry Andric __v.__first_ = __v.__begin_; 9410b57cec5SDimitry Andric __annotate_new(size()); 94281ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 9430b57cec5SDimitry Andric return __r; 9440b57cec5SDimitry Andric} 9450b57cec5SDimitry Andric 9460b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 947*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 9480b57cec5SDimitry Andricvoid 9490b57cec5SDimitry Andricvector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT 9500b57cec5SDimitry Andric{ 9510b57cec5SDimitry Andric if (this->__begin_ != nullptr) 9520b57cec5SDimitry Andric { 9530b57cec5SDimitry Andric clear(); 9540b57cec5SDimitry Andric __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity()); 9550b57cec5SDimitry Andric this->__begin_ = this->__end_ = this->__end_cap() = nullptr; 9560b57cec5SDimitry Andric } 9570b57cec5SDimitry Andric} 9580b57cec5SDimitry Andric 9590b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 960*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 9610b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::size_type 9620b57cec5SDimitry Andricvector<_Tp, _Allocator>::max_size() const _NOEXCEPT 9630b57cec5SDimitry Andric{ 9640b57cec5SDimitry Andric return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()), 9650b57cec5SDimitry Andric numeric_limits<difference_type>::max()); 9660b57cec5SDimitry Andric} 9670b57cec5SDimitry Andric 9680b57cec5SDimitry Andric// Precondition: __new_size > capacity() 9690b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 970*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 9710b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 9720b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::size_type 9730b57cec5SDimitry Andricvector<_Tp, _Allocator>::__recommend(size_type __new_size) const 9740b57cec5SDimitry Andric{ 9750b57cec5SDimitry Andric const size_type __ms = max_size(); 9760b57cec5SDimitry Andric if (__new_size > __ms) 9770b57cec5SDimitry Andric this->__throw_length_error(); 9780b57cec5SDimitry Andric const size_type __cap = capacity(); 9790b57cec5SDimitry Andric if (__cap >= __ms / 2) 9800b57cec5SDimitry Andric return __ms; 9810b57cec5SDimitry Andric return _VSTD::max<size_type>(2 * __cap, __new_size); 9820b57cec5SDimitry Andric} 9830b57cec5SDimitry Andric 9840b57cec5SDimitry Andric// Default constructs __n objects starting at __end_ 9850b57cec5SDimitry Andric// throws if construction throws 9860b57cec5SDimitry Andric// Precondition: __n > 0 9870b57cec5SDimitry Andric// Precondition: size() + __n <= capacity() 9880b57cec5SDimitry Andric// Postcondition: size() == size() + __n 9890b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 990*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 9910b57cec5SDimitry Andricvoid 9920b57cec5SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(size_type __n) 9930b57cec5SDimitry Andric{ 994e40139ffSDimitry Andric _ConstructTransaction __tx(*this, __n); 9955ffd83dbSDimitry Andric const_pointer __new_end = __tx.__new_end_; 996349cc55cSDimitry Andric for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) { 9975ffd83dbSDimitry Andric __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos)); 998e40139ffSDimitry Andric } 9990b57cec5SDimitry Andric} 10000b57cec5SDimitry Andric 10010b57cec5SDimitry Andric// Copy constructs __n objects starting at __end_ from __x 10020b57cec5SDimitry Andric// throws if construction throws 10030b57cec5SDimitry Andric// Precondition: __n > 0 10040b57cec5SDimitry Andric// Precondition: size() + __n <= capacity() 10050b57cec5SDimitry Andric// Postcondition: size() == old size() + __n 10060b57cec5SDimitry Andric// Postcondition: [i] == __x for all i in [size() - __n, __n) 10070b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1008*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 10090b57cec5SDimitry Andricinline 10100b57cec5SDimitry Andricvoid 10110b57cec5SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) 10120b57cec5SDimitry Andric{ 1013e40139ffSDimitry Andric _ConstructTransaction __tx(*this, __n); 10145ffd83dbSDimitry Andric const_pointer __new_end = __tx.__new_end_; 1015349cc55cSDimitry Andric for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) { 10165ffd83dbSDimitry Andric __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos), __x); 1017e40139ffSDimitry Andric } 10180b57cec5SDimitry Andric} 10190b57cec5SDimitry Andric 10200b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 10210b57cec5SDimitry Andrictemplate <class _ForwardIterator> 1022*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 10230b57cec5SDimitry Andrictypename enable_if 10240b57cec5SDimitry Andric< 1025480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 10260b57cec5SDimitry Andric void 10270b57cec5SDimitry Andric>::type 10280b57cec5SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n) 10290b57cec5SDimitry Andric{ 1030e40139ffSDimitry Andric _ConstructTransaction __tx(*this, __n); 1031972a253aSDimitry Andric __tx.__pos_ = std::__uninitialized_allocator_copy(__alloc(), __first, __last, __tx.__pos_); 10320b57cec5SDimitry Andric} 10330b57cec5SDimitry Andric 10340b57cec5SDimitry Andric// Default constructs __n objects starting at __end_ 10350b57cec5SDimitry Andric// throws if construction throws 10360b57cec5SDimitry Andric// Postcondition: size() == size() + __n 10370b57cec5SDimitry Andric// Exception safety: strong. 10380b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1039*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 10400b57cec5SDimitry Andricvoid 10410b57cec5SDimitry Andricvector<_Tp, _Allocator>::__append(size_type __n) 10420b57cec5SDimitry Andric{ 10430b57cec5SDimitry Andric if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) 10440b57cec5SDimitry Andric this->__construct_at_end(__n); 10450b57cec5SDimitry Andric else 10460b57cec5SDimitry Andric { 10470b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 10480b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); 10490b57cec5SDimitry Andric __v.__construct_at_end(__n); 10500b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 10510b57cec5SDimitry Andric } 10520b57cec5SDimitry Andric} 10530b57cec5SDimitry Andric 10540b57cec5SDimitry Andric// Default constructs __n objects starting at __end_ 10550b57cec5SDimitry Andric// throws if construction throws 10560b57cec5SDimitry Andric// Postcondition: size() == size() + __n 10570b57cec5SDimitry Andric// Exception safety: strong. 10580b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1059*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 10600b57cec5SDimitry Andricvoid 10610b57cec5SDimitry Andricvector<_Tp, _Allocator>::__append(size_type __n, const_reference __x) 10620b57cec5SDimitry Andric{ 10630b57cec5SDimitry Andric if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) 10640b57cec5SDimitry Andric this->__construct_at_end(__n, __x); 10650b57cec5SDimitry Andric else 10660b57cec5SDimitry Andric { 10670b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 10680b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); 10690b57cec5SDimitry Andric __v.__construct_at_end(__n, __x); 10700b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 10710b57cec5SDimitry Andric } 10720b57cec5SDimitry Andric} 10730b57cec5SDimitry Andric 10740b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1075*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 10760b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n) 10770b57cec5SDimitry Andric{ 107804eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 10790b57cec5SDimitry Andric if (__n > 0) 10800b57cec5SDimitry Andric { 10810b57cec5SDimitry Andric __vallocate(__n); 10820b57cec5SDimitry Andric __construct_at_end(__n); 10830b57cec5SDimitry Andric } 10840b57cec5SDimitry Andric} 10850b57cec5SDimitry Andric 10860b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 10870b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1088*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 10890b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a) 1090d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 10910b57cec5SDimitry Andric{ 109204eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 10930b57cec5SDimitry Andric if (__n > 0) 10940b57cec5SDimitry Andric { 10950b57cec5SDimitry Andric __vallocate(__n); 10960b57cec5SDimitry Andric __construct_at_end(__n); 10970b57cec5SDimitry Andric } 10980b57cec5SDimitry Andric} 10990b57cec5SDimitry Andric#endif 11000b57cec5SDimitry Andric 11010b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1102*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 11030b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x) 11040b57cec5SDimitry Andric{ 110504eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 11060b57cec5SDimitry Andric if (__n > 0) 11070b57cec5SDimitry Andric { 11080b57cec5SDimitry Andric __vallocate(__n); 11090b57cec5SDimitry Andric __construct_at_end(__n, __x); 11100b57cec5SDimitry Andric } 11110b57cec5SDimitry Andric} 11120b57cec5SDimitry Andric 11130b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11140b57cec5SDimitry Andrictemplate <class _InputIterator> 1115*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 11160b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_InputIterator __first, 1117753f127fSDimitry Andric typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value && 11180b57cec5SDimitry Andric is_constructible< 11190b57cec5SDimitry Andric value_type, 11200b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 11210b57cec5SDimitry Andric _InputIterator>::type __last) 11220b57cec5SDimitry Andric{ 112304eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 11240b57cec5SDimitry Andric for (; __first != __last; ++__first) 112581ad6265SDimitry Andric emplace_back(*__first); 11260b57cec5SDimitry Andric} 11270b57cec5SDimitry Andric 11280b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11290b57cec5SDimitry Andrictemplate <class _InputIterator> 1130*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 11310b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 1132753f127fSDimitry Andric typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value && 11330b57cec5SDimitry Andric is_constructible< 11340b57cec5SDimitry Andric value_type, 11350b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value>::type*) 1136d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 11370b57cec5SDimitry Andric{ 113804eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 11390b57cec5SDimitry Andric for (; __first != __last; ++__first) 114081ad6265SDimitry Andric emplace_back(*__first); 11410b57cec5SDimitry Andric} 11420b57cec5SDimitry Andric 11430b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11440b57cec5SDimitry Andrictemplate <class _ForwardIterator> 1145*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 11460b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_ForwardIterator __first, 1147480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value && 11480b57cec5SDimitry Andric is_constructible< 11490b57cec5SDimitry Andric value_type, 11500b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 11510b57cec5SDimitry Andric _ForwardIterator>::type __last) 11520b57cec5SDimitry Andric{ 115304eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 11540b57cec5SDimitry Andric size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 11550b57cec5SDimitry Andric if (__n > 0) 11560b57cec5SDimitry Andric { 11570b57cec5SDimitry Andric __vallocate(__n); 11580b57cec5SDimitry Andric __construct_at_end(__first, __last, __n); 11590b57cec5SDimitry Andric } 11600b57cec5SDimitry Andric} 11610b57cec5SDimitry Andric 11620b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 11630b57cec5SDimitry Andrictemplate <class _ForwardIterator> 1164*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 11650b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 1166480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value && 11670b57cec5SDimitry Andric is_constructible< 11680b57cec5SDimitry Andric value_type, 11690b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value>::type*) 1170d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 11710b57cec5SDimitry Andric{ 117204eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 11730b57cec5SDimitry Andric size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 11740b57cec5SDimitry Andric if (__n > 0) 11750b57cec5SDimitry Andric { 11760b57cec5SDimitry Andric __vallocate(__n); 11770b57cec5SDimitry Andric __construct_at_end(__first, __last, __n); 11780b57cec5SDimitry Andric } 11790b57cec5SDimitry Andric} 11800b57cec5SDimitry Andric 11810b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1182*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 11830b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(const vector& __x) 1184d56accc7SDimitry Andric : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc())) 11850b57cec5SDimitry Andric{ 118604eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 11870b57cec5SDimitry Andric size_type __n = __x.size(); 11880b57cec5SDimitry Andric if (__n > 0) 11890b57cec5SDimitry Andric { 11900b57cec5SDimitry Andric __vallocate(__n); 11910b57cec5SDimitry Andric __construct_at_end(__x.__begin_, __x.__end_, __n); 11920b57cec5SDimitry Andric } 11930b57cec5SDimitry Andric} 11940b57cec5SDimitry Andric 11950b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1196*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 119781ad6265SDimitry Andricvector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t<allocator_type>& __a) 1198d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 11990b57cec5SDimitry Andric{ 120004eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 12010b57cec5SDimitry Andric size_type __n = __x.size(); 12020b57cec5SDimitry Andric if (__n > 0) 12030b57cec5SDimitry Andric { 12040b57cec5SDimitry Andric __vallocate(__n); 12050b57cec5SDimitry Andric __construct_at_end(__x.__begin_, __x.__end_, __n); 12060b57cec5SDimitry Andric } 12070b57cec5SDimitry Andric} 12080b57cec5SDimitry Andric 12090b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1210*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 12110b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 12120b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(vector&& __x) 12130b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 121481ad6265SDimitry Andric noexcept 12150b57cec5SDimitry Andric#else 12160b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 12170b57cec5SDimitry Andric#endif 1218d56accc7SDimitry Andric : __end_cap_(nullptr, _VSTD::move(__x.__alloc())) 12190b57cec5SDimitry Andric{ 122004eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 122181ad6265SDimitry Andric std::__debug_db_swap(this, std::addressof(__x)); 12220b57cec5SDimitry Andric this->__begin_ = __x.__begin_; 12230b57cec5SDimitry Andric this->__end_ = __x.__end_; 12240b57cec5SDimitry Andric this->__end_cap() = __x.__end_cap(); 12250b57cec5SDimitry Andric __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; 12260b57cec5SDimitry Andric} 12270b57cec5SDimitry Andric 12280b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1229*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 12300b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 123181ad6265SDimitry Andricvector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_type>& __a) 1232d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 12330b57cec5SDimitry Andric{ 123404eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 12350b57cec5SDimitry Andric if (__a == __x.__alloc()) 12360b57cec5SDimitry Andric { 12370b57cec5SDimitry Andric this->__begin_ = __x.__begin_; 12380b57cec5SDimitry Andric this->__end_ = __x.__end_; 12390b57cec5SDimitry Andric this->__end_cap() = __x.__end_cap(); 12400b57cec5SDimitry Andric __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; 124181ad6265SDimitry Andric std::__debug_db_swap(this, std::addressof(__x)); 12420b57cec5SDimitry Andric } 12430b57cec5SDimitry Andric else 12440b57cec5SDimitry Andric { 12450b57cec5SDimitry Andric typedef move_iterator<iterator> _Ip; 12460b57cec5SDimitry Andric assign(_Ip(__x.begin()), _Ip(__x.end())); 12470b57cec5SDimitry Andric } 12480b57cec5SDimitry Andric} 12490b57cec5SDimitry Andric 125081ad6265SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 125181ad6265SDimitry Andric 12520b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1253*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 12540b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 12550b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il) 12560b57cec5SDimitry Andric{ 125704eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 12580b57cec5SDimitry Andric if (__il.size() > 0) 12590b57cec5SDimitry Andric { 12600b57cec5SDimitry Andric __vallocate(__il.size()); 12610b57cec5SDimitry Andric __construct_at_end(__il.begin(), __il.end(), __il.size()); 12620b57cec5SDimitry Andric } 12630b57cec5SDimitry Andric} 12640b57cec5SDimitry Andric 12650b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1266*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 12670b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 12680b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) 1269d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 12700b57cec5SDimitry Andric{ 127104eeddc0SDimitry Andric _VSTD::__debug_db_insert_c(this); 12720b57cec5SDimitry Andric if (__il.size() > 0) 12730b57cec5SDimitry Andric { 12740b57cec5SDimitry Andric __vallocate(__il.size()); 12750b57cec5SDimitry Andric __construct_at_end(__il.begin(), __il.end(), __il.size()); 12760b57cec5SDimitry Andric } 12770b57cec5SDimitry Andric} 12780b57cec5SDimitry Andric 127981ad6265SDimitry Andric#endif // _LIBCPP_CXX03_LANG 128081ad6265SDimitry Andric 12810b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1282*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 12830b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 12840b57cec5SDimitry Andricvector<_Tp, _Allocator>& 12850b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator=(vector&& __x) 12860b57cec5SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) 12870b57cec5SDimitry Andric{ 12880b57cec5SDimitry Andric __move_assign(__x, integral_constant<bool, 12890b57cec5SDimitry Andric __alloc_traits::propagate_on_container_move_assignment::value>()); 12900b57cec5SDimitry Andric return *this; 12910b57cec5SDimitry Andric} 12920b57cec5SDimitry Andric 12930b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1294*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 12950b57cec5SDimitry Andricvoid 12960b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_assign(vector& __c, false_type) 12970b57cec5SDimitry Andric _NOEXCEPT_(__alloc_traits::is_always_equal::value) 12980b57cec5SDimitry Andric{ 1299349cc55cSDimitry Andric if (__alloc() != __c.__alloc()) 13000b57cec5SDimitry Andric { 13010b57cec5SDimitry Andric typedef move_iterator<iterator> _Ip; 13020b57cec5SDimitry Andric assign(_Ip(__c.begin()), _Ip(__c.end())); 13030b57cec5SDimitry Andric } 13040b57cec5SDimitry Andric else 13050b57cec5SDimitry Andric __move_assign(__c, true_type()); 13060b57cec5SDimitry Andric} 13070b57cec5SDimitry Andric 13080b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1309*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 13100b57cec5SDimitry Andricvoid 13110b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_assign(vector& __c, true_type) 13120b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 13130b57cec5SDimitry Andric{ 13140b57cec5SDimitry Andric __vdeallocate(); 1315349cc55cSDimitry Andric __move_assign_alloc(__c); // this can throw 13160b57cec5SDimitry Andric this->__begin_ = __c.__begin_; 13170b57cec5SDimitry Andric this->__end_ = __c.__end_; 13180b57cec5SDimitry Andric this->__end_cap() = __c.__end_cap(); 13190b57cec5SDimitry Andric __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr; 132081ad6265SDimitry Andric std::__debug_db_swap(this, std::addressof(__c)); 13210b57cec5SDimitry Andric} 13220b57cec5SDimitry Andric 13230b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1324*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 13250b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 13260b57cec5SDimitry Andricvector<_Tp, _Allocator>& 13270b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator=(const vector& __x) 13280b57cec5SDimitry Andric{ 1329349cc55cSDimitry Andric if (this != _VSTD::addressof(__x)) 13300b57cec5SDimitry Andric { 1331349cc55cSDimitry Andric __copy_assign_alloc(__x); 13320b57cec5SDimitry Andric assign(__x.__begin_, __x.__end_); 13330b57cec5SDimitry Andric } 13340b57cec5SDimitry Andric return *this; 13350b57cec5SDimitry Andric} 13360b57cec5SDimitry Andric 13370b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 13380b57cec5SDimitry Andrictemplate <class _InputIterator> 1339*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value && 13400b57cec5SDimitry Andric is_constructible< 13410b57cec5SDimitry Andric _Tp, 13420b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 13430b57cec5SDimitry Andric void 13440b57cec5SDimitry Andric>::type 13450b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last) 13460b57cec5SDimitry Andric{ 13470b57cec5SDimitry Andric clear(); 13480b57cec5SDimitry Andric for (; __first != __last; ++__first) 134981ad6265SDimitry Andric emplace_back(*__first); 13500b57cec5SDimitry Andric} 13510b57cec5SDimitry Andric 13520b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 13530b57cec5SDimitry Andrictemplate <class _ForwardIterator> 1354*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 13550b57cec5SDimitry Andrictypename enable_if 13560b57cec5SDimitry Andric< 1357480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value && 13580b57cec5SDimitry Andric is_constructible< 13590b57cec5SDimitry Andric _Tp, 13600b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 13610b57cec5SDimitry Andric void 13620b57cec5SDimitry Andric>::type 13630b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) 13640b57cec5SDimitry Andric{ 13650b57cec5SDimitry Andric size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last)); 13660b57cec5SDimitry Andric if (__new_size <= capacity()) 13670b57cec5SDimitry Andric { 13680b57cec5SDimitry Andric _ForwardIterator __mid = __last; 13690b57cec5SDimitry Andric bool __growing = false; 13700b57cec5SDimitry Andric if (__new_size > size()) 13710b57cec5SDimitry Andric { 13720b57cec5SDimitry Andric __growing = true; 13730b57cec5SDimitry Andric __mid = __first; 13740b57cec5SDimitry Andric _VSTD::advance(__mid, size()); 13750b57cec5SDimitry Andric } 13760b57cec5SDimitry Andric pointer __m = _VSTD::copy(__first, __mid, this->__begin_); 13770b57cec5SDimitry Andric if (__growing) 13780b57cec5SDimitry Andric __construct_at_end(__mid, __last, __new_size - size()); 13790b57cec5SDimitry Andric else 13800b57cec5SDimitry Andric this->__destruct_at_end(__m); 13810b57cec5SDimitry Andric } 13820b57cec5SDimitry Andric else 13830b57cec5SDimitry Andric { 13840b57cec5SDimitry Andric __vdeallocate(); 13850b57cec5SDimitry Andric __vallocate(__recommend(__new_size)); 13860b57cec5SDimitry Andric __construct_at_end(__first, __last, __new_size); 13870b57cec5SDimitry Andric } 138881ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 13890b57cec5SDimitry Andric} 13900b57cec5SDimitry Andric 13910b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1392*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 13930b57cec5SDimitry Andricvoid 13940b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(size_type __n, const_reference __u) 13950b57cec5SDimitry Andric{ 13960b57cec5SDimitry Andric if (__n <= capacity()) 13970b57cec5SDimitry Andric { 13980b57cec5SDimitry Andric size_type __s = size(); 13990b57cec5SDimitry Andric _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u); 14000b57cec5SDimitry Andric if (__n > __s) 14010b57cec5SDimitry Andric __construct_at_end(__n - __s, __u); 14020b57cec5SDimitry Andric else 14030b57cec5SDimitry Andric this->__destruct_at_end(this->__begin_ + __n); 14040b57cec5SDimitry Andric } 14050b57cec5SDimitry Andric else 14060b57cec5SDimitry Andric { 14070b57cec5SDimitry Andric __vdeallocate(); 14080b57cec5SDimitry Andric __vallocate(__recommend(static_cast<size_type>(__n))); 14090b57cec5SDimitry Andric __construct_at_end(__n, __u); 14100b57cec5SDimitry Andric } 141181ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 14120b57cec5SDimitry Andric} 14130b57cec5SDimitry Andric 14140b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1415*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 14160b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 14170b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 14180b57cec5SDimitry Andricvector<_Tp, _Allocator>::begin() _NOEXCEPT 14190b57cec5SDimitry Andric{ 142081ad6265SDimitry Andric return iterator(this, this->__begin_); 14210b57cec5SDimitry Andric} 14220b57cec5SDimitry Andric 14230b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1424*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 14250b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 14260b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_iterator 14270b57cec5SDimitry Andricvector<_Tp, _Allocator>::begin() const _NOEXCEPT 14280b57cec5SDimitry Andric{ 142981ad6265SDimitry Andric return const_iterator(this, this->__begin_); 14300b57cec5SDimitry Andric} 14310b57cec5SDimitry Andric 14320b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1433*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 14340b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 14350b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 14360b57cec5SDimitry Andricvector<_Tp, _Allocator>::end() _NOEXCEPT 14370b57cec5SDimitry Andric{ 143881ad6265SDimitry Andric return iterator(this, this->__end_); 14390b57cec5SDimitry Andric} 14400b57cec5SDimitry Andric 14410b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1442*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 14430b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 14440b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_iterator 14450b57cec5SDimitry Andricvector<_Tp, _Allocator>::end() const _NOEXCEPT 14460b57cec5SDimitry Andric{ 144781ad6265SDimitry Andric return const_iterator(this, this->__end_); 14480b57cec5SDimitry Andric} 14490b57cec5SDimitry Andric 14500b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1451*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 14520b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 14530b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference 14540b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT 14550b57cec5SDimitry Andric{ 14560b57cec5SDimitry Andric _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); 14570b57cec5SDimitry Andric return this->__begin_[__n]; 14580b57cec5SDimitry Andric} 14590b57cec5SDimitry Andric 14600b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1461*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 14620b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 14630b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_reference 14640b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT 14650b57cec5SDimitry Andric{ 14660b57cec5SDimitry Andric _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); 14670b57cec5SDimitry Andric return this->__begin_[__n]; 14680b57cec5SDimitry Andric} 14690b57cec5SDimitry Andric 14700b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1471*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 14720b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference 14730b57cec5SDimitry Andricvector<_Tp, _Allocator>::at(size_type __n) 14740b57cec5SDimitry Andric{ 14750b57cec5SDimitry Andric if (__n >= size()) 14760b57cec5SDimitry Andric this->__throw_out_of_range(); 14770b57cec5SDimitry Andric return this->__begin_[__n]; 14780b57cec5SDimitry Andric} 14790b57cec5SDimitry Andric 14800b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1481*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 14820b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_reference 14830b57cec5SDimitry Andricvector<_Tp, _Allocator>::at(size_type __n) const 14840b57cec5SDimitry Andric{ 14850b57cec5SDimitry Andric if (__n >= size()) 14860b57cec5SDimitry Andric this->__throw_out_of_range(); 14870b57cec5SDimitry Andric return this->__begin_[__n]; 14880b57cec5SDimitry Andric} 14890b57cec5SDimitry Andric 14900b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1491*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 14920b57cec5SDimitry Andricvoid 14930b57cec5SDimitry Andricvector<_Tp, _Allocator>::reserve(size_type __n) 14940b57cec5SDimitry Andric{ 14950b57cec5SDimitry Andric if (__n > capacity()) 14960b57cec5SDimitry Andric { 1497349cc55cSDimitry Andric if (__n > max_size()) 1498349cc55cSDimitry Andric this->__throw_length_error(); 14990b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 15000b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__n, size(), __a); 15010b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 15020b57cec5SDimitry Andric } 15030b57cec5SDimitry Andric} 15040b57cec5SDimitry Andric 15050b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1506*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 15070b57cec5SDimitry Andricvoid 15080b57cec5SDimitry Andricvector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT 15090b57cec5SDimitry Andric{ 15100b57cec5SDimitry Andric if (capacity() > size()) 15110b57cec5SDimitry Andric { 15120b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 15130b57cec5SDimitry Andric try 15140b57cec5SDimitry Andric { 15150b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 15160b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 15170b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(size(), size(), __a); 15180b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 15190b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 15200b57cec5SDimitry Andric } 15210b57cec5SDimitry Andric catch (...) 15220b57cec5SDimitry Andric { 15230b57cec5SDimitry Andric } 15240b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 15250b57cec5SDimitry Andric } 15260b57cec5SDimitry Andric} 15270b57cec5SDimitry Andric 15280b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 15290b57cec5SDimitry Andrictemplate <class _Up> 1530*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 15310b57cec5SDimitry Andricvoid 15320b57cec5SDimitry Andricvector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x) 15330b57cec5SDimitry Andric{ 15340b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 15350b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); 15360b57cec5SDimitry Andric // __v.push_back(_VSTD::forward<_Up>(__x)); 1537480093f4SDimitry Andric __alloc_traits::construct(__a, _VSTD::__to_address(__v.__end_), _VSTD::forward<_Up>(__x)); 15380b57cec5SDimitry Andric __v.__end_++; 15390b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 15400b57cec5SDimitry Andric} 15410b57cec5SDimitry Andric 15420b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1543*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 15440b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 15450b57cec5SDimitry Andricvoid 15460b57cec5SDimitry Andricvector<_Tp, _Allocator>::push_back(const_reference __x) 15470b57cec5SDimitry Andric{ 15480b57cec5SDimitry Andric if (this->__end_ != this->__end_cap()) 15490b57cec5SDimitry Andric { 1550e40139ffSDimitry Andric __construct_one_at_end(__x); 15510b57cec5SDimitry Andric } 15520b57cec5SDimitry Andric else 15530b57cec5SDimitry Andric __push_back_slow_path(__x); 15540b57cec5SDimitry Andric} 15550b57cec5SDimitry Andric 15560b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1557*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 15580b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 15590b57cec5SDimitry Andricvoid 15600b57cec5SDimitry Andricvector<_Tp, _Allocator>::push_back(value_type&& __x) 15610b57cec5SDimitry Andric{ 15620b57cec5SDimitry Andric if (this->__end_ < this->__end_cap()) 15630b57cec5SDimitry Andric { 1564e40139ffSDimitry Andric __construct_one_at_end(_VSTD::move(__x)); 15650b57cec5SDimitry Andric } 15660b57cec5SDimitry Andric else 15670b57cec5SDimitry Andric __push_back_slow_path(_VSTD::move(__x)); 15680b57cec5SDimitry Andric} 15690b57cec5SDimitry Andric 15700b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 15710b57cec5SDimitry Andrictemplate <class... _Args> 1572*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 15730b57cec5SDimitry Andricvoid 15740b57cec5SDimitry Andricvector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args) 15750b57cec5SDimitry Andric{ 15760b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 15770b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); 15780b57cec5SDimitry Andric// __v.emplace_back(_VSTD::forward<_Args>(__args)...); 1579480093f4SDimitry Andric __alloc_traits::construct(__a, _VSTD::__to_address(__v.__end_), _VSTD::forward<_Args>(__args)...); 15800b57cec5SDimitry Andric __v.__end_++; 15810b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 15820b57cec5SDimitry Andric} 15830b57cec5SDimitry Andric 15840b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 15850b57cec5SDimitry Andrictemplate <class... _Args> 1586*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 15870b57cec5SDimitry Andricinline 15880b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 15890b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference 15900b57cec5SDimitry Andric#else 15910b57cec5SDimitry Andricvoid 15920b57cec5SDimitry Andric#endif 15930b57cec5SDimitry Andricvector<_Tp, _Allocator>::emplace_back(_Args&&... __args) 15940b57cec5SDimitry Andric{ 15950b57cec5SDimitry Andric if (this->__end_ < this->__end_cap()) 15960b57cec5SDimitry Andric { 1597e40139ffSDimitry Andric __construct_one_at_end(_VSTD::forward<_Args>(__args)...); 15980b57cec5SDimitry Andric } 15990b57cec5SDimitry Andric else 16000b57cec5SDimitry Andric __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...); 16010b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 16020b57cec5SDimitry Andric return this->back(); 16030b57cec5SDimitry Andric#endif 16040b57cec5SDimitry Andric} 16050b57cec5SDimitry Andric 16060b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1607*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 16080b57cec5SDimitry Andricinline 16090b57cec5SDimitry Andricvoid 16100b57cec5SDimitry Andricvector<_Tp, _Allocator>::pop_back() 16110b57cec5SDimitry Andric{ 1612fe6060f1SDimitry Andric _LIBCPP_ASSERT(!empty(), "vector::pop_back called on an empty vector"); 16130b57cec5SDimitry Andric this->__destruct_at_end(this->__end_ - 1); 16140b57cec5SDimitry Andric} 16150b57cec5SDimitry Andric 16160b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1617*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 16180b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 16190b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 16200b57cec5SDimitry Andricvector<_Tp, _Allocator>::erase(const_iterator __position) 16210b57cec5SDimitry Andric{ 162204eeddc0SDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, 162304eeddc0SDimitry Andric "vector::erase(iterator) called with an iterator not referring to this vector"); 16240b57cec5SDimitry Andric _LIBCPP_ASSERT(__position != end(), 16250b57cec5SDimitry Andric "vector::erase(iterator) called with a non-dereferenceable iterator"); 16260b57cec5SDimitry Andric difference_type __ps = __position - cbegin(); 16270b57cec5SDimitry Andric pointer __p = this->__begin_ + __ps; 16280b57cec5SDimitry Andric this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p)); 1629*61cfbce3SDimitry Andric if (!__libcpp_is_constant_evaluated()) 16300b57cec5SDimitry Andric this->__invalidate_iterators_past(__p - 1); 163181ad6265SDimitry Andric iterator __r = iterator(this, __p); 16320b57cec5SDimitry Andric return __r; 16330b57cec5SDimitry Andric} 16340b57cec5SDimitry Andric 16350b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1636*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 16370b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 16380b57cec5SDimitry Andricvector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) 16390b57cec5SDimitry Andric{ 164004eeddc0SDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__first)) == this, 164104eeddc0SDimitry Andric "vector::erase(iterator, iterator) called with an iterator not referring to this vector"); 164204eeddc0SDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__last)) == this, 164304eeddc0SDimitry Andric "vector::erase(iterator, iterator) called with an iterator not referring to this vector"); 164404eeddc0SDimitry Andric 16450b57cec5SDimitry Andric _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range"); 16460b57cec5SDimitry Andric pointer __p = this->__begin_ + (__first - begin()); 16470b57cec5SDimitry Andric if (__first != __last) { 16480b57cec5SDimitry Andric this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p)); 1649*61cfbce3SDimitry Andric if (!__libcpp_is_constant_evaluated()) 16500b57cec5SDimitry Andric this->__invalidate_iterators_past(__p - 1); 16510b57cec5SDimitry Andric } 165281ad6265SDimitry Andric iterator __r = iterator(this, __p); 16530b57cec5SDimitry Andric return __r; 16540b57cec5SDimitry Andric} 16550b57cec5SDimitry Andric 16560b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1657*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 16580b57cec5SDimitry Andricvoid 16590b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to) 16600b57cec5SDimitry Andric{ 16610b57cec5SDimitry Andric pointer __old_last = this->__end_; 16620b57cec5SDimitry Andric difference_type __n = __old_last - __to; 1663e40139ffSDimitry Andric { 1664e40139ffSDimitry Andric pointer __i = __from_s + __n; 1665e40139ffSDimitry Andric _ConstructTransaction __tx(*this, __from_e - __i); 16665ffd83dbSDimitry Andric for (pointer __pos = __tx.__pos_; __i < __from_e; 1667349cc55cSDimitry Andric ++__i, (void) ++__pos, __tx.__pos_ = __pos) { 16680b57cec5SDimitry Andric __alloc_traits::construct(this->__alloc(), 16695ffd83dbSDimitry Andric _VSTD::__to_address(__pos), 16700b57cec5SDimitry Andric _VSTD::move(*__i)); 1671e40139ffSDimitry Andric } 1672e40139ffSDimitry Andric } 16730b57cec5SDimitry Andric _VSTD::move_backward(__from_s, __from_s + __n, __old_last); 16740b57cec5SDimitry Andric} 16750b57cec5SDimitry Andric 16760b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1677*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 16780b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 16790b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) 16800b57cec5SDimitry Andric{ 168104eeddc0SDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, 168204eeddc0SDimitry Andric "vector::insert(iterator, x) called with an iterator not referring to this vector"); 16830b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 1684*61cfbce3SDimitry Andric // We can't compare unrelated pointers inside constant expressions 1685*61cfbce3SDimitry Andric if (!__libcpp_is_constant_evaluated() && this->__end_ < this->__end_cap()) 16860b57cec5SDimitry Andric { 16870b57cec5SDimitry Andric if (__p == this->__end_) 16880b57cec5SDimitry Andric { 1689e40139ffSDimitry Andric __construct_one_at_end(__x); 16900b57cec5SDimitry Andric } 16910b57cec5SDimitry Andric else 16920b57cec5SDimitry Andric { 16930b57cec5SDimitry Andric __move_range(__p, this->__end_, __p + 1); 16940b57cec5SDimitry Andric const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); 16950b57cec5SDimitry Andric if (__p <= __xr && __xr < this->__end_) 16960b57cec5SDimitry Andric ++__xr; 16970b57cec5SDimitry Andric *__p = *__xr; 16980b57cec5SDimitry Andric } 16990b57cec5SDimitry Andric } 17000b57cec5SDimitry Andric else 17010b57cec5SDimitry Andric { 17020b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 17030b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 17040b57cec5SDimitry Andric __v.push_back(__x); 17050b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 17060b57cec5SDimitry Andric } 170781ad6265SDimitry Andric return iterator(this, __p); 17080b57cec5SDimitry Andric} 17090b57cec5SDimitry Andric 17100b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1711*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 17120b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 17130b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) 17140b57cec5SDimitry Andric{ 171504eeddc0SDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, 171604eeddc0SDimitry Andric "vector::insert(iterator, x) called with an iterator not referring to this vector"); 17170b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 17180b57cec5SDimitry Andric if (this->__end_ < this->__end_cap()) 17190b57cec5SDimitry Andric { 17200b57cec5SDimitry Andric if (__p == this->__end_) 17210b57cec5SDimitry Andric { 1722e40139ffSDimitry Andric __construct_one_at_end(_VSTD::move(__x)); 17230b57cec5SDimitry Andric } 17240b57cec5SDimitry Andric else 17250b57cec5SDimitry Andric { 17260b57cec5SDimitry Andric __move_range(__p, this->__end_, __p + 1); 17270b57cec5SDimitry Andric *__p = _VSTD::move(__x); 17280b57cec5SDimitry Andric } 17290b57cec5SDimitry Andric } 17300b57cec5SDimitry Andric else 17310b57cec5SDimitry Andric { 17320b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 17330b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 17340b57cec5SDimitry Andric __v.push_back(_VSTD::move(__x)); 17350b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 17360b57cec5SDimitry Andric } 173781ad6265SDimitry Andric return iterator(this, __p); 17380b57cec5SDimitry Andric} 17390b57cec5SDimitry Andric 17400b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 17410b57cec5SDimitry Andrictemplate <class... _Args> 1742*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 17430b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 17440b57cec5SDimitry Andricvector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) 17450b57cec5SDimitry Andric{ 174604eeddc0SDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, 174704eeddc0SDimitry Andric "vector::emplace(iterator, x) called with an iterator not referring to this vector"); 17480b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 17490b57cec5SDimitry Andric if (this->__end_ < this->__end_cap()) 17500b57cec5SDimitry Andric { 17510b57cec5SDimitry Andric if (__p == this->__end_) 17520b57cec5SDimitry Andric { 1753e40139ffSDimitry Andric __construct_one_at_end(_VSTD::forward<_Args>(__args)...); 17540b57cec5SDimitry Andric } 17550b57cec5SDimitry Andric else 17560b57cec5SDimitry Andric { 17570b57cec5SDimitry Andric __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...); 17580b57cec5SDimitry Andric __move_range(__p, this->__end_, __p + 1); 17590b57cec5SDimitry Andric *__p = _VSTD::move(__tmp.get()); 17600b57cec5SDimitry Andric } 17610b57cec5SDimitry Andric } 17620b57cec5SDimitry Andric else 17630b57cec5SDimitry Andric { 17640b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 17650b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 17660b57cec5SDimitry Andric __v.emplace_back(_VSTD::forward<_Args>(__args)...); 17670b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 17680b57cec5SDimitry Andric } 176981ad6265SDimitry Andric return iterator(this, __p); 17700b57cec5SDimitry Andric} 17710b57cec5SDimitry Andric 17720b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1773*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 17740b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 17750b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x) 17760b57cec5SDimitry Andric{ 177704eeddc0SDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, 177804eeddc0SDimitry Andric "vector::insert(iterator, n, x) called with an iterator not referring to this vector"); 17790b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 17800b57cec5SDimitry Andric if (__n > 0) 17810b57cec5SDimitry Andric { 1782*61cfbce3SDimitry Andric // We can't compare unrelated pointers inside constant expressions 1783*61cfbce3SDimitry Andric if (!__libcpp_is_constant_evaluated() && __n <= static_cast<size_type>(this->__end_cap() - this->__end_)) 17840b57cec5SDimitry Andric { 17850b57cec5SDimitry Andric size_type __old_n = __n; 17860b57cec5SDimitry Andric pointer __old_last = this->__end_; 17870b57cec5SDimitry Andric if (__n > static_cast<size_type>(this->__end_ - __p)) 17880b57cec5SDimitry Andric { 17890b57cec5SDimitry Andric size_type __cx = __n - (this->__end_ - __p); 17900b57cec5SDimitry Andric __construct_at_end(__cx, __x); 17910b57cec5SDimitry Andric __n -= __cx; 17920b57cec5SDimitry Andric } 17930b57cec5SDimitry Andric if (__n > 0) 17940b57cec5SDimitry Andric { 17950b57cec5SDimitry Andric __move_range(__p, __old_last, __p + __old_n); 17960b57cec5SDimitry Andric const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); 17970b57cec5SDimitry Andric if (__p <= __xr && __xr < this->__end_) 17980b57cec5SDimitry Andric __xr += __old_n; 17990b57cec5SDimitry Andric _VSTD::fill_n(__p, __n, *__xr); 18000b57cec5SDimitry Andric } 18010b57cec5SDimitry Andric } 18020b57cec5SDimitry Andric else 18030b57cec5SDimitry Andric { 18040b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 18050b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); 18060b57cec5SDimitry Andric __v.__construct_at_end(__n, __x); 18070b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 18080b57cec5SDimitry Andric } 18090b57cec5SDimitry Andric } 181081ad6265SDimitry Andric return iterator(this, __p); 18110b57cec5SDimitry Andric} 18120b57cec5SDimitry Andric 18130b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 18140b57cec5SDimitry Andrictemplate <class _InputIterator> 1815*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value && 18160b57cec5SDimitry Andric is_constructible< 18170b57cec5SDimitry Andric _Tp, 18180b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::reference>::value, 18190b57cec5SDimitry Andric typename vector<_Tp, _Allocator>::iterator 18200b57cec5SDimitry Andric>::type 18210b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) 18220b57cec5SDimitry Andric{ 182304eeddc0SDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, 182404eeddc0SDimitry Andric "vector::insert(iterator, range) called with an iterator not referring to this vector"); 18250b57cec5SDimitry Andric difference_type __off = __position - begin(); 18260b57cec5SDimitry Andric pointer __p = this->__begin_ + __off; 18270b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 18280b57cec5SDimitry Andric pointer __old_last = this->__end_; 18290b57cec5SDimitry Andric for (; this->__end_ != this->__end_cap() && __first != __last; ++__first) 18300b57cec5SDimitry Andric { 1831e40139ffSDimitry Andric __construct_one_at_end(*__first); 18320b57cec5SDimitry Andric } 18330b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__a); 18340b57cec5SDimitry Andric if (__first != __last) 18350b57cec5SDimitry Andric { 18360b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 18370b57cec5SDimitry Andric try 18380b57cec5SDimitry Andric { 18390b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 18400b57cec5SDimitry Andric __v.__construct_at_end(__first, __last); 18410b57cec5SDimitry Andric difference_type __old_size = __old_last - this->__begin_; 18420b57cec5SDimitry Andric difference_type __old_p = __p - this->__begin_; 18430b57cec5SDimitry Andric reserve(__recommend(size() + __v.size())); 18440b57cec5SDimitry Andric __p = this->__begin_ + __old_p; 18450b57cec5SDimitry Andric __old_last = this->__begin_ + __old_size; 18460b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 18470b57cec5SDimitry Andric } 18480b57cec5SDimitry Andric catch (...) 18490b57cec5SDimitry Andric { 185081ad6265SDimitry Andric erase(iterator(this, __old_last), end()); 18510b57cec5SDimitry Andric throw; 18520b57cec5SDimitry Andric } 18530b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 18540b57cec5SDimitry Andric } 18550b57cec5SDimitry Andric __p = _VSTD::rotate(__p, __old_last, this->__end_); 185681ad6265SDimitry Andric insert(iterator(this, __p), _VSTD::make_move_iterator(__v.begin()), 18575ffd83dbSDimitry Andric _VSTD::make_move_iterator(__v.end())); 18580b57cec5SDimitry Andric return begin() + __off; 18590b57cec5SDimitry Andric} 18600b57cec5SDimitry Andric 18610b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 18620b57cec5SDimitry Andrictemplate <class _ForwardIterator> 1863*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 18640b57cec5SDimitry Andrictypename enable_if 18650b57cec5SDimitry Andric< 1866480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value && 18670b57cec5SDimitry Andric is_constructible< 18680b57cec5SDimitry Andric _Tp, 18690b57cec5SDimitry Andric typename iterator_traits<_ForwardIterator>::reference>::value, 18700b57cec5SDimitry Andric typename vector<_Tp, _Allocator>::iterator 18710b57cec5SDimitry Andric>::type 18720b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) 18730b57cec5SDimitry Andric{ 187404eeddc0SDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, 187504eeddc0SDimitry Andric "vector::insert(iterator, range) called with an iterator not referring to this vector"); 18760b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 18770b57cec5SDimitry Andric difference_type __n = _VSTD::distance(__first, __last); 18780b57cec5SDimitry Andric if (__n > 0) 18790b57cec5SDimitry Andric { 18800b57cec5SDimitry Andric if (__n <= this->__end_cap() - this->__end_) 18810b57cec5SDimitry Andric { 18820b57cec5SDimitry Andric size_type __old_n = __n; 18830b57cec5SDimitry Andric pointer __old_last = this->__end_; 18840b57cec5SDimitry Andric _ForwardIterator __m = __last; 18850b57cec5SDimitry Andric difference_type __dx = this->__end_ - __p; 18860b57cec5SDimitry Andric if (__n > __dx) 18870b57cec5SDimitry Andric { 18880b57cec5SDimitry Andric __m = __first; 18890b57cec5SDimitry Andric difference_type __diff = this->__end_ - __p; 18900b57cec5SDimitry Andric _VSTD::advance(__m, __diff); 18910b57cec5SDimitry Andric __construct_at_end(__m, __last, __n - __diff); 18920b57cec5SDimitry Andric __n = __dx; 18930b57cec5SDimitry Andric } 18940b57cec5SDimitry Andric if (__n > 0) 18950b57cec5SDimitry Andric { 18960b57cec5SDimitry Andric __move_range(__p, __old_last, __p + __old_n); 18970b57cec5SDimitry Andric _VSTD::copy(__first, __m, __p); 18980b57cec5SDimitry Andric } 18990b57cec5SDimitry Andric } 19000b57cec5SDimitry Andric else 19010b57cec5SDimitry Andric { 19020b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 19030b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); 19040b57cec5SDimitry Andric __v.__construct_at_end(__first, __last); 19050b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 19060b57cec5SDimitry Andric } 19070b57cec5SDimitry Andric } 190881ad6265SDimitry Andric return iterator(this, __p); 19090b57cec5SDimitry Andric} 19100b57cec5SDimitry Andric 19110b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1912*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 19130b57cec5SDimitry Andricvoid 19140b57cec5SDimitry Andricvector<_Tp, _Allocator>::resize(size_type __sz) 19150b57cec5SDimitry Andric{ 19160b57cec5SDimitry Andric size_type __cs = size(); 19170b57cec5SDimitry Andric if (__cs < __sz) 19180b57cec5SDimitry Andric this->__append(__sz - __cs); 19190b57cec5SDimitry Andric else if (__cs > __sz) 19200b57cec5SDimitry Andric this->__destruct_at_end(this->__begin_ + __sz); 19210b57cec5SDimitry Andric} 19220b57cec5SDimitry Andric 19230b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1924*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 19250b57cec5SDimitry Andricvoid 19260b57cec5SDimitry Andricvector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x) 19270b57cec5SDimitry Andric{ 19280b57cec5SDimitry Andric size_type __cs = size(); 19290b57cec5SDimitry Andric if (__cs < __sz) 19300b57cec5SDimitry Andric this->__append(__sz - __cs, __x); 19310b57cec5SDimitry Andric else if (__cs > __sz) 19320b57cec5SDimitry Andric this->__destruct_at_end(this->__begin_ + __sz); 19330b57cec5SDimitry Andric} 19340b57cec5SDimitry Andric 19350b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1936*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 19370b57cec5SDimitry Andricvoid 19380b57cec5SDimitry Andricvector<_Tp, _Allocator>::swap(vector& __x) 19390b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 19400b57cec5SDimitry Andric _NOEXCEPT 19410b57cec5SDimitry Andric#else 19420b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 19430b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value) 19440b57cec5SDimitry Andric#endif 19450b57cec5SDimitry Andric{ 19460b57cec5SDimitry Andric _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value || 19470b57cec5SDimitry Andric this->__alloc() == __x.__alloc(), 19480b57cec5SDimitry Andric "vector::swap: Either propagate_on_container_swap must be true" 19490b57cec5SDimitry Andric " or the allocators must compare equal"); 19500b57cec5SDimitry Andric _VSTD::swap(this->__begin_, __x.__begin_); 19510b57cec5SDimitry Andric _VSTD::swap(this->__end_, __x.__end_); 19520b57cec5SDimitry Andric _VSTD::swap(this->__end_cap(), __x.__end_cap()); 1953e8d8bef9SDimitry Andric _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(), 19540b57cec5SDimitry Andric integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>()); 195581ad6265SDimitry Andric std::__debug_db_swap(this, std::addressof(__x)); 19560b57cec5SDimitry Andric} 19570b57cec5SDimitry Andric 19580b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1959*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 19600b57cec5SDimitry Andricbool 19610b57cec5SDimitry Andricvector<_Tp, _Allocator>::__invariants() const 19620b57cec5SDimitry Andric{ 19630b57cec5SDimitry Andric if (this->__begin_ == nullptr) 19640b57cec5SDimitry Andric { 19650b57cec5SDimitry Andric if (this->__end_ != nullptr || this->__end_cap() != nullptr) 19660b57cec5SDimitry Andric return false; 19670b57cec5SDimitry Andric } 19680b57cec5SDimitry Andric else 19690b57cec5SDimitry Andric { 19700b57cec5SDimitry Andric if (this->__begin_ > this->__end_) 19710b57cec5SDimitry Andric return false; 19720b57cec5SDimitry Andric if (this->__begin_ == this->__end_cap()) 19730b57cec5SDimitry Andric return false; 19740b57cec5SDimitry Andric if (this->__end_ > this->__end_cap()) 19750b57cec5SDimitry Andric return false; 19760b57cec5SDimitry Andric } 19770b57cec5SDimitry Andric return true; 19780b57cec5SDimitry Andric} 19790b57cec5SDimitry Andric 198081ad6265SDimitry Andric#ifdef _LIBCPP_ENABLE_DEBUG_MODE 19810b57cec5SDimitry Andric 19820b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 19830b57cec5SDimitry Andricbool 19840b57cec5SDimitry Andricvector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const 19850b57cec5SDimitry Andric{ 19860b57cec5SDimitry Andric return this->__begin_ <= __i->base() && __i->base() < this->__end_; 19870b57cec5SDimitry Andric} 19880b57cec5SDimitry Andric 19890b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 19900b57cec5SDimitry Andricbool 19910b57cec5SDimitry Andricvector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const 19920b57cec5SDimitry Andric{ 19930b57cec5SDimitry Andric return this->__begin_ < __i->base() && __i->base() <= this->__end_; 19940b57cec5SDimitry Andric} 19950b57cec5SDimitry Andric 19960b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 19970b57cec5SDimitry Andricbool 19980b57cec5SDimitry Andricvector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const 19990b57cec5SDimitry Andric{ 20000b57cec5SDimitry Andric const_pointer __p = __i->base() + __n; 20010b57cec5SDimitry Andric return this->__begin_ <= __p && __p <= this->__end_; 20020b57cec5SDimitry Andric} 20030b57cec5SDimitry Andric 20040b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 20050b57cec5SDimitry Andricbool 20060b57cec5SDimitry Andricvector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const 20070b57cec5SDimitry Andric{ 20080b57cec5SDimitry Andric const_pointer __p = __i->base() + __n; 20090b57cec5SDimitry Andric return this->__begin_ <= __p && __p < this->__end_; 20100b57cec5SDimitry Andric} 20110b57cec5SDimitry Andric 201281ad6265SDimitry Andric#endif // _LIBCPP_ENABLE_DEBUG_MODE 20130b57cec5SDimitry Andric 20140b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 20150b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 20160b57cec5SDimitry Andricvoid 20170b57cec5SDimitry Andricvector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) { 201881ad6265SDimitry Andric#ifdef _LIBCPP_ENABLE_DEBUG_MODE 20190b57cec5SDimitry Andric __c_node* __c = __get_db()->__find_c_and_lock(this); 20200b57cec5SDimitry Andric for (__i_node** __p = __c->end_; __p != __c->beg_; ) { 20210b57cec5SDimitry Andric --__p; 20220b57cec5SDimitry Andric const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); 20230b57cec5SDimitry Andric if (__i->base() > __new_last) { 20240b57cec5SDimitry Andric (*__p)->__c_ = nullptr; 20250b57cec5SDimitry Andric if (--__c->end_ != __p) 2026e8d8bef9SDimitry Andric _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); 20270b57cec5SDimitry Andric } 20280b57cec5SDimitry Andric } 20290b57cec5SDimitry Andric __get_db()->unlock(); 20300b57cec5SDimitry Andric#else 20310b57cec5SDimitry Andric ((void)__new_last); 20320b57cec5SDimitry Andric#endif 20330b57cec5SDimitry Andric} 20340b57cec5SDimitry Andric 20350b57cec5SDimitry Andric// vector<bool> 20360b57cec5SDimitry Andric 20370b57cec5SDimitry Andrictemplate <class _Allocator> class vector<bool, _Allocator>; 20380b57cec5SDimitry Andric 20390b57cec5SDimitry Andrictemplate <class _Allocator> struct hash<vector<bool, _Allocator> >; 20400b57cec5SDimitry Andric 20410b57cec5SDimitry Andrictemplate <class _Allocator> 20420b57cec5SDimitry Andricstruct __has_storage_type<vector<bool, _Allocator> > 20430b57cec5SDimitry Andric{ 20440b57cec5SDimitry Andric static const bool value = true; 20450b57cec5SDimitry Andric}; 20460b57cec5SDimitry Andric 20470b57cec5SDimitry Andrictemplate <class _Allocator> 20480b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> 20490b57cec5SDimitry Andric{ 20500b57cec5SDimitry Andricpublic: 20510b57cec5SDimitry Andric typedef vector __self; 20520b57cec5SDimitry Andric typedef bool value_type; 20530b57cec5SDimitry Andric typedef _Allocator allocator_type; 20540b57cec5SDimitry Andric typedef allocator_traits<allocator_type> __alloc_traits; 20550b57cec5SDimitry Andric typedef typename __alloc_traits::size_type size_type; 20560b57cec5SDimitry Andric typedef typename __alloc_traits::difference_type difference_type; 20570b57cec5SDimitry Andric typedef size_type __storage_type; 20580b57cec5SDimitry Andric typedef __bit_iterator<vector, false> pointer; 20590b57cec5SDimitry Andric typedef __bit_iterator<vector, true> const_pointer; 20600b57cec5SDimitry Andric typedef pointer iterator; 20610b57cec5SDimitry Andric typedef const_pointer const_iterator; 20620b57cec5SDimitry Andric typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 20630b57cec5SDimitry Andric typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 20640b57cec5SDimitry Andric 20650b57cec5SDimitry Andricprivate: 20660b57cec5SDimitry Andric typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator; 20670b57cec5SDimitry Andric typedef allocator_traits<__storage_allocator> __storage_traits; 20680b57cec5SDimitry Andric typedef typename __storage_traits::pointer __storage_pointer; 20690b57cec5SDimitry Andric typedef typename __storage_traits::const_pointer __const_storage_pointer; 20700b57cec5SDimitry Andric 20710b57cec5SDimitry Andric __storage_pointer __begin_; 20720b57cec5SDimitry Andric size_type __size_; 20730b57cec5SDimitry Andric __compressed_pair<size_type, __storage_allocator> __cap_alloc_; 20740b57cec5SDimitry Andricpublic: 20750b57cec5SDimitry Andric typedef __bit_reference<vector> reference; 207681ad6265SDimitry Andric#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL 207781ad6265SDimitry Andric using const_reference = bool; 207881ad6265SDimitry Andric#else 20790b57cec5SDimitry Andric typedef __bit_const_reference<vector> const_reference; 208081ad6265SDimitry Andric#endif 20810b57cec5SDimitry Andricprivate: 2082*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 20830b57cec5SDimitry Andric size_type& __cap() _NOEXCEPT 20840b57cec5SDimitry Andric {return __cap_alloc_.first();} 2085*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 20860b57cec5SDimitry Andric const size_type& __cap() const _NOEXCEPT 20870b57cec5SDimitry Andric {return __cap_alloc_.first();} 2088*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 20890b57cec5SDimitry Andric __storage_allocator& __alloc() _NOEXCEPT 20900b57cec5SDimitry Andric {return __cap_alloc_.second();} 2091*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 20920b57cec5SDimitry Andric const __storage_allocator& __alloc() const _NOEXCEPT 20930b57cec5SDimitry Andric {return __cap_alloc_.second();} 20940b57cec5SDimitry Andric 20950b57cec5SDimitry Andric static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 20960b57cec5SDimitry Andric 2097*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 20980b57cec5SDimitry Andric static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT 20990b57cec5SDimitry Andric {return __n * __bits_per_word;} 2100*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 21010b57cec5SDimitry Andric static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT 21020b57cec5SDimitry Andric {return (__n - 1) / __bits_per_word + 1;} 21030b57cec5SDimitry Andric 21040b57cec5SDimitry Andricpublic: 2105*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 21060b57cec5SDimitry Andric vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); 21070b57cec5SDimitry Andric 2108*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit vector(const allocator_type& __a) 21090b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 21100b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value); 21110b57cec5SDimitry Andric#else 21120b57cec5SDimitry Andric _NOEXCEPT; 21130b57cec5SDimitry Andric#endif 2114*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 ~vector(); 2115*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit vector(size_type __n); 21160b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 2117*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit vector(size_type __n, const allocator_type& __a); 21180b57cec5SDimitry Andric#endif 2119*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(size_type __n, const value_type& __v); 2120*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(size_type __n, const value_type& __v, const allocator_type& __a); 21210b57cec5SDimitry Andric template <class _InputIterator> 2122*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(_InputIterator __first, _InputIterator __last, 2123753f127fSDimitry Andric typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type* = 0); 21240b57cec5SDimitry Andric template <class _InputIterator> 2125*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 2126753f127fSDimitry Andric typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type* = 0); 21270b57cec5SDimitry Andric template <class _ForwardIterator> 2128*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(_ForwardIterator __first, _ForwardIterator __last, 2129480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0); 21300b57cec5SDimitry Andric template <class _ForwardIterator> 2131*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 2132480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0); 21330b57cec5SDimitry Andric 2134*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(const vector& __v); 2135*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(const vector& __v, const allocator_type& __a); 2136*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 vector& operator=(const vector& __v); 21370b57cec5SDimitry Andric 21380b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 2139*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(initializer_list<value_type> __il); 2140*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(initializer_list<value_type> __il, const allocator_type& __a); 21410b57cec5SDimitry Andric 2142*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 21430b57cec5SDimitry Andric vector& operator=(initializer_list<value_type> __il) 21440b57cec5SDimitry Andric {assign(__il.begin(), __il.end()); return *this;} 21450b57cec5SDimitry Andric 21460b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG 21470b57cec5SDimitry Andric 2148*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 214981ad6265SDimitry Andric vector(vector&& __v) 215081ad6265SDimitry Andric#if _LIBCPP_STD_VER > 14 215181ad6265SDimitry Andric noexcept; 215281ad6265SDimitry Andric#else 215381ad6265SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); 215481ad6265SDimitry Andric#endif 2155*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(vector&& __v, const __type_identity_t<allocator_type>& __a); 2156*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 215781ad6265SDimitry Andric vector& operator=(vector&& __v) 215881ad6265SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); 215981ad6265SDimitry Andric 21600b57cec5SDimitry Andric template <class _InputIterator> 2161753f127fSDimitry Andric typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value, 21620b57cec5SDimitry Andric void 21630b57cec5SDimitry Andric >::type 2164*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 assign(_InputIterator __first, _InputIterator __last); 21650b57cec5SDimitry Andric template <class _ForwardIterator> 21660b57cec5SDimitry Andric typename enable_if 21670b57cec5SDimitry Andric < 2168480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 21690b57cec5SDimitry Andric void 21700b57cec5SDimitry Andric >::type 2171*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 assign(_ForwardIterator __first, _ForwardIterator __last); 21720b57cec5SDimitry Andric 2173*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void assign(size_type __n, const value_type& __x); 21740b57cec5SDimitry Andric 21750b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 2176*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 21770b57cec5SDimitry Andric void assign(initializer_list<value_type> __il) 21780b57cec5SDimitry Andric {assign(__il.begin(), __il.end());} 21790b57cec5SDimitry Andric#endif 21800b57cec5SDimitry Andric 2181*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 allocator_type get_allocator() const _NOEXCEPT 21820b57cec5SDimitry Andric {return allocator_type(this->__alloc());} 21830b57cec5SDimitry Andric 2184*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type max_size() const _NOEXCEPT; 2185*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 21860b57cec5SDimitry Andric size_type capacity() const _NOEXCEPT 21870b57cec5SDimitry Andric {return __internal_cap_to_external(__cap());} 2188*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 21890b57cec5SDimitry Andric size_type size() const _NOEXCEPT 21900b57cec5SDimitry Andric {return __size_;} 2191*61cfbce3SDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 21920b57cec5SDimitry Andric bool empty() const _NOEXCEPT 21930b57cec5SDimitry Andric {return __size_ == 0;} 2194*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void reserve(size_type __n); 2195*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void shrink_to_fit() _NOEXCEPT; 21960b57cec5SDimitry Andric 2197*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 21980b57cec5SDimitry Andric iterator begin() _NOEXCEPT 21990b57cec5SDimitry Andric {return __make_iter(0);} 2200*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 22010b57cec5SDimitry Andric const_iterator begin() const _NOEXCEPT 22020b57cec5SDimitry Andric {return __make_iter(0);} 2203*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 22040b57cec5SDimitry Andric iterator end() _NOEXCEPT 22050b57cec5SDimitry Andric {return __make_iter(__size_);} 2206*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 22070b57cec5SDimitry Andric const_iterator end() const _NOEXCEPT 22080b57cec5SDimitry Andric {return __make_iter(__size_);} 22090b57cec5SDimitry Andric 2210*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 22110b57cec5SDimitry Andric reverse_iterator rbegin() _NOEXCEPT 22120b57cec5SDimitry Andric {return reverse_iterator(end());} 2213*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 22140b57cec5SDimitry Andric const_reverse_iterator rbegin() const _NOEXCEPT 22150b57cec5SDimitry Andric {return const_reverse_iterator(end());} 2216*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 22170b57cec5SDimitry Andric reverse_iterator rend() _NOEXCEPT 22180b57cec5SDimitry Andric {return reverse_iterator(begin());} 2219*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 22200b57cec5SDimitry Andric const_reverse_iterator rend() const _NOEXCEPT 22210b57cec5SDimitry Andric {return const_reverse_iterator(begin());} 22220b57cec5SDimitry Andric 2223*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 22240b57cec5SDimitry Andric const_iterator cbegin() const _NOEXCEPT 22250b57cec5SDimitry Andric {return __make_iter(0);} 2226*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 22270b57cec5SDimitry Andric const_iterator cend() const _NOEXCEPT 22280b57cec5SDimitry Andric {return __make_iter(__size_);} 2229*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 22300b57cec5SDimitry Andric const_reverse_iterator crbegin() const _NOEXCEPT 22310b57cec5SDimitry Andric {return rbegin();} 2232*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 22330b57cec5SDimitry Andric const_reverse_iterator crend() const _NOEXCEPT 22340b57cec5SDimitry Andric {return rend();} 22350b57cec5SDimitry Andric 2236*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 reference operator[](size_type __n) {return __make_ref(__n);} 2237*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference operator[](size_type __n) const {return __make_ref(__n);} 22380b57cec5SDimitry Andric reference at(size_type __n); 22390b57cec5SDimitry Andric const_reference at(size_type __n) const; 22400b57cec5SDimitry Andric 2241*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 reference front() {return __make_ref(0);} 2242*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference front() const {return __make_ref(0);} 2243*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 reference back() {return __make_ref(__size_ - 1);} 2244*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference back() const {return __make_ref(__size_ - 1);} 22450b57cec5SDimitry Andric 2246*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void push_back(const value_type& __x); 22470b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 22480b57cec5SDimitry Andric template <class... _Args> 22490b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 2250*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 reference emplace_back(_Args&&... __args) 22510b57cec5SDimitry Andric#else 22520b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args) 22530b57cec5SDimitry Andric#endif 22540b57cec5SDimitry Andric { 22550b57cec5SDimitry Andric push_back ( value_type ( _VSTD::forward<_Args>(__args)... )); 22560b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 22570b57cec5SDimitry Andric return this->back(); 22580b57cec5SDimitry Andric#endif 22590b57cec5SDimitry Andric } 22600b57cec5SDimitry Andric#endif 22610b57cec5SDimitry Andric 2262*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void pop_back() {--__size_;} 22630b57cec5SDimitry Andric 22640b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 22650b57cec5SDimitry Andric template <class... _Args> 2266*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator emplace(const_iterator __position, _Args&&... __args) 2267753f127fSDimitry Andric { return insert ( __position, value_type ( _VSTD::forward<_Args>(__args)... )); } 22680b57cec5SDimitry Andric#endif 22690b57cec5SDimitry Andric 2270*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator insert(const_iterator __position, const value_type& __x); 2271*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator insert(const_iterator __position, size_type __n, const value_type& __x); 22720b57cec5SDimitry Andric template <class _InputIterator> 2273753f127fSDimitry Andric typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value, 22740b57cec5SDimitry Andric iterator 22750b57cec5SDimitry Andric >::type 2276*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 insert(const_iterator __position, _InputIterator __first, _InputIterator __last); 22770b57cec5SDimitry Andric template <class _ForwardIterator> 22780b57cec5SDimitry Andric typename enable_if 22790b57cec5SDimitry Andric < 2280480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 22810b57cec5SDimitry Andric iterator 22820b57cec5SDimitry Andric >::type 2283*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); 22840b57cec5SDimitry Andric 22850b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 2286*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 22870b57cec5SDimitry Andric iterator insert(const_iterator __position, initializer_list<value_type> __il) 22880b57cec5SDimitry Andric {return insert(__position, __il.begin(), __il.end());} 22890b57cec5SDimitry Andric#endif 22900b57cec5SDimitry Andric 2291*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator erase(const_iterator __position); 2292*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator erase(const_iterator __first, const_iterator __last); 22930b57cec5SDimitry Andric 2294*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 22950b57cec5SDimitry Andric void clear() _NOEXCEPT {__size_ = 0;} 22960b57cec5SDimitry Andric 2297*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void swap(vector&) 22980b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 22990b57cec5SDimitry Andric _NOEXCEPT; 23000b57cec5SDimitry Andric#else 23010b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 23020b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value); 23030b57cec5SDimitry Andric#endif 2304*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); } 23050b57cec5SDimitry Andric 2306*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void resize(size_type __sz, value_type __x = false); 2307*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void flip() _NOEXCEPT; 23080b57cec5SDimitry Andric 2309*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 bool __invariants() const; 23100b57cec5SDimitry Andric 23110b57cec5SDimitry Andricprivate: 2312d56accc7SDimitry Andric _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI 2313d56accc7SDimitry Andric void __throw_length_error() const { 2314d56accc7SDimitry Andric _VSTD::__throw_length_error("vector"); 2315d56accc7SDimitry Andric } 2316d56accc7SDimitry Andric 2317d56accc7SDimitry Andric _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI 2318d56accc7SDimitry Andric void __throw_out_of_range() const { 2319d56accc7SDimitry Andric _VSTD::__throw_out_of_range("vector"); 2320d56accc7SDimitry Andric } 2321d56accc7SDimitry Andric 232281ad6265SDimitry Andric // Allocate space for __n objects 232381ad6265SDimitry Andric // throws length_error if __n > max_size() 232481ad6265SDimitry Andric // throws (probably bad_alloc) if memory run out 232581ad6265SDimitry Andric // Precondition: __begin_ == __end_ == __cap() == 0 232681ad6265SDimitry Andric // Precondition: __n > 0 232781ad6265SDimitry Andric // Postcondition: capacity() >= __n 232881ad6265SDimitry Andric // Postcondition: size() == 0 2329*61cfbce3SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __vallocate(size_type __n) { 233081ad6265SDimitry Andric if (__n > max_size()) 233181ad6265SDimitry Andric __throw_length_error(); 233281ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __external_cap_to_internal(__n)); 233381ad6265SDimitry Andric __begin_ = __allocation.ptr; 233481ad6265SDimitry Andric __size_ = 0; 233581ad6265SDimitry Andric __cap() = __allocation.count; 2336*61cfbce3SDimitry Andric if (__libcpp_is_constant_evaluated()) { 2337*61cfbce3SDimitry Andric for (size_type __i = 0; __i != __cap(); ++__i) 2338*61cfbce3SDimitry Andric std::__construct_at(std::__to_address(__begin_) + __i); 2339*61cfbce3SDimitry Andric } 234081ad6265SDimitry Andric } 234181ad6265SDimitry Andric 2342*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void __vdeallocate() _NOEXCEPT; 2343*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 23440b57cec5SDimitry Andric static size_type __align_it(size_type __new_size) _NOEXCEPT 234581ad6265SDimitry Andric {return (__new_size + (__bits_per_word-1)) & ~((size_type)__bits_per_word-1);} 2346*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type __recommend(size_type __new_size) const; 2347*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void __construct_at_end(size_type __n, bool __x); 23480b57cec5SDimitry Andric template <class _ForwardIterator> 23490b57cec5SDimitry Andric typename enable_if 23500b57cec5SDimitry Andric < 2351480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 23520b57cec5SDimitry Andric void 23530b57cec5SDimitry Andric >::type 2354*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last); 2355*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void __append(size_type __n, const_reference __x); 2356*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 23570b57cec5SDimitry Andric reference __make_ref(size_type __pos) _NOEXCEPT 23580b57cec5SDimitry Andric {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 2359*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 236081ad6265SDimitry Andric const_reference __make_ref(size_type __pos) const _NOEXCEPT { 236181ad6265SDimitry Andric return __bit_const_reference<vector>(__begin_ + __pos / __bits_per_word, 236281ad6265SDimitry Andric __storage_type(1) << __pos % __bits_per_word); 236381ad6265SDimitry Andric } 2364*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 23650b57cec5SDimitry Andric iterator __make_iter(size_type __pos) _NOEXCEPT 23660b57cec5SDimitry Andric {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));} 2367*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 23680b57cec5SDimitry Andric const_iterator __make_iter(size_type __pos) const _NOEXCEPT 23690b57cec5SDimitry Andric {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));} 2370*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 23710b57cec5SDimitry Andric iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT 23720b57cec5SDimitry Andric {return begin() + (__p - cbegin());} 23730b57cec5SDimitry Andric 2374*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 23750b57cec5SDimitry Andric void __copy_assign_alloc(const vector& __v) 23760b57cec5SDimitry Andric {__copy_assign_alloc(__v, integral_constant<bool, 23770b57cec5SDimitry Andric __storage_traits::propagate_on_container_copy_assignment::value>());} 2378*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 23790b57cec5SDimitry Andric void __copy_assign_alloc(const vector& __c, true_type) 23800b57cec5SDimitry Andric { 23810b57cec5SDimitry Andric if (__alloc() != __c.__alloc()) 23820b57cec5SDimitry Andric __vdeallocate(); 23830b57cec5SDimitry Andric __alloc() = __c.__alloc(); 23840b57cec5SDimitry Andric } 23850b57cec5SDimitry Andric 2386*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 23870b57cec5SDimitry Andric void __copy_assign_alloc(const vector&, false_type) 23880b57cec5SDimitry Andric {} 23890b57cec5SDimitry Andric 2390*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void __move_assign(vector& __c, false_type); 2391*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void __move_assign(vector& __c, true_type) 23920b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); 2393*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 23940b57cec5SDimitry Andric void __move_assign_alloc(vector& __c) 23950b57cec5SDimitry Andric _NOEXCEPT_( 23960b57cec5SDimitry Andric !__storage_traits::propagate_on_container_move_assignment::value || 23970b57cec5SDimitry Andric is_nothrow_move_assignable<allocator_type>::value) 23980b57cec5SDimitry Andric {__move_assign_alloc(__c, integral_constant<bool, 23990b57cec5SDimitry Andric __storage_traits::propagate_on_container_move_assignment::value>());} 2400*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 24010b57cec5SDimitry Andric void __move_assign_alloc(vector& __c, true_type) 24020b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 24030b57cec5SDimitry Andric { 24040b57cec5SDimitry Andric __alloc() = _VSTD::move(__c.__alloc()); 24050b57cec5SDimitry Andric } 24060b57cec5SDimitry Andric 2407*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 24080b57cec5SDimitry Andric void __move_assign_alloc(vector&, false_type) 24090b57cec5SDimitry Andric _NOEXCEPT 24100b57cec5SDimitry Andric {} 24110b57cec5SDimitry Andric 2412*61cfbce3SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 size_t __hash_code() const _NOEXCEPT; 24130b57cec5SDimitry Andric 24140b57cec5SDimitry Andric friend class __bit_reference<vector>; 24150b57cec5SDimitry Andric friend class __bit_const_reference<vector>; 24160b57cec5SDimitry Andric friend class __bit_iterator<vector, false>; 24170b57cec5SDimitry Andric friend class __bit_iterator<vector, true>; 24180b57cec5SDimitry Andric friend struct __bit_array<vector>; 24190b57cec5SDimitry Andric friend struct _LIBCPP_TEMPLATE_VIS hash<vector>; 24200b57cec5SDimitry Andric}; 24210b57cec5SDimitry Andric 24220b57cec5SDimitry Andrictemplate <class _Allocator> 2423*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 void 24240b57cec5SDimitry Andricvector<bool, _Allocator>::__vdeallocate() _NOEXCEPT 24250b57cec5SDimitry Andric{ 24260b57cec5SDimitry Andric if (this->__begin_ != nullptr) 24270b57cec5SDimitry Andric { 24280b57cec5SDimitry Andric __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap()); 242981ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 24300b57cec5SDimitry Andric this->__begin_ = nullptr; 24310b57cec5SDimitry Andric this->__size_ = this->__cap() = 0; 24320b57cec5SDimitry Andric } 24330b57cec5SDimitry Andric} 24340b57cec5SDimitry Andric 24350b57cec5SDimitry Andrictemplate <class _Allocator> 2436*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 24370b57cec5SDimitry Andrictypename vector<bool, _Allocator>::size_type 24380b57cec5SDimitry Andricvector<bool, _Allocator>::max_size() const _NOEXCEPT 24390b57cec5SDimitry Andric{ 24400b57cec5SDimitry Andric size_type __amax = __storage_traits::max_size(__alloc()); 24410b57cec5SDimitry Andric size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always 24420b57cec5SDimitry Andric if (__nmax / __bits_per_word <= __amax) 24430b57cec5SDimitry Andric return __nmax; 24440b57cec5SDimitry Andric return __internal_cap_to_external(__amax); 24450b57cec5SDimitry Andric} 24460b57cec5SDimitry Andric 24470b57cec5SDimitry Andric// Precondition: __new_size > capacity() 24480b57cec5SDimitry Andrictemplate <class _Allocator> 2449*61cfbce3SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 24500b57cec5SDimitry Andrictypename vector<bool, _Allocator>::size_type 24510b57cec5SDimitry Andricvector<bool, _Allocator>::__recommend(size_type __new_size) const 24520b57cec5SDimitry Andric{ 24530b57cec5SDimitry Andric const size_type __ms = max_size(); 24540b57cec5SDimitry Andric if (__new_size > __ms) 24550b57cec5SDimitry Andric this->__throw_length_error(); 24560b57cec5SDimitry Andric const size_type __cap = capacity(); 24570b57cec5SDimitry Andric if (__cap >= __ms / 2) 24580b57cec5SDimitry Andric return __ms; 24590b57cec5SDimitry Andric return _VSTD::max(2 * __cap, __align_it(__new_size)); 24600b57cec5SDimitry Andric} 24610b57cec5SDimitry Andric 24620b57cec5SDimitry Andric// Default constructs __n objects starting at __end_ 24630b57cec5SDimitry Andric// Precondition: __n > 0 24640b57cec5SDimitry Andric// Precondition: size() + __n <= capacity() 24650b57cec5SDimitry Andric// Postcondition: size() == size() + __n 24660b57cec5SDimitry Andrictemplate <class _Allocator> 2467*61cfbce3SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 24680b57cec5SDimitry Andricvoid 24690b57cec5SDimitry Andricvector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x) 24700b57cec5SDimitry Andric{ 24710b57cec5SDimitry Andric size_type __old_size = this->__size_; 24720b57cec5SDimitry Andric this->__size_ += __n; 24730b57cec5SDimitry Andric if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) 24740b57cec5SDimitry Andric { 24750b57cec5SDimitry Andric if (this->__size_ <= __bits_per_word) 24760b57cec5SDimitry Andric this->__begin_[0] = __storage_type(0); 24770b57cec5SDimitry Andric else 24780b57cec5SDimitry Andric this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0); 24790b57cec5SDimitry Andric } 24800b57cec5SDimitry Andric _VSTD::fill_n(__make_iter(__old_size), __n, __x); 24810b57cec5SDimitry Andric} 24820b57cec5SDimitry Andric 24830b57cec5SDimitry Andrictemplate <class _Allocator> 24840b57cec5SDimitry Andrictemplate <class _ForwardIterator> 2485*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 24860b57cec5SDimitry Andrictypename enable_if 24870b57cec5SDimitry Andric< 2488480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 24890b57cec5SDimitry Andric void 24900b57cec5SDimitry Andric>::type 24910b57cec5SDimitry Andricvector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last) 24920b57cec5SDimitry Andric{ 24930b57cec5SDimitry Andric size_type __old_size = this->__size_; 24940b57cec5SDimitry Andric this->__size_ += _VSTD::distance(__first, __last); 24950b57cec5SDimitry Andric if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) 24960b57cec5SDimitry Andric { 24970b57cec5SDimitry Andric if (this->__size_ <= __bits_per_word) 24980b57cec5SDimitry Andric this->__begin_[0] = __storage_type(0); 24990b57cec5SDimitry Andric else 25000b57cec5SDimitry Andric this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0); 25010b57cec5SDimitry Andric } 25020b57cec5SDimitry Andric _VSTD::copy(__first, __last, __make_iter(__old_size)); 25030b57cec5SDimitry Andric} 25040b57cec5SDimitry Andric 25050b57cec5SDimitry Andrictemplate <class _Allocator> 2506*61cfbce3SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 25070b57cec5SDimitry Andricvector<bool, _Allocator>::vector() 25080b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 25090b57cec5SDimitry Andric : __begin_(nullptr), 25100b57cec5SDimitry Andric __size_(0), 2511480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 25120b57cec5SDimitry Andric{ 25130b57cec5SDimitry Andric} 25140b57cec5SDimitry Andric 25150b57cec5SDimitry Andrictemplate <class _Allocator> 2516*61cfbce3SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 25170b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const allocator_type& __a) 25180b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 25190b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) 25200b57cec5SDimitry Andric#else 25210b57cec5SDimitry Andric _NOEXCEPT 25220b57cec5SDimitry Andric#endif 25230b57cec5SDimitry Andric : __begin_(nullptr), 25240b57cec5SDimitry Andric __size_(0), 25250b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 25260b57cec5SDimitry Andric{ 25270b57cec5SDimitry Andric} 25280b57cec5SDimitry Andric 25290b57cec5SDimitry Andrictemplate <class _Allocator> 2530*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 25310b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n) 25320b57cec5SDimitry Andric : __begin_(nullptr), 25330b57cec5SDimitry Andric __size_(0), 2534480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 25350b57cec5SDimitry Andric{ 25360b57cec5SDimitry Andric if (__n > 0) 25370b57cec5SDimitry Andric { 25380b57cec5SDimitry Andric __vallocate(__n); 25390b57cec5SDimitry Andric __construct_at_end(__n, false); 25400b57cec5SDimitry Andric } 25410b57cec5SDimitry Andric} 25420b57cec5SDimitry Andric 25430b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 25440b57cec5SDimitry Andrictemplate <class _Allocator> 2545*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 25460b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a) 25470b57cec5SDimitry Andric : __begin_(nullptr), 25480b57cec5SDimitry Andric __size_(0), 25490b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 25500b57cec5SDimitry Andric{ 25510b57cec5SDimitry Andric if (__n > 0) 25520b57cec5SDimitry Andric { 25530b57cec5SDimitry Andric __vallocate(__n); 25540b57cec5SDimitry Andric __construct_at_end(__n, false); 25550b57cec5SDimitry Andric } 25560b57cec5SDimitry Andric} 25570b57cec5SDimitry Andric#endif 25580b57cec5SDimitry Andric 25590b57cec5SDimitry Andrictemplate <class _Allocator> 2560*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 25610b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const value_type& __x) 25620b57cec5SDimitry Andric : __begin_(nullptr), 25630b57cec5SDimitry Andric __size_(0), 2564480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 25650b57cec5SDimitry Andric{ 25660b57cec5SDimitry Andric if (__n > 0) 25670b57cec5SDimitry Andric { 25680b57cec5SDimitry Andric __vallocate(__n); 25690b57cec5SDimitry Andric __construct_at_end(__n, __x); 25700b57cec5SDimitry Andric } 25710b57cec5SDimitry Andric} 25720b57cec5SDimitry Andric 25730b57cec5SDimitry Andrictemplate <class _Allocator> 2574*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 25750b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a) 25760b57cec5SDimitry Andric : __begin_(nullptr), 25770b57cec5SDimitry Andric __size_(0), 25780b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 25790b57cec5SDimitry Andric{ 25800b57cec5SDimitry Andric if (__n > 0) 25810b57cec5SDimitry Andric { 25820b57cec5SDimitry Andric __vallocate(__n); 25830b57cec5SDimitry Andric __construct_at_end(__n, __x); 25840b57cec5SDimitry Andric } 25850b57cec5SDimitry Andric} 25860b57cec5SDimitry Andric 25870b57cec5SDimitry Andrictemplate <class _Allocator> 25880b57cec5SDimitry Andrictemplate <class _InputIterator> 2589*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 25900b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, 2591753f127fSDimitry Andric typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type*) 25920b57cec5SDimitry Andric : __begin_(nullptr), 25930b57cec5SDimitry Andric __size_(0), 2594480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 25950b57cec5SDimitry Andric{ 25960b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 25970b57cec5SDimitry Andric try 25980b57cec5SDimitry Andric { 25990b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 26000b57cec5SDimitry Andric for (; __first != __last; ++__first) 26010b57cec5SDimitry Andric push_back(*__first); 26020b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 26030b57cec5SDimitry Andric } 26040b57cec5SDimitry Andric catch (...) 26050b57cec5SDimitry Andric { 26060b57cec5SDimitry Andric if (__begin_ != nullptr) 26070b57cec5SDimitry Andric __storage_traits::deallocate(__alloc(), __begin_, __cap()); 260881ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 26090b57cec5SDimitry Andric throw; 26100b57cec5SDimitry Andric } 26110b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 26120b57cec5SDimitry Andric} 26130b57cec5SDimitry Andric 26140b57cec5SDimitry Andrictemplate <class _Allocator> 26150b57cec5SDimitry Andrictemplate <class _InputIterator> 2616*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 26170b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, 2618753f127fSDimitry Andric typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type*) 26190b57cec5SDimitry Andric : __begin_(nullptr), 26200b57cec5SDimitry Andric __size_(0), 26210b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 26220b57cec5SDimitry Andric{ 26230b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 26240b57cec5SDimitry Andric try 26250b57cec5SDimitry Andric { 26260b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 26270b57cec5SDimitry Andric for (; __first != __last; ++__first) 26280b57cec5SDimitry Andric push_back(*__first); 26290b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 26300b57cec5SDimitry Andric } 26310b57cec5SDimitry Andric catch (...) 26320b57cec5SDimitry Andric { 26330b57cec5SDimitry Andric if (__begin_ != nullptr) 26340b57cec5SDimitry Andric __storage_traits::deallocate(__alloc(), __begin_, __cap()); 263581ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 26360b57cec5SDimitry Andric throw; 26370b57cec5SDimitry Andric } 26380b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 26390b57cec5SDimitry Andric} 26400b57cec5SDimitry Andric 26410b57cec5SDimitry Andrictemplate <class _Allocator> 26420b57cec5SDimitry Andrictemplate <class _ForwardIterator> 2643*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 26440b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, 2645480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*) 26460b57cec5SDimitry Andric : __begin_(nullptr), 26470b57cec5SDimitry Andric __size_(0), 2648480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 26490b57cec5SDimitry Andric{ 26500b57cec5SDimitry Andric size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 26510b57cec5SDimitry Andric if (__n > 0) 26520b57cec5SDimitry Andric { 26530b57cec5SDimitry Andric __vallocate(__n); 26540b57cec5SDimitry Andric __construct_at_end(__first, __last); 26550b57cec5SDimitry Andric } 26560b57cec5SDimitry Andric} 26570b57cec5SDimitry Andric 26580b57cec5SDimitry Andrictemplate <class _Allocator> 26590b57cec5SDimitry Andrictemplate <class _ForwardIterator> 2660*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 26610b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, 2662480093f4SDimitry Andric typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*) 26630b57cec5SDimitry Andric : __begin_(nullptr), 26640b57cec5SDimitry Andric __size_(0), 26650b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 26660b57cec5SDimitry Andric{ 26670b57cec5SDimitry Andric size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 26680b57cec5SDimitry Andric if (__n > 0) 26690b57cec5SDimitry Andric { 26700b57cec5SDimitry Andric __vallocate(__n); 26710b57cec5SDimitry Andric __construct_at_end(__first, __last); 26720b57cec5SDimitry Andric } 26730b57cec5SDimitry Andric} 26740b57cec5SDimitry Andric 26750b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 26760b57cec5SDimitry Andric 26770b57cec5SDimitry Andrictemplate <class _Allocator> 2678*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 26790b57cec5SDimitry Andricvector<bool, _Allocator>::vector(initializer_list<value_type> __il) 26800b57cec5SDimitry Andric : __begin_(nullptr), 26810b57cec5SDimitry Andric __size_(0), 2682480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 26830b57cec5SDimitry Andric{ 26840b57cec5SDimitry Andric size_type __n = static_cast<size_type>(__il.size()); 26850b57cec5SDimitry Andric if (__n > 0) 26860b57cec5SDimitry Andric { 26870b57cec5SDimitry Andric __vallocate(__n); 26880b57cec5SDimitry Andric __construct_at_end(__il.begin(), __il.end()); 26890b57cec5SDimitry Andric } 26900b57cec5SDimitry Andric} 26910b57cec5SDimitry Andric 26920b57cec5SDimitry Andrictemplate <class _Allocator> 2693*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 26940b57cec5SDimitry Andricvector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) 26950b57cec5SDimitry Andric : __begin_(nullptr), 26960b57cec5SDimitry Andric __size_(0), 26970b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 26980b57cec5SDimitry Andric{ 26990b57cec5SDimitry Andric size_type __n = static_cast<size_type>(__il.size()); 27000b57cec5SDimitry Andric if (__n > 0) 27010b57cec5SDimitry Andric { 27020b57cec5SDimitry Andric __vallocate(__n); 27030b57cec5SDimitry Andric __construct_at_end(__il.begin(), __il.end()); 27040b57cec5SDimitry Andric } 27050b57cec5SDimitry Andric} 27060b57cec5SDimitry Andric 27070b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 27080b57cec5SDimitry Andric 27090b57cec5SDimitry Andrictemplate <class _Allocator> 2710*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 27110b57cec5SDimitry Andricvector<bool, _Allocator>::~vector() 27120b57cec5SDimitry Andric{ 27130b57cec5SDimitry Andric if (__begin_ != nullptr) 27140b57cec5SDimitry Andric __storage_traits::deallocate(__alloc(), __begin_, __cap()); 271581ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 27160b57cec5SDimitry Andric} 27170b57cec5SDimitry Andric 27180b57cec5SDimitry Andrictemplate <class _Allocator> 2719*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 27200b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const vector& __v) 27210b57cec5SDimitry Andric : __begin_(nullptr), 27220b57cec5SDimitry Andric __size_(0), 27230b57cec5SDimitry Andric __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc())) 27240b57cec5SDimitry Andric{ 27250b57cec5SDimitry Andric if (__v.size() > 0) 27260b57cec5SDimitry Andric { 27270b57cec5SDimitry Andric __vallocate(__v.size()); 27280b57cec5SDimitry Andric __construct_at_end(__v.begin(), __v.end()); 27290b57cec5SDimitry Andric } 27300b57cec5SDimitry Andric} 27310b57cec5SDimitry Andric 27320b57cec5SDimitry Andrictemplate <class _Allocator> 2733*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 27340b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a) 27350b57cec5SDimitry Andric : __begin_(nullptr), 27360b57cec5SDimitry Andric __size_(0), 27370b57cec5SDimitry Andric __cap_alloc_(0, __a) 27380b57cec5SDimitry Andric{ 27390b57cec5SDimitry Andric if (__v.size() > 0) 27400b57cec5SDimitry Andric { 27410b57cec5SDimitry Andric __vallocate(__v.size()); 27420b57cec5SDimitry Andric __construct_at_end(__v.begin(), __v.end()); 27430b57cec5SDimitry Andric } 27440b57cec5SDimitry Andric} 27450b57cec5SDimitry Andric 27460b57cec5SDimitry Andrictemplate <class _Allocator> 2747*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 27480b57cec5SDimitry Andricvector<bool, _Allocator>& 27490b57cec5SDimitry Andricvector<bool, _Allocator>::operator=(const vector& __v) 27500b57cec5SDimitry Andric{ 2751349cc55cSDimitry Andric if (this != _VSTD::addressof(__v)) 27520b57cec5SDimitry Andric { 27530b57cec5SDimitry Andric __copy_assign_alloc(__v); 27540b57cec5SDimitry Andric if (__v.__size_) 27550b57cec5SDimitry Andric { 27560b57cec5SDimitry Andric if (__v.__size_ > capacity()) 27570b57cec5SDimitry Andric { 27580b57cec5SDimitry Andric __vdeallocate(); 27590b57cec5SDimitry Andric __vallocate(__v.__size_); 27600b57cec5SDimitry Andric } 27610b57cec5SDimitry Andric _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_); 27620b57cec5SDimitry Andric } 27630b57cec5SDimitry Andric __size_ = __v.__size_; 27640b57cec5SDimitry Andric } 27650b57cec5SDimitry Andric return *this; 27660b57cec5SDimitry Andric} 27670b57cec5SDimitry Andric 27680b57cec5SDimitry Andrictemplate <class _Allocator> 2769*61cfbce3SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 vector<bool, _Allocator>::vector(vector&& __v) 27700b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 27710b57cec5SDimitry Andric _NOEXCEPT 27720b57cec5SDimitry Andric#else 27730b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 27740b57cec5SDimitry Andric#endif 27750b57cec5SDimitry Andric : __begin_(__v.__begin_), 27760b57cec5SDimitry Andric __size_(__v.__size_), 2777e8d8bef9SDimitry Andric __cap_alloc_(_VSTD::move(__v.__cap_alloc_)) { 27780b57cec5SDimitry Andric __v.__begin_ = nullptr; 27790b57cec5SDimitry Andric __v.__size_ = 0; 27800b57cec5SDimitry Andric __v.__cap() = 0; 27810b57cec5SDimitry Andric} 27820b57cec5SDimitry Andric 27830b57cec5SDimitry Andrictemplate <class _Allocator> 2784*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 278581ad6265SDimitry Andricvector<bool, _Allocator>::vector(vector&& __v, const __type_identity_t<allocator_type>& __a) 27860b57cec5SDimitry Andric : __begin_(nullptr), 27870b57cec5SDimitry Andric __size_(0), 27880b57cec5SDimitry Andric __cap_alloc_(0, __a) 27890b57cec5SDimitry Andric{ 27900b57cec5SDimitry Andric if (__a == allocator_type(__v.__alloc())) 27910b57cec5SDimitry Andric { 27920b57cec5SDimitry Andric this->__begin_ = __v.__begin_; 27930b57cec5SDimitry Andric this->__size_ = __v.__size_; 27940b57cec5SDimitry Andric this->__cap() = __v.__cap(); 27950b57cec5SDimitry Andric __v.__begin_ = nullptr; 27960b57cec5SDimitry Andric __v.__cap() = __v.__size_ = 0; 27970b57cec5SDimitry Andric } 27980b57cec5SDimitry Andric else if (__v.size() > 0) 27990b57cec5SDimitry Andric { 28000b57cec5SDimitry Andric __vallocate(__v.size()); 28010b57cec5SDimitry Andric __construct_at_end(__v.begin(), __v.end()); 28020b57cec5SDimitry Andric } 28030b57cec5SDimitry Andric} 28040b57cec5SDimitry Andric 28050b57cec5SDimitry Andrictemplate <class _Allocator> 2806*61cfbce3SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 28070b57cec5SDimitry Andricvector<bool, _Allocator>& 28080b57cec5SDimitry Andricvector<bool, _Allocator>::operator=(vector&& __v) 28090b57cec5SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) 28100b57cec5SDimitry Andric{ 28110b57cec5SDimitry Andric __move_assign(__v, integral_constant<bool, 28120b57cec5SDimitry Andric __storage_traits::propagate_on_container_move_assignment::value>()); 28130b57cec5SDimitry Andric return *this; 28140b57cec5SDimitry Andric} 28150b57cec5SDimitry Andric 28160b57cec5SDimitry Andrictemplate <class _Allocator> 2817*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 void 28180b57cec5SDimitry Andricvector<bool, _Allocator>::__move_assign(vector& __c, false_type) 28190b57cec5SDimitry Andric{ 28200b57cec5SDimitry Andric if (__alloc() != __c.__alloc()) 28210b57cec5SDimitry Andric assign(__c.begin(), __c.end()); 28220b57cec5SDimitry Andric else 28230b57cec5SDimitry Andric __move_assign(__c, true_type()); 28240b57cec5SDimitry Andric} 28250b57cec5SDimitry Andric 28260b57cec5SDimitry Andrictemplate <class _Allocator> 2827*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 void 28280b57cec5SDimitry Andricvector<bool, _Allocator>::__move_assign(vector& __c, true_type) 28290b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 28300b57cec5SDimitry Andric{ 28310b57cec5SDimitry Andric __vdeallocate(); 28320b57cec5SDimitry Andric __move_assign_alloc(__c); 28330b57cec5SDimitry Andric this->__begin_ = __c.__begin_; 28340b57cec5SDimitry Andric this->__size_ = __c.__size_; 28350b57cec5SDimitry Andric this->__cap() = __c.__cap(); 28360b57cec5SDimitry Andric __c.__begin_ = nullptr; 28370b57cec5SDimitry Andric __c.__cap() = __c.__size_ = 0; 28380b57cec5SDimitry Andric} 28390b57cec5SDimitry Andric 28400b57cec5SDimitry Andrictemplate <class _Allocator> 2841*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 void 28420b57cec5SDimitry Andricvector<bool, _Allocator>::assign(size_type __n, const value_type& __x) 28430b57cec5SDimitry Andric{ 28440b57cec5SDimitry Andric __size_ = 0; 28450b57cec5SDimitry Andric if (__n > 0) 28460b57cec5SDimitry Andric { 28470b57cec5SDimitry Andric size_type __c = capacity(); 28480b57cec5SDimitry Andric if (__n <= __c) 28490b57cec5SDimitry Andric __size_ = __n; 28500b57cec5SDimitry Andric else 28510b57cec5SDimitry Andric { 2852349cc55cSDimitry Andric vector __v(get_allocator()); 28530b57cec5SDimitry Andric __v.reserve(__recommend(__n)); 28540b57cec5SDimitry Andric __v.__size_ = __n; 28550b57cec5SDimitry Andric swap(__v); 28560b57cec5SDimitry Andric } 28570b57cec5SDimitry Andric _VSTD::fill_n(begin(), __n, __x); 28580b57cec5SDimitry Andric } 285981ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 28600b57cec5SDimitry Andric} 28610b57cec5SDimitry Andric 28620b57cec5SDimitry Andrictemplate <class _Allocator> 28630b57cec5SDimitry Andrictemplate <class _InputIterator> 2864*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value, 28650b57cec5SDimitry Andric void 28660b57cec5SDimitry Andric>::type 28670b57cec5SDimitry Andricvector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last) 28680b57cec5SDimitry Andric{ 28690b57cec5SDimitry Andric clear(); 28700b57cec5SDimitry Andric for (; __first != __last; ++__first) 28710b57cec5SDimitry Andric push_back(*__first); 28720b57cec5SDimitry Andric} 28730b57cec5SDimitry Andric 28740b57cec5SDimitry Andrictemplate <class _Allocator> 28750b57cec5SDimitry Andrictemplate <class _ForwardIterator> 2876*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 28770b57cec5SDimitry Andrictypename enable_if 28780b57cec5SDimitry Andric< 2879480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 28800b57cec5SDimitry Andric void 28810b57cec5SDimitry Andric>::type 28820b57cec5SDimitry Andricvector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) 28830b57cec5SDimitry Andric{ 28840b57cec5SDimitry Andric clear(); 28850b57cec5SDimitry Andric difference_type __ns = _VSTD::distance(__first, __last); 28860b57cec5SDimitry Andric _LIBCPP_ASSERT(__ns >= 0, "invalid range specified"); 28870b57cec5SDimitry Andric const size_t __n = static_cast<size_type>(__ns); 28880b57cec5SDimitry Andric if (__n) 28890b57cec5SDimitry Andric { 28900b57cec5SDimitry Andric if (__n > capacity()) 28910b57cec5SDimitry Andric { 28920b57cec5SDimitry Andric __vdeallocate(); 28930b57cec5SDimitry Andric __vallocate(__n); 28940b57cec5SDimitry Andric } 28950b57cec5SDimitry Andric __construct_at_end(__first, __last); 28960b57cec5SDimitry Andric } 28970b57cec5SDimitry Andric} 28980b57cec5SDimitry Andric 28990b57cec5SDimitry Andrictemplate <class _Allocator> 2900*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 void 29010b57cec5SDimitry Andricvector<bool, _Allocator>::reserve(size_type __n) 29020b57cec5SDimitry Andric{ 29030b57cec5SDimitry Andric if (__n > capacity()) 29040b57cec5SDimitry Andric { 2905349cc55cSDimitry Andric if (__n > max_size()) 2906349cc55cSDimitry Andric this->__throw_length_error(); 2907349cc55cSDimitry Andric vector __v(this->get_allocator()); 29080b57cec5SDimitry Andric __v.__vallocate(__n); 29090b57cec5SDimitry Andric __v.__construct_at_end(this->begin(), this->end()); 29100b57cec5SDimitry Andric swap(__v); 291181ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 29120b57cec5SDimitry Andric } 29130b57cec5SDimitry Andric} 29140b57cec5SDimitry Andric 29150b57cec5SDimitry Andrictemplate <class _Allocator> 2916*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 void 29170b57cec5SDimitry Andricvector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT 29180b57cec5SDimitry Andric{ 29190b57cec5SDimitry Andric if (__external_cap_to_internal(size()) > __cap()) 29200b57cec5SDimitry Andric { 29210b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 29220b57cec5SDimitry Andric try 29230b57cec5SDimitry Andric { 29240b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 29250b57cec5SDimitry Andric vector(*this, allocator_type(__alloc())).swap(*this); 29260b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 29270b57cec5SDimitry Andric } 29280b57cec5SDimitry Andric catch (...) 29290b57cec5SDimitry Andric { 29300b57cec5SDimitry Andric } 29310b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 29320b57cec5SDimitry Andric } 29330b57cec5SDimitry Andric} 29340b57cec5SDimitry Andric 29350b57cec5SDimitry Andrictemplate <class _Allocator> 29360b57cec5SDimitry Andrictypename vector<bool, _Allocator>::reference 29370b57cec5SDimitry Andricvector<bool, _Allocator>::at(size_type __n) 29380b57cec5SDimitry Andric{ 29390b57cec5SDimitry Andric if (__n >= size()) 29400b57cec5SDimitry Andric this->__throw_out_of_range(); 29410b57cec5SDimitry Andric return (*this)[__n]; 29420b57cec5SDimitry Andric} 29430b57cec5SDimitry Andric 29440b57cec5SDimitry Andrictemplate <class _Allocator> 29450b57cec5SDimitry Andrictypename vector<bool, _Allocator>::const_reference 29460b57cec5SDimitry Andricvector<bool, _Allocator>::at(size_type __n) const 29470b57cec5SDimitry Andric{ 29480b57cec5SDimitry Andric if (__n >= size()) 29490b57cec5SDimitry Andric this->__throw_out_of_range(); 29500b57cec5SDimitry Andric return (*this)[__n]; 29510b57cec5SDimitry Andric} 29520b57cec5SDimitry Andric 29530b57cec5SDimitry Andrictemplate <class _Allocator> 2954*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 void 29550b57cec5SDimitry Andricvector<bool, _Allocator>::push_back(const value_type& __x) 29560b57cec5SDimitry Andric{ 29570b57cec5SDimitry Andric if (this->__size_ == this->capacity()) 29580b57cec5SDimitry Andric reserve(__recommend(this->__size_ + 1)); 29590b57cec5SDimitry Andric ++this->__size_; 29600b57cec5SDimitry Andric back() = __x; 29610b57cec5SDimitry Andric} 29620b57cec5SDimitry Andric 29630b57cec5SDimitry Andrictemplate <class _Allocator> 2964*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 typename vector<bool, _Allocator>::iterator 29650b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x) 29660b57cec5SDimitry Andric{ 29670b57cec5SDimitry Andric iterator __r; 29680b57cec5SDimitry Andric if (size() < capacity()) 29690b57cec5SDimitry Andric { 29700b57cec5SDimitry Andric const_iterator __old_end = end(); 29710b57cec5SDimitry Andric ++__size_; 29720b57cec5SDimitry Andric _VSTD::copy_backward(__position, __old_end, end()); 29730b57cec5SDimitry Andric __r = __const_iterator_cast(__position); 29740b57cec5SDimitry Andric } 29750b57cec5SDimitry Andric else 29760b57cec5SDimitry Andric { 2977349cc55cSDimitry Andric vector __v(get_allocator()); 29780b57cec5SDimitry Andric __v.reserve(__recommend(__size_ + 1)); 29790b57cec5SDimitry Andric __v.__size_ = __size_ + 1; 29800b57cec5SDimitry Andric __r = _VSTD::copy(cbegin(), __position, __v.begin()); 29810b57cec5SDimitry Andric _VSTD::copy_backward(__position, cend(), __v.end()); 29820b57cec5SDimitry Andric swap(__v); 29830b57cec5SDimitry Andric } 29840b57cec5SDimitry Andric *__r = __x; 29850b57cec5SDimitry Andric return __r; 29860b57cec5SDimitry Andric} 29870b57cec5SDimitry Andric 29880b57cec5SDimitry Andrictemplate <class _Allocator> 2989*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 typename vector<bool, _Allocator>::iterator 29900b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x) 29910b57cec5SDimitry Andric{ 29920b57cec5SDimitry Andric iterator __r; 29930b57cec5SDimitry Andric size_type __c = capacity(); 29940b57cec5SDimitry Andric if (__n <= __c && size() <= __c - __n) 29950b57cec5SDimitry Andric { 29960b57cec5SDimitry Andric const_iterator __old_end = end(); 29970b57cec5SDimitry Andric __size_ += __n; 29980b57cec5SDimitry Andric _VSTD::copy_backward(__position, __old_end, end()); 29990b57cec5SDimitry Andric __r = __const_iterator_cast(__position); 30000b57cec5SDimitry Andric } 30010b57cec5SDimitry Andric else 30020b57cec5SDimitry Andric { 3003349cc55cSDimitry Andric vector __v(get_allocator()); 30040b57cec5SDimitry Andric __v.reserve(__recommend(__size_ + __n)); 30050b57cec5SDimitry Andric __v.__size_ = __size_ + __n; 30060b57cec5SDimitry Andric __r = _VSTD::copy(cbegin(), __position, __v.begin()); 30070b57cec5SDimitry Andric _VSTD::copy_backward(__position, cend(), __v.end()); 30080b57cec5SDimitry Andric swap(__v); 30090b57cec5SDimitry Andric } 30100b57cec5SDimitry Andric _VSTD::fill_n(__r, __n, __x); 30110b57cec5SDimitry Andric return __r; 30120b57cec5SDimitry Andric} 30130b57cec5SDimitry Andric 30140b57cec5SDimitry Andrictemplate <class _Allocator> 30150b57cec5SDimitry Andrictemplate <class _InputIterator> 3016*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value, 30170b57cec5SDimitry Andric typename vector<bool, _Allocator>::iterator 30180b57cec5SDimitry Andric>::type 30190b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) 30200b57cec5SDimitry Andric{ 30210b57cec5SDimitry Andric difference_type __off = __position - begin(); 30220b57cec5SDimitry Andric iterator __p = __const_iterator_cast(__position); 30230b57cec5SDimitry Andric iterator __old_end = end(); 30240b57cec5SDimitry Andric for (; size() != capacity() && __first != __last; ++__first) 30250b57cec5SDimitry Andric { 30260b57cec5SDimitry Andric ++this->__size_; 30270b57cec5SDimitry Andric back() = *__first; 30280b57cec5SDimitry Andric } 3029349cc55cSDimitry Andric vector __v(get_allocator()); 30300b57cec5SDimitry Andric if (__first != __last) 30310b57cec5SDimitry Andric { 30320b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 30330b57cec5SDimitry Andric try 30340b57cec5SDimitry Andric { 30350b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 30360b57cec5SDimitry Andric __v.assign(__first, __last); 30370b57cec5SDimitry Andric difference_type __old_size = static_cast<difference_type>(__old_end - begin()); 30380b57cec5SDimitry Andric difference_type __old_p = __p - begin(); 30390b57cec5SDimitry Andric reserve(__recommend(size() + __v.size())); 30400b57cec5SDimitry Andric __p = begin() + __old_p; 30410b57cec5SDimitry Andric __old_end = begin() + __old_size; 30420b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 30430b57cec5SDimitry Andric } 30440b57cec5SDimitry Andric catch (...) 30450b57cec5SDimitry Andric { 30460b57cec5SDimitry Andric erase(__old_end, end()); 30470b57cec5SDimitry Andric throw; 30480b57cec5SDimitry Andric } 30490b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 30500b57cec5SDimitry Andric } 30510b57cec5SDimitry Andric __p = _VSTD::rotate(__p, __old_end, end()); 30520b57cec5SDimitry Andric insert(__p, __v.begin(), __v.end()); 30530b57cec5SDimitry Andric return begin() + __off; 30540b57cec5SDimitry Andric} 30550b57cec5SDimitry Andric 30560b57cec5SDimitry Andrictemplate <class _Allocator> 30570b57cec5SDimitry Andrictemplate <class _ForwardIterator> 3058*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 30590b57cec5SDimitry Andrictypename enable_if 30600b57cec5SDimitry Andric< 3061480093f4SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 30620b57cec5SDimitry Andric typename vector<bool, _Allocator>::iterator 30630b57cec5SDimitry Andric>::type 30640b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) 30650b57cec5SDimitry Andric{ 30660b57cec5SDimitry Andric const difference_type __n_signed = _VSTD::distance(__first, __last); 30670b57cec5SDimitry Andric _LIBCPP_ASSERT(__n_signed >= 0, "invalid range specified"); 30680b57cec5SDimitry Andric const size_type __n = static_cast<size_type>(__n_signed); 30690b57cec5SDimitry Andric iterator __r; 30700b57cec5SDimitry Andric size_type __c = capacity(); 30710b57cec5SDimitry Andric if (__n <= __c && size() <= __c - __n) 30720b57cec5SDimitry Andric { 30730b57cec5SDimitry Andric const_iterator __old_end = end(); 30740b57cec5SDimitry Andric __size_ += __n; 30750b57cec5SDimitry Andric _VSTD::copy_backward(__position, __old_end, end()); 30760b57cec5SDimitry Andric __r = __const_iterator_cast(__position); 30770b57cec5SDimitry Andric } 30780b57cec5SDimitry Andric else 30790b57cec5SDimitry Andric { 3080349cc55cSDimitry Andric vector __v(get_allocator()); 30810b57cec5SDimitry Andric __v.reserve(__recommend(__size_ + __n)); 30820b57cec5SDimitry Andric __v.__size_ = __size_ + __n; 30830b57cec5SDimitry Andric __r = _VSTD::copy(cbegin(), __position, __v.begin()); 30840b57cec5SDimitry Andric _VSTD::copy_backward(__position, cend(), __v.end()); 30850b57cec5SDimitry Andric swap(__v); 30860b57cec5SDimitry Andric } 30870b57cec5SDimitry Andric _VSTD::copy(__first, __last, __r); 30880b57cec5SDimitry Andric return __r; 30890b57cec5SDimitry Andric} 30900b57cec5SDimitry Andric 30910b57cec5SDimitry Andrictemplate <class _Allocator> 3092*61cfbce3SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 30930b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator 30940b57cec5SDimitry Andricvector<bool, _Allocator>::erase(const_iterator __position) 30950b57cec5SDimitry Andric{ 30960b57cec5SDimitry Andric iterator __r = __const_iterator_cast(__position); 30970b57cec5SDimitry Andric _VSTD::copy(__position + 1, this->cend(), __r); 30980b57cec5SDimitry Andric --__size_; 30990b57cec5SDimitry Andric return __r; 31000b57cec5SDimitry Andric} 31010b57cec5SDimitry Andric 31020b57cec5SDimitry Andrictemplate <class _Allocator> 3103*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 31040b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator 31050b57cec5SDimitry Andricvector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last) 31060b57cec5SDimitry Andric{ 31070b57cec5SDimitry Andric iterator __r = __const_iterator_cast(__first); 31080b57cec5SDimitry Andric difference_type __d = __last - __first; 31090b57cec5SDimitry Andric _VSTD::copy(__last, this->cend(), __r); 31100b57cec5SDimitry Andric __size_ -= __d; 31110b57cec5SDimitry Andric return __r; 31120b57cec5SDimitry Andric} 31130b57cec5SDimitry Andric 31140b57cec5SDimitry Andrictemplate <class _Allocator> 3115*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 void 31160b57cec5SDimitry Andricvector<bool, _Allocator>::swap(vector& __x) 31170b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 31180b57cec5SDimitry Andric _NOEXCEPT 31190b57cec5SDimitry Andric#else 31200b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 31210b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value) 31220b57cec5SDimitry Andric#endif 31230b57cec5SDimitry Andric{ 31240b57cec5SDimitry Andric _VSTD::swap(this->__begin_, __x.__begin_); 31250b57cec5SDimitry Andric _VSTD::swap(this->__size_, __x.__size_); 31260b57cec5SDimitry Andric _VSTD::swap(this->__cap(), __x.__cap()); 3127e8d8bef9SDimitry Andric _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(), 31280b57cec5SDimitry Andric integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>()); 31290b57cec5SDimitry Andric} 31300b57cec5SDimitry Andric 31310b57cec5SDimitry Andrictemplate <class _Allocator> 3132*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 void 31330b57cec5SDimitry Andricvector<bool, _Allocator>::resize(size_type __sz, value_type __x) 31340b57cec5SDimitry Andric{ 31350b57cec5SDimitry Andric size_type __cs = size(); 31360b57cec5SDimitry Andric if (__cs < __sz) 31370b57cec5SDimitry Andric { 31380b57cec5SDimitry Andric iterator __r; 31390b57cec5SDimitry Andric size_type __c = capacity(); 31400b57cec5SDimitry Andric size_type __n = __sz - __cs; 31410b57cec5SDimitry Andric if (__n <= __c && __cs <= __c - __n) 31420b57cec5SDimitry Andric { 31430b57cec5SDimitry Andric __r = end(); 31440b57cec5SDimitry Andric __size_ += __n; 31450b57cec5SDimitry Andric } 31460b57cec5SDimitry Andric else 31470b57cec5SDimitry Andric { 3148349cc55cSDimitry Andric vector __v(get_allocator()); 31490b57cec5SDimitry Andric __v.reserve(__recommend(__size_ + __n)); 31500b57cec5SDimitry Andric __v.__size_ = __size_ + __n; 31510b57cec5SDimitry Andric __r = _VSTD::copy(cbegin(), cend(), __v.begin()); 31520b57cec5SDimitry Andric swap(__v); 31530b57cec5SDimitry Andric } 31540b57cec5SDimitry Andric _VSTD::fill_n(__r, __n, __x); 31550b57cec5SDimitry Andric } 31560b57cec5SDimitry Andric else 31570b57cec5SDimitry Andric __size_ = __sz; 31580b57cec5SDimitry Andric} 31590b57cec5SDimitry Andric 31600b57cec5SDimitry Andrictemplate <class _Allocator> 3161*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 void 31620b57cec5SDimitry Andricvector<bool, _Allocator>::flip() _NOEXCEPT 31630b57cec5SDimitry Andric{ 31640b57cec5SDimitry Andric // do middle whole words 31650b57cec5SDimitry Andric size_type __n = __size_; 31660b57cec5SDimitry Andric __storage_pointer __p = __begin_; 31670b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 31680b57cec5SDimitry Andric *__p = ~*__p; 31690b57cec5SDimitry Andric // do last partial word 31700b57cec5SDimitry Andric if (__n > 0) 31710b57cec5SDimitry Andric { 31720b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 31730b57cec5SDimitry Andric __storage_type __b = *__p & __m; 31740b57cec5SDimitry Andric *__p &= ~__m; 31750b57cec5SDimitry Andric *__p |= ~__b & __m; 31760b57cec5SDimitry Andric } 31770b57cec5SDimitry Andric} 31780b57cec5SDimitry Andric 31790b57cec5SDimitry Andrictemplate <class _Allocator> 3180*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool 31810b57cec5SDimitry Andricvector<bool, _Allocator>::__invariants() const 31820b57cec5SDimitry Andric{ 31830b57cec5SDimitry Andric if (this->__begin_ == nullptr) 31840b57cec5SDimitry Andric { 31850b57cec5SDimitry Andric if (this->__size_ != 0 || this->__cap() != 0) 31860b57cec5SDimitry Andric return false; 31870b57cec5SDimitry Andric } 31880b57cec5SDimitry Andric else 31890b57cec5SDimitry Andric { 31900b57cec5SDimitry Andric if (this->__cap() == 0) 31910b57cec5SDimitry Andric return false; 31920b57cec5SDimitry Andric if (this->__size_ > this->capacity()) 31930b57cec5SDimitry Andric return false; 31940b57cec5SDimitry Andric } 31950b57cec5SDimitry Andric return true; 31960b57cec5SDimitry Andric} 31970b57cec5SDimitry Andric 31980b57cec5SDimitry Andrictemplate <class _Allocator> 3199*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 size_t 32000b57cec5SDimitry Andricvector<bool, _Allocator>::__hash_code() const _NOEXCEPT 32010b57cec5SDimitry Andric{ 32020b57cec5SDimitry Andric size_t __h = 0; 32030b57cec5SDimitry Andric // do middle whole words 32040b57cec5SDimitry Andric size_type __n = __size_; 32050b57cec5SDimitry Andric __storage_pointer __p = __begin_; 32060b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 32070b57cec5SDimitry Andric __h ^= *__p; 32080b57cec5SDimitry Andric // do last partial word 32090b57cec5SDimitry Andric if (__n > 0) 32100b57cec5SDimitry Andric { 32110b57cec5SDimitry Andric const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 32120b57cec5SDimitry Andric __h ^= *__p & __m; 32130b57cec5SDimitry Andric } 32140b57cec5SDimitry Andric return __h; 32150b57cec5SDimitry Andric} 32160b57cec5SDimitry Andric 32170b57cec5SDimitry Andrictemplate <class _Allocator> 32180b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> > 321981ad6265SDimitry Andric : public __unary_function<vector<bool, _Allocator>, size_t> 32200b57cec5SDimitry Andric{ 3221*61cfbce3SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 32220b57cec5SDimitry Andric size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT 32230b57cec5SDimitry Andric {return __vec.__hash_code();} 32240b57cec5SDimitry Andric}; 32250b57cec5SDimitry Andric 32260b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 3227*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 32280b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 32290b57cec5SDimitry Andricbool 32300b57cec5SDimitry Andricoperator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 32310b57cec5SDimitry Andric{ 32320b57cec5SDimitry Andric const typename vector<_Tp, _Allocator>::size_type __sz = __x.size(); 32330b57cec5SDimitry Andric return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); 32340b57cec5SDimitry Andric} 32350b57cec5SDimitry Andric 32360b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 3237*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 32380b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 32390b57cec5SDimitry Andricbool 32400b57cec5SDimitry Andricoperator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 32410b57cec5SDimitry Andric{ 32420b57cec5SDimitry Andric return !(__x == __y); 32430b57cec5SDimitry Andric} 32440b57cec5SDimitry Andric 32450b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 3246*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 32470b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 32480b57cec5SDimitry Andricbool 32490b57cec5SDimitry Andricoperator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 32500b57cec5SDimitry Andric{ 32510b57cec5SDimitry Andric return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); 32520b57cec5SDimitry Andric} 32530b57cec5SDimitry Andric 32540b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 3255*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 32560b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 32570b57cec5SDimitry Andricbool 32580b57cec5SDimitry Andricoperator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 32590b57cec5SDimitry Andric{ 32600b57cec5SDimitry Andric return __y < __x; 32610b57cec5SDimitry Andric} 32620b57cec5SDimitry Andric 32630b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 3264*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 32650b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 32660b57cec5SDimitry Andricbool 32670b57cec5SDimitry Andricoperator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 32680b57cec5SDimitry Andric{ 32690b57cec5SDimitry Andric return !(__x < __y); 32700b57cec5SDimitry Andric} 32710b57cec5SDimitry Andric 32720b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 3273*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 32740b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 32750b57cec5SDimitry Andricbool 32760b57cec5SDimitry Andricoperator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 32770b57cec5SDimitry Andric{ 32780b57cec5SDimitry Andric return !(__y < __x); 32790b57cec5SDimitry Andric} 32800b57cec5SDimitry Andric 32810b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 3282*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 32830b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 32840b57cec5SDimitry Andricvoid 32850b57cec5SDimitry Andricswap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) 32860b57cec5SDimitry Andric _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 32870b57cec5SDimitry Andric{ 32880b57cec5SDimitry Andric __x.swap(__y); 32890b57cec5SDimitry Andric} 32900b57cec5SDimitry Andric 32910b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17 32920b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Up> 3293*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 32945ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type 32955ffd83dbSDimitry Andricerase(vector<_Tp, _Allocator>& __c, const _Up& __v) { 32965ffd83dbSDimitry Andric auto __old_size = __c.size(); 32975ffd83dbSDimitry Andric __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end()); 32985ffd83dbSDimitry Andric return __old_size - __c.size(); 32995ffd83dbSDimitry Andric} 33000b57cec5SDimitry Andric 33010b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Predicate> 3302*61cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 33035ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type 33045ffd83dbSDimitry Andricerase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) { 33055ffd83dbSDimitry Andric auto __old_size = __c.size(); 33065ffd83dbSDimitry Andric __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end()); 33075ffd83dbSDimitry Andric return __old_size - __c.size(); 33085ffd83dbSDimitry Andric} 330981ad6265SDimitry Andric 331081ad6265SDimitry Andrictemplate <> 331181ad6265SDimitry Andricinline constexpr bool __format::__enable_insertable<std::vector<char>> = true; 331281ad6265SDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 331381ad6265SDimitry Andrictemplate <> 331481ad6265SDimitry Andricinline constexpr bool __format::__enable_insertable<std::vector<wchar_t>> = true; 33150b57cec5SDimitry Andric#endif 33160b57cec5SDimitry Andric 331781ad6265SDimitry Andric#endif // _LIBCPP_STD_VER > 17 331881ad6265SDimitry Andric 33190b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 33200b57cec5SDimitry Andric 33210b57cec5SDimitry Andric_LIBCPP_POP_MACROS 33220b57cec5SDimitry Andric 33230b57cec5SDimitry Andric#endif // _LIBCPP_VECTOR 3324