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 13c9157d92SDimitry Andric// clang-format off 14c9157d92SDimitry Andric 150b57cec5SDimitry Andric/* 160b57cec5SDimitry Andric vector synopsis 170b57cec5SDimitry Andric 180b57cec5SDimitry Andricnamespace std 190b57cec5SDimitry Andric{ 200b57cec5SDimitry Andric 210b57cec5SDimitry Andrictemplate <class T, class Allocator = allocator<T> > 220b57cec5SDimitry Andricclass vector 230b57cec5SDimitry Andric{ 240b57cec5SDimitry Andricpublic: 250b57cec5SDimitry Andric typedef T value_type; 260b57cec5SDimitry Andric typedef Allocator allocator_type; 270b57cec5SDimitry Andric typedef typename allocator_type::reference reference; 280b57cec5SDimitry Andric typedef typename allocator_type::const_reference const_reference; 290b57cec5SDimitry Andric typedef implementation-defined iterator; 300b57cec5SDimitry Andric typedef implementation-defined const_iterator; 310b57cec5SDimitry Andric typedef typename allocator_type::size_type size_type; 320b57cec5SDimitry Andric typedef typename allocator_type::difference_type difference_type; 330b57cec5SDimitry Andric typedef typename allocator_type::pointer pointer; 340b57cec5SDimitry Andric typedef typename allocator_type::const_pointer const_pointer; 350b57cec5SDimitry Andric typedef std::reverse_iterator<iterator> reverse_iterator; 360b57cec5SDimitry Andric typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 370b57cec5SDimitry Andric 380b57cec5SDimitry Andric vector() 390b57cec5SDimitry Andric noexcept(is_nothrow_default_constructible<allocator_type>::value); 400b57cec5SDimitry Andric explicit vector(const allocator_type&); 410b57cec5SDimitry Andric explicit vector(size_type n); 420b57cec5SDimitry Andric explicit vector(size_type n, const allocator_type&); // C++14 430b57cec5SDimitry Andric vector(size_type n, const value_type& value, const allocator_type& = allocator_type()); 440b57cec5SDimitry Andric template <class InputIterator> 450b57cec5SDimitry Andric vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); 46fe013be4SDimitry Andric template<container-compatible-range<T> R> 47fe013be4SDimitry Andric constexpr vector(from_range_t, R&& rg, const Allocator& = Allocator()); // C++23 480b57cec5SDimitry Andric vector(const vector& x); 490b57cec5SDimitry Andric vector(vector&& x) 500b57cec5SDimitry Andric noexcept(is_nothrow_move_constructible<allocator_type>::value); 510b57cec5SDimitry Andric vector(initializer_list<value_type> il); 520b57cec5SDimitry Andric vector(initializer_list<value_type> il, const allocator_type& a); 530b57cec5SDimitry Andric ~vector(); 540b57cec5SDimitry Andric vector& operator=(const vector& x); 550b57cec5SDimitry Andric vector& operator=(vector&& x) 560b57cec5SDimitry Andric noexcept( 570b57cec5SDimitry Andric allocator_type::propagate_on_container_move_assignment::value || 580b57cec5SDimitry Andric allocator_type::is_always_equal::value); // C++17 590b57cec5SDimitry Andric vector& operator=(initializer_list<value_type> il); 600b57cec5SDimitry Andric template <class InputIterator> 610b57cec5SDimitry Andric void assign(InputIterator first, InputIterator last); 62fe013be4SDimitry Andric template<container-compatible-range<T> R> 63fe013be4SDimitry Andric constexpr void assign_range(R&& rg); // C++23 640b57cec5SDimitry Andric void assign(size_type n, const value_type& u); 650b57cec5SDimitry Andric void assign(initializer_list<value_type> il); 660b57cec5SDimitry Andric 670b57cec5SDimitry Andric allocator_type get_allocator() const noexcept; 680b57cec5SDimitry Andric 690b57cec5SDimitry Andric iterator begin() noexcept; 700b57cec5SDimitry Andric const_iterator begin() const noexcept; 710b57cec5SDimitry Andric iterator end() noexcept; 720b57cec5SDimitry Andric const_iterator end() const noexcept; 730b57cec5SDimitry Andric 740b57cec5SDimitry Andric reverse_iterator rbegin() noexcept; 750b57cec5SDimitry Andric const_reverse_iterator rbegin() const noexcept; 760b57cec5SDimitry Andric reverse_iterator rend() noexcept; 770b57cec5SDimitry Andric const_reverse_iterator rend() const noexcept; 780b57cec5SDimitry Andric 790b57cec5SDimitry Andric const_iterator cbegin() const noexcept; 800b57cec5SDimitry Andric const_iterator cend() const noexcept; 810b57cec5SDimitry Andric const_reverse_iterator crbegin() const noexcept; 820b57cec5SDimitry Andric const_reverse_iterator crend() const noexcept; 830b57cec5SDimitry Andric 840b57cec5SDimitry Andric size_type size() const noexcept; 850b57cec5SDimitry Andric size_type max_size() const noexcept; 860b57cec5SDimitry Andric size_type capacity() const noexcept; 870b57cec5SDimitry Andric bool empty() const noexcept; 880b57cec5SDimitry Andric void reserve(size_type n); 890b57cec5SDimitry Andric void shrink_to_fit() noexcept; 900b57cec5SDimitry Andric 910b57cec5SDimitry Andric reference operator[](size_type n); 920b57cec5SDimitry Andric const_reference operator[](size_type n) const; 930b57cec5SDimitry Andric reference at(size_type n); 940b57cec5SDimitry Andric const_reference at(size_type n) const; 950b57cec5SDimitry Andric 960b57cec5SDimitry Andric reference front(); 970b57cec5SDimitry Andric const_reference front() const; 980b57cec5SDimitry Andric reference back(); 990b57cec5SDimitry Andric const_reference back() const; 1000b57cec5SDimitry Andric 1010b57cec5SDimitry Andric value_type* data() noexcept; 1020b57cec5SDimitry Andric const value_type* data() const noexcept; 1030b57cec5SDimitry Andric 1040b57cec5SDimitry Andric void push_back(const value_type& x); 1050b57cec5SDimitry Andric void push_back(value_type&& x); 1060b57cec5SDimitry Andric template <class... Args> 1070b57cec5SDimitry Andric reference emplace_back(Args&&... args); // reference in C++17 108fe013be4SDimitry Andric template<container-compatible-range<T> R> 109fe013be4SDimitry Andric constexpr void append_range(R&& rg); // C++23 1100b57cec5SDimitry Andric void pop_back(); 1110b57cec5SDimitry Andric 1120b57cec5SDimitry Andric template <class... Args> iterator emplace(const_iterator position, Args&&... args); 1130b57cec5SDimitry Andric iterator insert(const_iterator position, const value_type& x); 1140b57cec5SDimitry Andric iterator insert(const_iterator position, value_type&& x); 1150b57cec5SDimitry Andric iterator insert(const_iterator position, size_type n, const value_type& x); 1160b57cec5SDimitry Andric template <class InputIterator> 1170b57cec5SDimitry Andric iterator insert(const_iterator position, InputIterator first, InputIterator last); 118fe013be4SDimitry Andric template<container-compatible-range<T> R> 119fe013be4SDimitry Andric constexpr iterator insert_range(const_iterator position, R&& rg); // C++23 1200b57cec5SDimitry Andric iterator insert(const_iterator position, initializer_list<value_type> il); 1210b57cec5SDimitry Andric 1220b57cec5SDimitry Andric iterator erase(const_iterator position); 1230b57cec5SDimitry Andric iterator erase(const_iterator first, const_iterator last); 1240b57cec5SDimitry Andric 1250b57cec5SDimitry Andric void clear() noexcept; 1260b57cec5SDimitry Andric 1270b57cec5SDimitry Andric void resize(size_type sz); 1280b57cec5SDimitry Andric void resize(size_type sz, const value_type& c); 1290b57cec5SDimitry Andric 1300b57cec5SDimitry Andric void swap(vector&) 1310b57cec5SDimitry Andric noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || 1320b57cec5SDimitry Andric allocator_traits<allocator_type>::is_always_equal::value); // C++17 1330b57cec5SDimitry Andric 1340b57cec5SDimitry Andric bool __invariants() const; 1350b57cec5SDimitry Andric}; 1360b57cec5SDimitry Andric 1370b57cec5SDimitry Andrictemplate <class Allocator = allocator<T> > 1380b57cec5SDimitry Andricclass vector<bool, Allocator> 1390b57cec5SDimitry Andric{ 1400b57cec5SDimitry Andricpublic: 1410b57cec5SDimitry Andric typedef bool value_type; 1420b57cec5SDimitry Andric typedef Allocator allocator_type; 1430b57cec5SDimitry Andric typedef implementation-defined iterator; 1440b57cec5SDimitry Andric typedef implementation-defined const_iterator; 1450b57cec5SDimitry Andric typedef typename allocator_type::size_type size_type; 1460b57cec5SDimitry Andric typedef typename allocator_type::difference_type difference_type; 1470b57cec5SDimitry Andric typedef iterator pointer; 1480b57cec5SDimitry Andric typedef const_iterator const_pointer; 1490b57cec5SDimitry Andric typedef std::reverse_iterator<iterator> reverse_iterator; 1500b57cec5SDimitry Andric typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 1510b57cec5SDimitry Andric 1520b57cec5SDimitry Andric class reference 1530b57cec5SDimitry Andric { 1540b57cec5SDimitry Andric public: 1550b57cec5SDimitry Andric reference(const reference&) noexcept; 1560b57cec5SDimitry Andric operator bool() const noexcept; 157fe6060f1SDimitry Andric reference& operator=(bool x) noexcept; 1580b57cec5SDimitry Andric reference& operator=(const reference& x) noexcept; 1590b57cec5SDimitry Andric iterator operator&() const noexcept; 1600b57cec5SDimitry Andric void flip() noexcept; 1610b57cec5SDimitry Andric }; 1620b57cec5SDimitry Andric 1630b57cec5SDimitry Andric class const_reference 1640b57cec5SDimitry Andric { 1650b57cec5SDimitry Andric public: 1660b57cec5SDimitry Andric const_reference(const reference&) noexcept; 1670b57cec5SDimitry Andric operator bool() const noexcept; 1680b57cec5SDimitry Andric const_iterator operator&() const noexcept; 1690b57cec5SDimitry Andric }; 1700b57cec5SDimitry Andric 1710b57cec5SDimitry Andric vector() 1720b57cec5SDimitry Andric noexcept(is_nothrow_default_constructible<allocator_type>::value); 1730b57cec5SDimitry Andric explicit vector(const allocator_type&); 1740b57cec5SDimitry Andric explicit vector(size_type n, const allocator_type& a = allocator_type()); // C++14 1750b57cec5SDimitry Andric vector(size_type n, const value_type& value, const allocator_type& = allocator_type()); 1760b57cec5SDimitry Andric template <class InputIterator> 1770b57cec5SDimitry Andric vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); 178fe013be4SDimitry Andric template<container-compatible-range<bool> R> 179fe013be4SDimitry Andric constexpr vector(from_range_t, R&& rg, const Allocator& = Allocator()); 1800b57cec5SDimitry Andric vector(const vector& x); 1810b57cec5SDimitry Andric vector(vector&& x) 1820b57cec5SDimitry Andric noexcept(is_nothrow_move_constructible<allocator_type>::value); 1830b57cec5SDimitry Andric vector(initializer_list<value_type> il); 1840b57cec5SDimitry Andric vector(initializer_list<value_type> il, const allocator_type& a); 1850b57cec5SDimitry Andric ~vector(); 1860b57cec5SDimitry Andric vector& operator=(const vector& x); 1870b57cec5SDimitry Andric vector& operator=(vector&& x) 1880b57cec5SDimitry Andric noexcept( 1890b57cec5SDimitry Andric allocator_type::propagate_on_container_move_assignment::value || 1900b57cec5SDimitry Andric allocator_type::is_always_equal::value); // C++17 1910b57cec5SDimitry Andric vector& operator=(initializer_list<value_type> il); 1920b57cec5SDimitry Andric template <class InputIterator> 1930b57cec5SDimitry Andric void assign(InputIterator first, InputIterator last); 194fe013be4SDimitry Andric template<container-compatible-range<T> R> 195fe013be4SDimitry Andric constexpr void assign_range(R&& rg); // C++23 1960b57cec5SDimitry Andric void assign(size_type n, const value_type& u); 1970b57cec5SDimitry Andric void assign(initializer_list<value_type> il); 1980b57cec5SDimitry Andric 1990b57cec5SDimitry Andric allocator_type get_allocator() const noexcept; 2000b57cec5SDimitry Andric 2010b57cec5SDimitry Andric iterator begin() noexcept; 2020b57cec5SDimitry Andric const_iterator begin() const noexcept; 2030b57cec5SDimitry Andric iterator end() noexcept; 2040b57cec5SDimitry Andric const_iterator end() const noexcept; 2050b57cec5SDimitry Andric 2060b57cec5SDimitry Andric reverse_iterator rbegin() noexcept; 2070b57cec5SDimitry Andric const_reverse_iterator rbegin() const noexcept; 2080b57cec5SDimitry Andric reverse_iterator rend() noexcept; 2090b57cec5SDimitry Andric const_reverse_iterator rend() const noexcept; 2100b57cec5SDimitry Andric 2110b57cec5SDimitry Andric const_iterator cbegin() const noexcept; 2120b57cec5SDimitry Andric const_iterator cend() const noexcept; 2130b57cec5SDimitry Andric const_reverse_iterator crbegin() const noexcept; 2140b57cec5SDimitry Andric const_reverse_iterator crend() const noexcept; 2150b57cec5SDimitry Andric 2160b57cec5SDimitry Andric size_type size() const noexcept; 2170b57cec5SDimitry Andric size_type max_size() const noexcept; 2180b57cec5SDimitry Andric size_type capacity() const noexcept; 2190b57cec5SDimitry Andric bool empty() const noexcept; 2200b57cec5SDimitry Andric void reserve(size_type n); 2210b57cec5SDimitry Andric void shrink_to_fit() noexcept; 2220b57cec5SDimitry Andric 2230b57cec5SDimitry Andric reference operator[](size_type n); 2240b57cec5SDimitry Andric const_reference operator[](size_type n) const; 2250b57cec5SDimitry Andric reference at(size_type n); 2260b57cec5SDimitry Andric const_reference at(size_type n) const; 2270b57cec5SDimitry Andric 2280b57cec5SDimitry Andric reference front(); 2290b57cec5SDimitry Andric const_reference front() const; 2300b57cec5SDimitry Andric reference back(); 2310b57cec5SDimitry Andric const_reference back() const; 2320b57cec5SDimitry Andric 2330b57cec5SDimitry Andric void push_back(const value_type& x); 2340b57cec5SDimitry Andric template <class... Args> reference emplace_back(Args&&... args); // C++14; reference in C++17 235fe013be4SDimitry Andric template<container-compatible-range<T> R> 236fe013be4SDimitry Andric constexpr void append_range(R&& rg); // C++23 2370b57cec5SDimitry Andric void pop_back(); 2380b57cec5SDimitry Andric 2390b57cec5SDimitry Andric template <class... Args> iterator emplace(const_iterator position, Args&&... args); // C++14 2400b57cec5SDimitry Andric iterator insert(const_iterator position, const value_type& x); 2410b57cec5SDimitry Andric iterator insert(const_iterator position, size_type n, const value_type& x); 2420b57cec5SDimitry Andric template <class InputIterator> 2430b57cec5SDimitry Andric iterator insert(const_iterator position, InputIterator first, InputIterator last); 244fe013be4SDimitry Andric template<container-compatible-range<T> R> 245fe013be4SDimitry Andric constexpr iterator insert_range(const_iterator position, R&& rg); // C++23 2460b57cec5SDimitry Andric iterator insert(const_iterator position, initializer_list<value_type> il); 2470b57cec5SDimitry Andric 2480b57cec5SDimitry Andric iterator erase(const_iterator position); 2490b57cec5SDimitry Andric iterator erase(const_iterator first, const_iterator last); 2500b57cec5SDimitry Andric 2510b57cec5SDimitry Andric void clear() noexcept; 2520b57cec5SDimitry Andric 2530b57cec5SDimitry Andric void resize(size_type sz); 2540b57cec5SDimitry Andric void resize(size_type sz, value_type x); 2550b57cec5SDimitry Andric 2560b57cec5SDimitry Andric void swap(vector&) 2570b57cec5SDimitry Andric noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || 2580b57cec5SDimitry Andric allocator_traits<allocator_type>::is_always_equal::value); // C++17 2590b57cec5SDimitry Andric void flip() noexcept; 2600b57cec5SDimitry Andric 2610b57cec5SDimitry Andric bool __invariants() const; 2620b57cec5SDimitry Andric}; 2630b57cec5SDimitry Andric 2640b57cec5SDimitry Andrictemplate <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> 2650b57cec5SDimitry Andric vector(InputIterator, InputIterator, Allocator = Allocator()) 266349cc55cSDimitry Andric -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17 2670b57cec5SDimitry Andric 268fe013be4SDimitry Andrictemplate<ranges::input_range R, class Allocator = allocator<ranges::range_value_t<R>>> 269fe013be4SDimitry Andric vector(from_range_t, R&&, Allocator = Allocator()) 270fe013be4SDimitry Andric -> vector<ranges::range_value_t<R>, Allocator>; // C++23 271fe013be4SDimitry Andric 2720b57cec5SDimitry Andrictemplate <class Allocator> struct hash<std::vector<bool, Allocator>>; 2730b57cec5SDimitry Andric 274fe013be4SDimitry Andrictemplate <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y); // constexpr since C++20 275fe013be4SDimitry Andrictemplate <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); // removed in C++20 276fe013be4SDimitry Andrictemplate <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y); // removed in C++20 277fe013be4SDimitry Andrictemplate <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y); // removed in C++20 278fe013be4SDimitry Andrictemplate <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); // removed in C++20 279fe013be4SDimitry Andrictemplate <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); // removed in C++20 280fe013be4SDimitry Andrictemplate <class T, class Allocator> constexpr 281fe013be4SDimitry Andric constexpr synth-three-way-result<T> operator<=>(const vector<T, Allocator>& x, 282fe013be4SDimitry Andric const vector<T, Allocator>& y); // since C++20 2830b57cec5SDimitry Andric 2840b57cec5SDimitry Andrictemplate <class T, class Allocator> 2850b57cec5SDimitry Andricvoid swap(vector<T,Allocator>& x, vector<T,Allocator>& y) 2860b57cec5SDimitry Andric noexcept(noexcept(x.swap(y))); 2870b57cec5SDimitry Andric 2880b57cec5SDimitry Andrictemplate <class T, class Allocator, class U> 2895ffd83dbSDimitry Andrictypename vector<T, Allocator>::size_type 290fe013be4SDimitry Andricerase(vector<T, Allocator>& c, const U& value); // since C++20 2910b57cec5SDimitry Andrictemplate <class T, class Allocator, class Predicate> 2925ffd83dbSDimitry Andrictypename vector<T, Allocator>::size_type 293fe013be4SDimitry Andricerase_if(vector<T, Allocator>& c, Predicate pred); // since C++20 2940b57cec5SDimitry Andric 295bdd1243dSDimitry Andric 296bdd1243dSDimitry Andrictemplate<class T> 297bdd1243dSDimitry Andric inline constexpr bool is-vector-bool-reference = see below; // exposition only, since C++23 298bdd1243dSDimitry Andric 299bdd1243dSDimitry Andrictemplate<class T, class charT> requires is-vector-bool-reference<T> // Since C++23 300bdd1243dSDimitry Andric struct formatter<T, charT>; 301bdd1243dSDimitry Andric 3020b57cec5SDimitry Andric} // std 3030b57cec5SDimitry Andric 3040b57cec5SDimitry Andric*/ 3050b57cec5SDimitry Andric 306c9157d92SDimitry Andric// clang-format on 307c9157d92SDimitry Andric 30881ad6265SDimitry Andric#include <__algorithm/copy.h> 30981ad6265SDimitry Andric#include <__algorithm/equal.h> 31081ad6265SDimitry Andric#include <__algorithm/fill_n.h> 311fe013be4SDimitry Andric#include <__algorithm/iterator_operations.h> 31281ad6265SDimitry Andric#include <__algorithm/lexicographical_compare.h> 313fe013be4SDimitry Andric#include <__algorithm/lexicographical_compare_three_way.h> 31481ad6265SDimitry Andric#include <__algorithm/remove.h> 31581ad6265SDimitry Andric#include <__algorithm/remove_if.h> 31681ad6265SDimitry Andric#include <__algorithm/rotate.h> 31781ad6265SDimitry Andric#include <__algorithm/unwrap_iter.h> 31881ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler 319fe013be4SDimitry Andric#include <__availability> 3200b57cec5SDimitry Andric#include <__bit_reference> 321bdd1243dSDimitry Andric#include <__concepts/same_as.h> 32204eeddc0SDimitry Andric#include <__config> 32381ad6265SDimitry Andric#include <__format/enable_insertable.h> 324bdd1243dSDimitry Andric#include <__format/formatter.h> 325fe013be4SDimitry Andric#include <__format/formatter_bool.h> 32681ad6265SDimitry Andric#include <__functional/hash.h> 32781ad6265SDimitry Andric#include <__functional/unary_function.h> 32881ad6265SDimitry Andric#include <__iterator/advance.h> 329fe013be4SDimitry Andric#include <__iterator/distance.h> 330349cc55cSDimitry Andric#include <__iterator/iterator_traits.h> 33181ad6265SDimitry Andric#include <__iterator/reverse_iterator.h> 332fe6060f1SDimitry Andric#include <__iterator/wrap_iter.h> 333fe013be4SDimitry Andric#include <__memory/addressof.h> 33481ad6265SDimitry Andric#include <__memory/allocate_at_least.h> 335fe013be4SDimitry Andric#include <__memory/allocator_traits.h> 336972a253aSDimitry Andric#include <__memory/pointer_traits.h> 337972a253aSDimitry Andric#include <__memory/swap_allocator.h> 338bdd1243dSDimitry Andric#include <__memory/temp_value.h> 339bdd1243dSDimitry Andric#include <__memory/uninitialized_algorithms.h> 340bdd1243dSDimitry Andric#include <__memory_resource/polymorphic_allocator.h> 341fe013be4SDimitry Andric#include <__ranges/access.h> 342fe013be4SDimitry Andric#include <__ranges/concepts.h> 343fe013be4SDimitry Andric#include <__ranges/container_compatible_range.h> 344fe013be4SDimitry Andric#include <__ranges/from_range.h> 345fe013be4SDimitry Andric#include <__ranges/size.h> 346fe6060f1SDimitry Andric#include <__split_buffer> 347bdd1243dSDimitry Andric#include <__type_traits/is_allocator.h> 348fe013be4SDimitry Andric#include <__type_traits/is_constructible.h> 349fe013be4SDimitry Andric#include <__type_traits/is_nothrow_move_assignable.h> 350bdd1243dSDimitry Andric#include <__type_traits/noexcept_move_assign_container.h> 351fe013be4SDimitry Andric#include <__type_traits/type_identity.h> 352bdd1243dSDimitry Andric#include <__utility/exception_guard.h> 353fe6060f1SDimitry Andric#include <__utility/forward.h> 35481ad6265SDimitry Andric#include <__utility/move.h> 355fe013be4SDimitry Andric#include <__utility/pair.h> 35681ad6265SDimitry Andric#include <__utility/swap.h> 3570b57cec5SDimitry Andric#include <climits> 358fe6060f1SDimitry Andric#include <cstring> 359fe6060f1SDimitry Andric#include <iosfwd> // for forward declaration of vector 360fe6060f1SDimitry Andric#include <limits> 3610b57cec5SDimitry Andric#include <stdexcept> 3620b57cec5SDimitry Andric#include <version> 3630b57cec5SDimitry Andric 36481ad6265SDimitry Andric// standard-mandated includes 36581ad6265SDimitry Andric 36681ad6265SDimitry Andric// [iterator.range] 36781ad6265SDimitry Andric#include <__iterator/access.h> 36881ad6265SDimitry Andric#include <__iterator/data.h> 36981ad6265SDimitry Andric#include <__iterator/empty.h> 37081ad6265SDimitry Andric#include <__iterator/reverse_access.h> 37181ad6265SDimitry Andric#include <__iterator/size.h> 37281ad6265SDimitry Andric 37381ad6265SDimitry Andric// [vector.syn] 37481ad6265SDimitry Andric#include <compare> 37581ad6265SDimitry Andric#include <initializer_list> 37681ad6265SDimitry Andric 3770b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 3780b57cec5SDimitry Andric# pragma GCC system_header 3790b57cec5SDimitry Andric#endif 3800b57cec5SDimitry Andric 3810b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS 3820b57cec5SDimitry Andric#include <__undef_macros> 3830b57cec5SDimitry Andric 3840b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 3850b57cec5SDimitry Andric 3860b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator /* = allocator<_Tp> */> 387e710425bSDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector { 3880b57cec5SDimitry Andricprivate: 3890b57cec5SDimitry Andric typedef allocator<_Tp> __default_allocator_type; 390e710425bSDimitry Andric 3910b57cec5SDimitry Andricpublic: 3920b57cec5SDimitry Andric typedef vector __self; 3930b57cec5SDimitry Andric typedef _Tp value_type; 3940b57cec5SDimitry Andric typedef _Allocator allocator_type; 395349cc55cSDimitry Andric typedef allocator_traits<allocator_type> __alloc_traits; 396349cc55cSDimitry Andric typedef value_type& reference; 397349cc55cSDimitry Andric typedef const value_type& const_reference; 3984824e7fdSDimitry Andric typedef typename __alloc_traits::size_type size_type; 399349cc55cSDimitry Andric typedef typename __alloc_traits::difference_type difference_type; 400349cc55cSDimitry Andric typedef typename __alloc_traits::pointer pointer; 401349cc55cSDimitry Andric typedef typename __alloc_traits::const_pointer const_pointer; 402bdd1243dSDimitry Andric // TODO: Implement iterator bounds checking without requiring the global database. 4030b57cec5SDimitry Andric typedef __wrap_iter<pointer> iterator; 4040b57cec5SDimitry Andric typedef __wrap_iter<const_pointer> const_iterator; 405bdd1243dSDimitry Andric typedef std::reverse_iterator<iterator> reverse_iterator; 406bdd1243dSDimitry Andric typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 4070b57cec5SDimitry Andric 4080b57cec5SDimitry Andric static_assert((is_same<typename allocator_type::value_type, value_type>::value), 4090b57cec5SDimitry Andric "Allocator::value_type must be same type as value_type"); 4100b57cec5SDimitry Andric 411bdd1243dSDimitry Andric static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value, 412bdd1243dSDimitry Andric "[allocator.requirements] states that rebinding an allocator to the same type should result in the " 413bdd1243dSDimitry Andric "original allocator"); 414bdd1243dSDimitry Andric 415e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector() 416e710425bSDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) {} 417bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(const allocator_type& __a) 4180b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 4190b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) 4200b57cec5SDimitry Andric#else 4210b57cec5SDimitry Andric _NOEXCEPT 4220b57cec5SDimitry Andric#endif 423e710425bSDimitry Andric : __end_cap_(nullptr, __a) { 4240b57cec5SDimitry Andric } 425bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n); 426fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 14 427bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n, const allocator_type& __a); 4280b57cec5SDimitry Andric#endif 429bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(size_type __n, const value_type& __x); 4304824e7fdSDimitry Andric 4314824e7fdSDimitry Andric template <class = __enable_if_t<__is_allocator<_Allocator>::value> > 432bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 4334824e7fdSDimitry Andric vector(size_type __n, const value_type& __x, const allocator_type& __a) 434e710425bSDimitry Andric : __end_cap_(nullptr, __a) { 435e710425bSDimitry Andric if (__n > 0) { 4364824e7fdSDimitry Andric __vallocate(__n); 4374824e7fdSDimitry Andric __construct_at_end(__n, __x); 4384824e7fdSDimitry Andric } 4394824e7fdSDimitry Andric } 4404824e7fdSDimitry Andric 441bdd1243dSDimitry Andric template <class _InputIterator, 442fe013be4SDimitry Andric __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value && 443bdd1243dSDimitry Andric is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value, 444bdd1243dSDimitry Andric int> = 0> 445bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(_InputIterator __first, _InputIterator __last); 446bdd1243dSDimitry Andric template <class _InputIterator, 447fe013be4SDimitry Andric __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value && 448bdd1243dSDimitry Andric is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value, 449bdd1243dSDimitry Andric int> = 0> 450bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 451bdd1243dSDimitry Andric vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a); 452bdd1243dSDimitry Andric 453bdd1243dSDimitry Andric template < 454bdd1243dSDimitry Andric class _ForwardIterator, 455fe013be4SDimitry Andric __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value && 456bdd1243dSDimitry Andric is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value, 457bdd1243dSDimitry Andric int> = 0> 458bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(_ForwardIterator __first, _ForwardIterator __last); 459bdd1243dSDimitry Andric 460e710425bSDimitry Andric template < 461e710425bSDimitry Andric class _ForwardIterator, 462fe013be4SDimitry Andric __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value && 463bdd1243dSDimitry Andric is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value, 464bdd1243dSDimitry Andric int> = 0> 465bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 466bdd1243dSDimitry Andric vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a); 4670b57cec5SDimitry Andric 468fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 23 469fe013be4SDimitry Andric template <_ContainerCompatibleRange<_Tp> _Range> 470e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr vector( 471e710425bSDimitry Andric from_range_t, _Range&& __range, const allocator_type& __alloc = allocator_type()) 472e710425bSDimitry Andric : __end_cap_(nullptr, __alloc) { 473fe013be4SDimitry Andric if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) { 474fe013be4SDimitry Andric auto __n = static_cast<size_type>(ranges::distance(__range)); 475fe013be4SDimitry Andric __init_with_size(ranges::begin(__range), ranges::end(__range), __n); 476fe013be4SDimitry Andric 477fe013be4SDimitry Andric } else { 478fe013be4SDimitry Andric __init_with_sentinel(ranges::begin(__range), ranges::end(__range)); 479fe013be4SDimitry Andric } 480fe013be4SDimitry Andric } 481fe013be4SDimitry Andric#endif 482fe013be4SDimitry Andric 48350d7464cSDimitry Andricprivate: 48450d7464cSDimitry Andric class __destroy_vector { 48550d7464cSDimitry Andric public: 486fe013be4SDimitry Andric _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI __destroy_vector(vector& __vec) : __vec_(__vec) {} 487349cc55cSDimitry Andric 488bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() { 48950d7464cSDimitry Andric if (__vec_.__begin_ != nullptr) { 49050d7464cSDimitry Andric __vec_.__clear(); 491fe013be4SDimitry Andric __vec_.__annotate_delete(); 49250d7464cSDimitry Andric __alloc_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.capacity()); 493349cc55cSDimitry Andric } 4940b57cec5SDimitry Andric } 4950b57cec5SDimitry Andric 49650d7464cSDimitry Andric private: 49750d7464cSDimitry Andric vector& __vec_; 49850d7464cSDimitry Andric }; 49950d7464cSDimitry Andric 50050d7464cSDimitry Andricpublic: 501bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~vector() { __destroy_vector (*this)(); } 50250d7464cSDimitry Andric 503bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(const vector& __x); 504bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 505e710425bSDimitry Andric vector(const vector& __x, const __type_identity_t<allocator_type>& __a); 506e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector& operator=(const vector& __x); 5070b57cec5SDimitry Andric 5080b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 509e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(initializer_list<value_type> __il); 5100b57cec5SDimitry Andric 511bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 5120b57cec5SDimitry Andric vector(initializer_list<value_type> __il, const allocator_type& __a); 5130b57cec5SDimitry Andric 514e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector& operator=(initializer_list<value_type> __il) { 515e710425bSDimitry Andric assign(__il.begin(), __il.end()); 516e710425bSDimitry Andric return *this; 517e710425bSDimitry Andric } 51881ad6265SDimitry Andric#endif // !_LIBCPP_CXX03_LANG 51981ad6265SDimitry Andric 520e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(vector&& __x) 521fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 17 52281ad6265SDimitry Andric noexcept; 5230b57cec5SDimitry Andric#else 5240b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); 5250b57cec5SDimitry Andric#endif 5260b57cec5SDimitry Andric 527bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 52881ad6265SDimitry Andric vector(vector&& __x, const __type_identity_t<allocator_type>& __a); 529e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector& operator=(vector&& __x) 5300b57cec5SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); 5310b57cec5SDimitry Andric 532bdd1243dSDimitry Andric template <class _InputIterator, 533fe013be4SDimitry Andric __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value && 534bdd1243dSDimitry Andric is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value, 535bdd1243dSDimitry Andric int> = 0> 536bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(_InputIterator __first, _InputIterator __last); 537bdd1243dSDimitry Andric template < 538bdd1243dSDimitry Andric class _ForwardIterator, 539fe013be4SDimitry Andric __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value && 540bdd1243dSDimitry Andric is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value, 541bdd1243dSDimitry Andric int> = 0> 542bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(_ForwardIterator __first, _ForwardIterator __last); 5430b57cec5SDimitry Andric 544fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 23 545fe013be4SDimitry Andric template <_ContainerCompatibleRange<_Tp> _Range> 546e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr void assign_range(_Range&& __range) { 547fe013be4SDimitry Andric if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) { 548fe013be4SDimitry Andric auto __n = static_cast<size_type>(ranges::distance(__range)); 549fe013be4SDimitry Andric __assign_with_size(ranges::begin(__range), ranges::end(__range), __n); 550fe013be4SDimitry Andric 551fe013be4SDimitry Andric } else { 552fe013be4SDimitry Andric __assign_with_sentinel(ranges::begin(__range), ranges::end(__range)); 553fe013be4SDimitry Andric } 554fe013be4SDimitry Andric } 555fe013be4SDimitry Andric#endif 556fe013be4SDimitry Andric 557bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const_reference __u); 5580b57cec5SDimitry Andric 5590b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 560e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(initializer_list<value_type> __il) { 561e710425bSDimitry Andric assign(__il.begin(), __il.end()); 562e710425bSDimitry Andric } 5630b57cec5SDimitry Andric#endif 5640b57cec5SDimitry Andric 565e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT { 566e710425bSDimitry Andric return this->__alloc(); 567e710425bSDimitry Andric } 5680b57cec5SDimitry Andric 569bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT; 570bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT; 571bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT; 572bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT; 5730b57cec5SDimitry Andric 574e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT { 575e710425bSDimitry Andric return reverse_iterator(end()); 576e710425bSDimitry Andric } 577e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT { 578e710425bSDimitry Andric return const_reverse_iterator(end()); 579e710425bSDimitry Andric } 580e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() _NOEXCEPT { 581e710425bSDimitry Andric return reverse_iterator(begin()); 582e710425bSDimitry Andric } 583e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT { 584e710425bSDimitry Andric return const_reverse_iterator(begin()); 585e710425bSDimitry Andric } 5860b57cec5SDimitry Andric 587e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return begin(); } 588e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return end(); } 589e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT { 590e710425bSDimitry Andric return rbegin(); 591e710425bSDimitry Andric } 592e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return rend(); } 5930b57cec5SDimitry Andric 594e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { 595e710425bSDimitry Andric return static_cast<size_type>(this->__end_ - this->__begin_); 596e710425bSDimitry Andric } 597e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type capacity() const _NOEXCEPT { 598e710425bSDimitry Andric return static_cast<size_type>(__end_cap() - this->__begin_); 599e710425bSDimitry Andric } 600e710425bSDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { 601e710425bSDimitry Andric return this->__begin_ == this->__end_; 602e710425bSDimitry Andric } 603bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT; 604bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void reserve(size_type __n); 605bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void shrink_to_fit() _NOEXCEPT; 6060b57cec5SDimitry Andric 607bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference operator[](size_type __n) _NOEXCEPT; 608bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference operator[](size_type __n) const _NOEXCEPT; 609bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference at(size_type __n); 610bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __n) const; 6110b57cec5SDimitry Andric 612e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference front() _NOEXCEPT { 613fe013be4SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "front() called on an empty vector"); 6140b57cec5SDimitry Andric return *this->__begin_; 6150b57cec5SDimitry Andric } 616e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference front() const _NOEXCEPT { 617fe013be4SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "front() called on an empty vector"); 6180b57cec5SDimitry Andric return *this->__begin_; 6190b57cec5SDimitry Andric } 620e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference back() _NOEXCEPT { 621fe013be4SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "back() called on an empty vector"); 6220b57cec5SDimitry Andric return *(this->__end_ - 1); 6230b57cec5SDimitry Andric } 624e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference back() const _NOEXCEPT { 625fe013be4SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "back() called on an empty vector"); 6260b57cec5SDimitry Andric return *(this->__end_ - 1); 6270b57cec5SDimitry Andric } 6280b57cec5SDimitry Andric 629e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI value_type* data() _NOEXCEPT { 630e710425bSDimitry Andric return std::__to_address(this->__begin_); 631e710425bSDimitry Andric } 63261cfbce3SDimitry Andric 633e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const value_type* data() const _NOEXCEPT { 634e710425bSDimitry Andric return std::__to_address(this->__begin_); 635e710425bSDimitry Andric } 6360b57cec5SDimitry Andric 637bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_back(const_reference __x); 6380b57cec5SDimitry Andric 639bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __x); 6400b57cec5SDimitry Andric 6410b57cec5SDimitry Andric template <class... _Args> 642bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 643fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 17 644e710425bSDimitry Andric reference 645e710425bSDimitry Andric emplace_back(_Args&&... __args); 6460b57cec5SDimitry Andric#else 647e710425bSDimitry Andric void 648e710425bSDimitry Andric emplace_back(_Args&&... __args); 6490b57cec5SDimitry Andric#endif 6500b57cec5SDimitry Andric 651fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 23 652fe013be4SDimitry Andric template <_ContainerCompatibleRange<_Tp> _Range> 653e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr void append_range(_Range&& __range) { 654fe013be4SDimitry Andric insert_range(end(), std::forward<_Range>(__range)); 655fe013be4SDimitry Andric } 656fe013be4SDimitry Andric#endif 657fe013be4SDimitry Andric 658e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void pop_back(); 6590b57cec5SDimitry Andric 660bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, const_reference __x); 6610b57cec5SDimitry Andric 662bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, value_type&& __x); 6630b57cec5SDimitry Andric template <class... _Args> 664bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __position, _Args&&... __args); 6650b57cec5SDimitry Andric 666e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator 667e710425bSDimitry Andric insert(const_iterator __position, size_type __n, const_reference __x); 668bdd1243dSDimitry Andric 669bdd1243dSDimitry Andric template <class _InputIterator, 670fe013be4SDimitry Andric __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value && 671bdd1243dSDimitry Andric is_constructible< value_type, typename iterator_traits<_InputIterator>::reference>::value, 672bdd1243dSDimitry Andric int> = 0> 673bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator 6740b57cec5SDimitry Andric insert(const_iterator __position, _InputIterator __first, _InputIterator __last); 675bdd1243dSDimitry Andric 676fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 23 677fe013be4SDimitry Andric template <_ContainerCompatibleRange<_Tp> _Range> 678e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr iterator insert_range(const_iterator __position, _Range&& __range) { 679fe013be4SDimitry Andric if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) { 680fe013be4SDimitry Andric auto __n = static_cast<size_type>(ranges::distance(__range)); 681fe013be4SDimitry Andric return __insert_with_size(__position, ranges::begin(__range), ranges::end(__range), __n); 682fe013be4SDimitry Andric 683fe013be4SDimitry Andric } else { 684fe013be4SDimitry Andric return __insert_with_sentinel(__position, ranges::begin(__range), ranges::end(__range)); 685fe013be4SDimitry Andric } 686fe013be4SDimitry Andric } 687fe013be4SDimitry Andric#endif 688fe013be4SDimitry Andric 689bdd1243dSDimitry Andric template < 690bdd1243dSDimitry Andric class _ForwardIterator, 691fe013be4SDimitry Andric __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value && 692bdd1243dSDimitry Andric is_constructible< value_type, typename iterator_traits<_ForwardIterator>::reference>::value, 693bdd1243dSDimitry Andric int> = 0> 694bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator 6950b57cec5SDimitry Andric insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); 6960b57cec5SDimitry Andric 6970b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 698e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator 699e710425bSDimitry Andric insert(const_iterator __position, initializer_list<value_type> __il) { 700e710425bSDimitry Andric return insert(__position, __il.begin(), __il.end()); 701e710425bSDimitry Andric } 7020b57cec5SDimitry Andric#endif 7030b57cec5SDimitry Andric 704bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __position); 705bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last); 7060b57cec5SDimitry Andric 707e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { 7080b57cec5SDimitry Andric size_type __old_size = size(); 709349cc55cSDimitry Andric __clear(); 7100b57cec5SDimitry Andric __annotate_shrink(__old_size); 7110b57cec5SDimitry Andric } 7120b57cec5SDimitry Andric 713bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz); 714bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz, const_reference __x); 7150b57cec5SDimitry Andric 716bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void swap(vector&) 7170b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 7180b57cec5SDimitry Andric _NOEXCEPT; 7190b57cec5SDimitry Andric#else 720e710425bSDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value); 7210b57cec5SDimitry Andric#endif 7220b57cec5SDimitry Andric 723bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool __invariants() const; 7240b57cec5SDimitry Andric 7250b57cec5SDimitry Andricprivate: 726d56accc7SDimitry Andric pointer __begin_ = nullptr; 727d56accc7SDimitry Andric pointer __end_ = nullptr; 728d56accc7SDimitry Andric __compressed_pair<pointer, allocator_type> __end_cap_ = 729d56accc7SDimitry Andric __compressed_pair<pointer, allocator_type>(nullptr, __default_init_tag()); 730d56accc7SDimitry Andric 73181ad6265SDimitry Andric // Allocate space for __n objects 73281ad6265SDimitry Andric // throws length_error if __n > max_size() 73381ad6265SDimitry Andric // throws (probably bad_alloc) if memory run out 73481ad6265SDimitry Andric // Precondition: __begin_ == __end_ == __end_cap() == 0 73581ad6265SDimitry Andric // Precondition: __n > 0 73681ad6265SDimitry Andric // Postcondition: capacity() >= __n 73781ad6265SDimitry Andric // Postcondition: size() == 0 738bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) { 73981ad6265SDimitry Andric if (__n > max_size()) 74081ad6265SDimitry Andric __throw_length_error(); 74181ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __n); 74281ad6265SDimitry Andric __begin_ = __allocation.ptr; 74381ad6265SDimitry Andric __end_ = __allocation.ptr; 74481ad6265SDimitry Andric __end_cap() = __begin_ + __allocation.count; 74581ad6265SDimitry Andric __annotate_new(0); 74681ad6265SDimitry Andric } 74781ad6265SDimitry Andric 748bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __vdeallocate() _NOEXCEPT; 749bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type __recommend(size_type __new_size) const; 750bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_at_end(size_type __n); 751e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_at_end(size_type __n, const_reference __x); 752bdd1243dSDimitry Andric 753fe013be4SDimitry Andric template <class _InputIterator, class _Sentinel> 754e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void 755e710425bSDimitry Andric __init_with_size(_InputIterator __first, _Sentinel __last, size_type __n) { 756fe013be4SDimitry Andric auto __guard = std::__make_exception_guard(__destroy_vector(*this)); 757fe013be4SDimitry Andric 758fe013be4SDimitry Andric if (__n > 0) { 759fe013be4SDimitry Andric __vallocate(__n); 760fe013be4SDimitry Andric __construct_at_end(__first, __last, __n); 761fe013be4SDimitry Andric } 762fe013be4SDimitry Andric 763fe013be4SDimitry Andric __guard.__complete(); 764fe013be4SDimitry Andric } 765fe013be4SDimitry Andric 766fe013be4SDimitry Andric template <class _InputIterator, class _Sentinel> 767e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void 768e710425bSDimitry Andric __init_with_sentinel(_InputIterator __first, _Sentinel __last) { 769fe013be4SDimitry Andric auto __guard = std::__make_exception_guard(__destroy_vector(*this)); 770fe013be4SDimitry Andric 771fe013be4SDimitry Andric for (; __first != __last; ++__first) 772fe013be4SDimitry Andric emplace_back(*__first); 773fe013be4SDimitry Andric 774fe013be4SDimitry Andric __guard.__complete(); 775fe013be4SDimitry Andric } 776fe013be4SDimitry Andric 777fe013be4SDimitry Andric template <class _Iterator, class _Sentinel> 778e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __assign_with_sentinel(_Iterator __first, _Sentinel __last); 779fe013be4SDimitry Andric 780fe013be4SDimitry Andric template <class _ForwardIterator, class _Sentinel> 781e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void 782e710425bSDimitry Andric __assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __n); 783fe013be4SDimitry Andric 784fe013be4SDimitry Andric template <class _InputIterator, class _Sentinel> 785e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator 786e710425bSDimitry Andric __insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last); 787fe013be4SDimitry Andric 788fe013be4SDimitry Andric template <class _Iterator, class _Sentinel> 789e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator 790e710425bSDimitry Andric __insert_with_size(const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n); 791fe013be4SDimitry Andric 792fe013be4SDimitry Andric template <class _InputIterator, class _Sentinel> 793e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void 794e710425bSDimitry Andric __construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n); 795bdd1243dSDimitry Andric 796bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __append(size_type __n); 797bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __append(size_type __n, const_reference __x); 798e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator __make_iter(pointer __p) _NOEXCEPT { 799e710425bSDimitry Andric return iterator(__p); 800e710425bSDimitry Andric } 801e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator __make_iter(const_pointer __p) const _NOEXCEPT { 802e710425bSDimitry Andric return const_iterator(__p); 803e710425bSDimitry Andric } 804e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void 805e710425bSDimitry Andric __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v); 806e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer 807e710425bSDimitry Andric __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p); 808e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void 809e710425bSDimitry Andric __move_range(pointer __from_s, pointer __from_e, pointer __to); 810bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, true_type) 8110b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); 812bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, false_type) 8130b57cec5SDimitry Andric _NOEXCEPT_(__alloc_traits::is_always_equal::value); 814e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __destruct_at_end(pointer __new_last) _NOEXCEPT { 8150b57cec5SDimitry Andric size_type __old_size = size(); 816349cc55cSDimitry Andric __base_destruct_at_end(__new_last); 8170b57cec5SDimitry Andric __annotate_shrink(__old_size); 8180b57cec5SDimitry Andric } 8190b57cec5SDimitry Andric 8200b57cec5SDimitry Andric template <class _Up> 821e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI inline pointer __push_back_slow_path(_Up&& __x); 8220b57cec5SDimitry Andric 8230b57cec5SDimitry Andric template <class... _Args> 824e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI inline pointer __emplace_back_slow_path(_Args&&... __args); 8250b57cec5SDimitry Andric 8260b57cec5SDimitry Andric // The following functions are no-ops outside of AddressSanitizer mode. 827fe013be4SDimitry Andric // We call annotations for every allocator, unless explicitly disabled. 828fe013be4SDimitry Andric // 829fe013be4SDimitry Andric // To disable annotations for a particular allocator, change value of 830fe013be4SDimitry Andric // __asan_annotate_container_with_allocator to false. 831fe013be4SDimitry Andric // For more details, see the "Using libc++" documentation page or 832fe013be4SDimitry Andric // the documentation for __sanitizer_annotate_contiguous_container. 833c9157d92SDimitry Andric 834e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_contiguous_container( 835*a58f00eaSDimitry Andric const void* __old_mid, const void* __new_mid) const { 836c9157d92SDimitry Andric (void)__old_mid; 837c9157d92SDimitry Andric (void)__new_mid; 838c9157d92SDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN 839*a58f00eaSDimitry Andric const void* __beg = data(); 840*a58f00eaSDimitry Andric const void* __end = data() + capacity(); 841e710425bSDimitry Andric if (!__libcpp_is_constant_evaluated() && __beg != nullptr && 842e710425bSDimitry Andric __asan_annotate_container_with_allocator<_Allocator>::value) 8430b57cec5SDimitry Andric __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid); 8440b57cec5SDimitry Andric#endif 845c9157d92SDimitry Andric } 846c9157d92SDimitry Andric 847e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_new(size_type __current_size) const _NOEXCEPT { 848e710425bSDimitry Andric (void)__current_size; 849e710425bSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN 850*a58f00eaSDimitry Andric __annotate_contiguous_container(data() + capacity(), data() + __current_size); 851e710425bSDimitry Andric#endif 8520b57cec5SDimitry Andric } 8530b57cec5SDimitry Andric 854e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_delete() const _NOEXCEPT { 855e710425bSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN 856*a58f00eaSDimitry Andric __annotate_contiguous_container(data() + size(), data() + capacity()); 857e710425bSDimitry Andric#endif 8580b57cec5SDimitry Andric } 8590b57cec5SDimitry Andric 860e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_increase(size_type __n) const _NOEXCEPT { 861e710425bSDimitry Andric (void)__n; 862e710425bSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN 863*a58f00eaSDimitry Andric __annotate_contiguous_container(data() + size(), data() + size() + __n); 864e710425bSDimitry Andric#endif 8650b57cec5SDimitry Andric } 8660b57cec5SDimitry Andric 867e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_shrink(size_type __old_size) const _NOEXCEPT { 868e710425bSDimitry Andric (void)__old_size; 869e710425bSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN 870*a58f00eaSDimitry Andric __annotate_contiguous_container(data() + __old_size, data() + size()); 871e710425bSDimitry Andric#endif 8720b57cec5SDimitry Andric } 8730b57cec5SDimitry Andric 874e40139ffSDimitry Andric struct _ConstructTransaction { 875e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit _ConstructTransaction(vector& __v, size_type __n) 876e40139ffSDimitry Andric : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) { 877e40139ffSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN 878e40139ffSDimitry Andric __v_.__annotate_increase(__n); 879e40139ffSDimitry Andric#endif 880e40139ffSDimitry Andric } 881bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~_ConstructTransaction() { 882e40139ffSDimitry Andric __v_.__end_ = __pos_; 883e40139ffSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN 884e40139ffSDimitry Andric if (__pos_ != __new_end_) { 885e40139ffSDimitry Andric __v_.__annotate_shrink(__new_end_ - __v_.__begin_); 886e40139ffSDimitry Andric } 887e40139ffSDimitry Andric#endif 888e40139ffSDimitry Andric } 889e40139ffSDimitry Andric 890e40139ffSDimitry Andric vector& __v_; 891e40139ffSDimitry Andric pointer __pos_; 892e40139ffSDimitry Andric const_pointer const __new_end_; 893e40139ffSDimitry Andric 894e40139ffSDimitry Andric private: 895e40139ffSDimitry Andric _ConstructTransaction(_ConstructTransaction const&) = delete; 896e40139ffSDimitry Andric _ConstructTransaction& operator=(_ConstructTransaction const&) = delete; 897e40139ffSDimitry Andric }; 898e40139ffSDimitry Andric 899e40139ffSDimitry Andric template <class... _Args> 900e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_one_at_end(_Args&&... __args) { 901e40139ffSDimitry Andric _ConstructTransaction __tx(*this, 1); 902e710425bSDimitry Andric __alloc_traits::construct(this->__alloc(), std::__to_address(__tx.__pos_), std::forward<_Args>(__args)...); 903e40139ffSDimitry Andric ++__tx.__pos_; 904e40139ffSDimitry Andric } 905349cc55cSDimitry Andric 906e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI allocator_type& __alloc() _NOEXCEPT { 907e710425bSDimitry Andric return this->__end_cap_.second(); 908e710425bSDimitry Andric } 909e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const allocator_type& __alloc() const _NOEXCEPT { 910e710425bSDimitry Andric return this->__end_cap_.second(); 911e710425bSDimitry Andric } 912e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer& __end_cap() _NOEXCEPT { 913e710425bSDimitry Andric return this->__end_cap_.first(); 914e710425bSDimitry Andric } 915e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const pointer& __end_cap() const _NOEXCEPT { 916e710425bSDimitry Andric return this->__end_cap_.first(); 917e710425bSDimitry Andric } 918349cc55cSDimitry Andric 919e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __clear() _NOEXCEPT { 920e710425bSDimitry Andric __base_destruct_at_end(this->__begin_); 921e710425bSDimitry Andric } 922349cc55cSDimitry Andric 923e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __base_destruct_at_end(pointer __new_last) _NOEXCEPT { 924349cc55cSDimitry Andric pointer __soon_to_be_end = this->__end_; 925349cc55cSDimitry Andric while (__new_last != __soon_to_be_end) 926bdd1243dSDimitry Andric __alloc_traits::destroy(__alloc(), std::__to_address(--__soon_to_be_end)); 927349cc55cSDimitry Andric this->__end_ = __new_last; 928349cc55cSDimitry Andric } 929349cc55cSDimitry Andric 930e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const vector& __c) { 931e710425bSDimitry Andric __copy_assign_alloc(__c, integral_constant<bool, __alloc_traits::propagate_on_container_copy_assignment::value>()); 932349cc55cSDimitry Andric } 933349cc55cSDimitry Andric 934e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector& __c) 935e710425bSDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_move_assignment::value || 936e710425bSDimitry Andric is_nothrow_move_assignable<allocator_type>::value) { 937e710425bSDimitry Andric __move_assign_alloc(__c, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>()); 938349cc55cSDimitry Andric } 939349cc55cSDimitry Andric 940e710425bSDimitry Andric _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_length_error() const { std::__throw_length_error("vector"); } 941e710425bSDimitry Andric 942e710425bSDimitry Andric _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range() const { std::__throw_out_of_range("vector"); } 943e710425bSDimitry Andric 944e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const vector& __c, true_type) { 945e710425bSDimitry Andric if (__alloc() != __c.__alloc()) { 946349cc55cSDimitry Andric __clear(); 947fe013be4SDimitry Andric __annotate_delete(); 948349cc55cSDimitry Andric __alloc_traits::deallocate(__alloc(), this->__begin_, capacity()); 949349cc55cSDimitry Andric this->__begin_ = this->__end_ = __end_cap() = nullptr; 950349cc55cSDimitry Andric } 951349cc55cSDimitry Andric __alloc() = __c.__alloc(); 952349cc55cSDimitry Andric } 953349cc55cSDimitry Andric 954e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const vector&, false_type) {} 955349cc55cSDimitry Andric 956e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector& __c, true_type) 957e710425bSDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) { 958bdd1243dSDimitry Andric __alloc() = std::move(__c.__alloc()); 959349cc55cSDimitry Andric } 960349cc55cSDimitry Andric 961e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector&, false_type) _NOEXCEPT {} 9620b57cec5SDimitry Andric}; 9630b57cec5SDimitry Andric 964349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17 9650b57cec5SDimitry Andrictemplate <class _InputIterator, 966fe6060f1SDimitry Andric class _Alloc = allocator<__iter_value_type<_InputIterator>>, 967fe013be4SDimitry Andric class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>, 968e710425bSDimitry Andric class = enable_if_t<__is_allocator<_Alloc>::value> > 969e710425bSDimitry Andricvector(_InputIterator, _InputIterator) -> vector<__iter_value_type<_InputIterator>, _Alloc>; 9700b57cec5SDimitry Andric 9710b57cec5SDimitry Andrictemplate <class _InputIterator, 9720b57cec5SDimitry Andric class _Alloc, 973fe013be4SDimitry Andric class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>, 974e710425bSDimitry Andric class = enable_if_t<__is_allocator<_Alloc>::value> > 975e710425bSDimitry Andricvector(_InputIterator, _InputIterator, _Alloc) -> vector<__iter_value_type<_InputIterator>, _Alloc>; 9760b57cec5SDimitry Andric#endif 9770b57cec5SDimitry Andric 978fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 23 979fe013be4SDimitry Andrictemplate <ranges::input_range _Range, 980fe013be4SDimitry Andric class _Alloc = allocator<ranges::range_value_t<_Range>>, 981e710425bSDimitry Andric class = enable_if_t<__is_allocator<_Alloc>::value> > 982e710425bSDimitry Andricvector(from_range_t, _Range&&, _Alloc = _Alloc()) -> vector<ranges::range_value_t<_Range>, _Alloc>; 983fe013be4SDimitry Andric#endif 984fe013be4SDimitry Andric 9850b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 986e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void 987e710425bSDimitry Andricvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v) { 9880b57cec5SDimitry Andric __annotate_delete(); 989972a253aSDimitry Andric using _RevIter = std::reverse_iterator<pointer>; 990972a253aSDimitry Andric __v.__begin_ = std::__uninitialized_allocator_move_if_noexcept( 991972a253aSDimitry Andric __alloc(), _RevIter(__end_), _RevIter(__begin_), _RevIter(__v.__begin_)) 992972a253aSDimitry Andric .base(); 993bdd1243dSDimitry Andric std::swap(this->__begin_, __v.__begin_); 994bdd1243dSDimitry Andric std::swap(this->__end_, __v.__end_); 995bdd1243dSDimitry Andric std::swap(this->__end_cap(), __v.__end_cap()); 9960b57cec5SDimitry Andric __v.__first_ = __v.__begin_; 9970b57cec5SDimitry Andric __annotate_new(size()); 9980b57cec5SDimitry Andric} 9990b57cec5SDimitry Andric 10000b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1001e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::pointer 1002e710425bSDimitry Andricvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p) { 10030b57cec5SDimitry Andric __annotate_delete(); 10040b57cec5SDimitry Andric pointer __r = __v.__begin_; 1005972a253aSDimitry Andric using _RevIter = std::reverse_iterator<pointer>; 1006972a253aSDimitry Andric __v.__begin_ = std::__uninitialized_allocator_move_if_noexcept( 1007972a253aSDimitry Andric __alloc(), _RevIter(__p), _RevIter(__begin_), _RevIter(__v.__begin_)) 1008972a253aSDimitry Andric .base(); 1009972a253aSDimitry Andric __v.__end_ = std::__uninitialized_allocator_move_if_noexcept(__alloc(), __p, __end_, __v.__end_); 1010bdd1243dSDimitry Andric std::swap(this->__begin_, __v.__begin_); 1011bdd1243dSDimitry Andric std::swap(this->__end_, __v.__end_); 1012bdd1243dSDimitry Andric std::swap(this->__end_cap(), __v.__end_cap()); 10130b57cec5SDimitry Andric __v.__first_ = __v.__begin_; 10140b57cec5SDimitry Andric __annotate_new(size()); 10150b57cec5SDimitry Andric return __r; 10160b57cec5SDimitry Andric} 10170b57cec5SDimitry Andric 10180b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1019e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT { 1020e710425bSDimitry Andric if (this->__begin_ != nullptr) { 10210b57cec5SDimitry Andric clear(); 1022fe013be4SDimitry Andric __annotate_delete(); 10230b57cec5SDimitry Andric __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity()); 10240b57cec5SDimitry Andric this->__begin_ = this->__end_ = this->__end_cap() = nullptr; 10250b57cec5SDimitry Andric } 10260b57cec5SDimitry Andric} 10270b57cec5SDimitry Andric 10280b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1029e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::size_type 1030e710425bSDimitry Andricvector<_Tp, _Allocator>::max_size() const _NOEXCEPT { 1031e710425bSDimitry Andric return std::min<size_type>(__alloc_traits::max_size(this->__alloc()), numeric_limits<difference_type>::max()); 10320b57cec5SDimitry Andric} 10330b57cec5SDimitry Andric 10340b57cec5SDimitry Andric// Precondition: __new_size > capacity() 10350b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1036e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type 1037e710425bSDimitry Andricvector<_Tp, _Allocator>::__recommend(size_type __new_size) const { 10380b57cec5SDimitry Andric const size_type __ms = max_size(); 10390b57cec5SDimitry Andric if (__new_size > __ms) 10400b57cec5SDimitry Andric this->__throw_length_error(); 10410b57cec5SDimitry Andric const size_type __cap = capacity(); 10420b57cec5SDimitry Andric if (__cap >= __ms / 2) 10430b57cec5SDimitry Andric return __ms; 1044bdd1243dSDimitry Andric return std::max<size_type>(2 * __cap, __new_size); 10450b57cec5SDimitry Andric} 10460b57cec5SDimitry Andric 10470b57cec5SDimitry Andric// Default constructs __n objects starting at __end_ 10480b57cec5SDimitry Andric// throws if construction throws 10490b57cec5SDimitry Andric// Precondition: __n > 0 10500b57cec5SDimitry Andric// Precondition: size() + __n <= capacity() 10510b57cec5SDimitry Andric// Postcondition: size() == size() + __n 10520b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1053e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__construct_at_end(size_type __n) { 1054e40139ffSDimitry Andric _ConstructTransaction __tx(*this, __n); 10555ffd83dbSDimitry Andric const_pointer __new_end = __tx.__new_end_; 1056349cc55cSDimitry Andric for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) { 1057bdd1243dSDimitry Andric __alloc_traits::construct(this->__alloc(), std::__to_address(__pos)); 1058e40139ffSDimitry Andric } 10590b57cec5SDimitry Andric} 10600b57cec5SDimitry Andric 10610b57cec5SDimitry Andric// Copy constructs __n objects starting at __end_ from __x 10620b57cec5SDimitry Andric// throws if construction throws 10630b57cec5SDimitry Andric// Precondition: __n > 0 10640b57cec5SDimitry Andric// Precondition: size() + __n <= capacity() 10650b57cec5SDimitry Andric// Postcondition: size() == old size() + __n 10660b57cec5SDimitry Andric// Postcondition: [i] == __x for all i in [size() - __n, __n) 10670b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1068e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline void 1069e710425bSDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) { 1070e40139ffSDimitry Andric _ConstructTransaction __tx(*this, __n); 10715ffd83dbSDimitry Andric const_pointer __new_end = __tx.__new_end_; 1072349cc55cSDimitry Andric for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) { 1073bdd1243dSDimitry Andric __alloc_traits::construct(this->__alloc(), std::__to_address(__pos), __x); 1074e40139ffSDimitry Andric } 10750b57cec5SDimitry Andric} 10760b57cec5SDimitry Andric 10770b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1078fe013be4SDimitry Andrictemplate <class _InputIterator, class _Sentinel> 1079bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void 1080fe013be4SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) { 1081e40139ffSDimitry Andric _ConstructTransaction __tx(*this, __n); 1082972a253aSDimitry Andric __tx.__pos_ = std::__uninitialized_allocator_copy(__alloc(), __first, __last, __tx.__pos_); 10830b57cec5SDimitry Andric} 10840b57cec5SDimitry Andric 10850b57cec5SDimitry Andric// Default constructs __n objects starting at __end_ 10860b57cec5SDimitry Andric// throws if construction throws 10870b57cec5SDimitry Andric// Postcondition: size() == size() + __n 10880b57cec5SDimitry Andric// Exception safety: strong. 10890b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1090e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__append(size_type __n) { 10910b57cec5SDimitry Andric if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) 10920b57cec5SDimitry Andric this->__construct_at_end(__n); 1093e710425bSDimitry Andric else { 10940b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 10950b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); 10960b57cec5SDimitry Andric __v.__construct_at_end(__n); 10970b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 10980b57cec5SDimitry Andric } 10990b57cec5SDimitry Andric} 11000b57cec5SDimitry Andric 11010b57cec5SDimitry Andric// Default constructs __n objects starting at __end_ 11020b57cec5SDimitry Andric// throws if construction throws 11030b57cec5SDimitry Andric// Postcondition: size() == size() + __n 11040b57cec5SDimitry Andric// Exception safety: strong. 11050b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1106e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x) { 11070b57cec5SDimitry Andric if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) 11080b57cec5SDimitry Andric this->__construct_at_end(__n, __x); 1109e710425bSDimitry Andric else { 11100b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 11110b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); 11120b57cec5SDimitry Andric __v.__construct_at_end(__n, __x); 11130b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 11140b57cec5SDimitry Andric } 11150b57cec5SDimitry Andric} 11160b57cec5SDimitry Andric 11170b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1118e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n) { 1119bdd1243dSDimitry Andric auto __guard = std::__make_exception_guard(__destroy_vector(*this)); 1120e710425bSDimitry Andric if (__n > 0) { 11210b57cec5SDimitry Andric __vallocate(__n); 11220b57cec5SDimitry Andric __construct_at_end(__n); 11230b57cec5SDimitry Andric } 112450d7464cSDimitry Andric __guard.__complete(); 11250b57cec5SDimitry Andric} 11260b57cec5SDimitry Andric 1127fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 14 11280b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1129e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a) 1130e710425bSDimitry Andric : __end_cap_(nullptr, __a) { 1131bdd1243dSDimitry Andric auto __guard = std::__make_exception_guard(__destroy_vector(*this)); 1132e710425bSDimitry Andric if (__n > 0) { 11330b57cec5SDimitry Andric __vallocate(__n); 11340b57cec5SDimitry Andric __construct_at_end(__n); 11350b57cec5SDimitry Andric } 113650d7464cSDimitry Andric __guard.__complete(); 11370b57cec5SDimitry Andric} 11380b57cec5SDimitry Andric#endif 11390b57cec5SDimitry Andric 11400b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1141e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x) { 1142bdd1243dSDimitry Andric auto __guard = std::__make_exception_guard(__destroy_vector(*this)); 1143e710425bSDimitry Andric if (__n > 0) { 11440b57cec5SDimitry Andric __vallocate(__n); 11450b57cec5SDimitry Andric __construct_at_end(__n, __x); 11460b57cec5SDimitry Andric } 114750d7464cSDimitry Andric __guard.__complete(); 11480b57cec5SDimitry Andric} 11490b57cec5SDimitry Andric 11500b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1151e710425bSDimitry Andrictemplate <class _InputIterator, 1152e710425bSDimitry Andric __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value && 1153bdd1243dSDimitry Andric is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value, 1154bdd1243dSDimitry Andric int> > 1155e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last) { 1156fe013be4SDimitry Andric __init_with_sentinel(__first, __last); 11570b57cec5SDimitry Andric} 11580b57cec5SDimitry Andric 11590b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1160e710425bSDimitry Andrictemplate <class _InputIterator, 1161e710425bSDimitry Andric __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value && 1162bdd1243dSDimitry Andric is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value, 1163bdd1243dSDimitry Andric int> > 1164bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1165bdd1243dSDimitry Andricvector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a) 1166e710425bSDimitry Andric : __end_cap_(nullptr, __a) { 1167fe013be4SDimitry Andric __init_with_sentinel(__first, __last); 11680b57cec5SDimitry Andric} 11690b57cec5SDimitry Andric 11700b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1171e710425bSDimitry Andrictemplate <class _ForwardIterator, 1172e710425bSDimitry Andric __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value && 1173bdd1243dSDimitry Andric is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value, 1174bdd1243dSDimitry Andric int> > 1175e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last) { 117650d7464cSDimitry Andric size_type __n = static_cast<size_type>(std::distance(__first, __last)); 1177fe013be4SDimitry Andric __init_with_size(__first, __last, __n); 11780b57cec5SDimitry Andric} 11790b57cec5SDimitry Andric 11800b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1181e710425bSDimitry Andrictemplate <class _ForwardIterator, 1182e710425bSDimitry Andric __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value && 1183bdd1243dSDimitry Andric is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value, 1184bdd1243dSDimitry Andric int> > 1185bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1186bdd1243dSDimitry Andricvector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a) 1187e710425bSDimitry Andric : __end_cap_(nullptr, __a) { 118850d7464cSDimitry Andric size_type __n = static_cast<size_type>(std::distance(__first, __last)); 1189fe013be4SDimitry Andric __init_with_size(__first, __last, __n); 11900b57cec5SDimitry Andric} 11910b57cec5SDimitry Andric 11920b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1193e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(const vector& __x) 1194e710425bSDimitry Andric : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc())) { 1195fe013be4SDimitry Andric __init_with_size(__x.__begin_, __x.__end_, __x.size()); 11960b57cec5SDimitry Andric} 11970b57cec5SDimitry Andric 11980b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1199bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 120081ad6265SDimitry Andricvector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t<allocator_type>& __a) 1201e710425bSDimitry Andric : __end_cap_(nullptr, __a) { 1202fe013be4SDimitry Andric __init_with_size(__x.__begin_, __x.__end_, __x.size()); 12030b57cec5SDimitry Andric} 12040b57cec5SDimitry Andric 12050b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1206e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>::vector(vector&& __x) 1207fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 17 120881ad6265SDimitry Andric noexcept 12090b57cec5SDimitry Andric#else 12100b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 12110b57cec5SDimitry Andric#endif 1212e710425bSDimitry Andric : __end_cap_(nullptr, std::move(__x.__alloc())) { 12130b57cec5SDimitry Andric this->__begin_ = __x.__begin_; 12140b57cec5SDimitry Andric this->__end_ = __x.__end_; 12150b57cec5SDimitry Andric this->__end_cap() = __x.__end_cap(); 12160b57cec5SDimitry Andric __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; 12170b57cec5SDimitry Andric} 12180b57cec5SDimitry Andric 12190b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1220e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI 122181ad6265SDimitry Andricvector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_type>& __a) 1222e710425bSDimitry Andric : __end_cap_(nullptr, __a) { 1223e710425bSDimitry Andric if (__a == __x.__alloc()) { 12240b57cec5SDimitry Andric this->__begin_ = __x.__begin_; 12250b57cec5SDimitry Andric this->__end_ = __x.__end_; 12260b57cec5SDimitry Andric this->__end_cap() = __x.__end_cap(); 12270b57cec5SDimitry Andric __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; 1228e710425bSDimitry Andric } else { 12290b57cec5SDimitry Andric typedef move_iterator<iterator> _Ip; 1230bdd1243dSDimitry Andric auto __guard = std::__make_exception_guard(__destroy_vector(*this)); 12310b57cec5SDimitry Andric assign(_Ip(__x.begin()), _Ip(__x.end())); 123250d7464cSDimitry Andric __guard.__complete(); 12330b57cec5SDimitry Andric } 12340b57cec5SDimitry Andric} 12350b57cec5SDimitry Andric 123681ad6265SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 123781ad6265SDimitry Andric 12380b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1239e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI 1240e710425bSDimitry Andricvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il) { 1241bdd1243dSDimitry Andric auto __guard = std::__make_exception_guard(__destroy_vector(*this)); 1242e710425bSDimitry Andric if (__il.size() > 0) { 12430b57cec5SDimitry Andric __vallocate(__il.size()); 12440b57cec5SDimitry Andric __construct_at_end(__il.begin(), __il.end(), __il.size()); 12450b57cec5SDimitry Andric } 124650d7464cSDimitry Andric __guard.__complete(); 12470b57cec5SDimitry Andric} 12480b57cec5SDimitry Andric 12490b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1250e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI 12510b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) 1252e710425bSDimitry Andric : __end_cap_(nullptr, __a) { 1253bdd1243dSDimitry Andric auto __guard = std::__make_exception_guard(__destroy_vector(*this)); 1254e710425bSDimitry Andric if (__il.size() > 0) { 12550b57cec5SDimitry Andric __vallocate(__il.size()); 12560b57cec5SDimitry Andric __construct_at_end(__il.begin(), __il.end(), __il.size()); 12570b57cec5SDimitry Andric } 125850d7464cSDimitry Andric __guard.__complete(); 12590b57cec5SDimitry Andric} 12600b57cec5SDimitry Andric 126181ad6265SDimitry Andric#endif // _LIBCPP_CXX03_LANG 126281ad6265SDimitry Andric 12630b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1264e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>& 12650b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator=(vector&& __x) 1266e710425bSDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) { 1267e710425bSDimitry Andric __move_assign(__x, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>()); 12680b57cec5SDimitry Andric return *this; 12690b57cec5SDimitry Andric} 12700b57cec5SDimitry Andric 12710b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1272e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type) 1273e710425bSDimitry Andric _NOEXCEPT_(__alloc_traits::is_always_equal::value) { 1274e710425bSDimitry Andric if (__alloc() != __c.__alloc()) { 12750b57cec5SDimitry Andric typedef move_iterator<iterator> _Ip; 12760b57cec5SDimitry Andric assign(_Ip(__c.begin()), _Ip(__c.end())); 1277e710425bSDimitry Andric } else 12780b57cec5SDimitry Andric __move_assign(__c, true_type()); 12790b57cec5SDimitry Andric} 12800b57cec5SDimitry Andric 12810b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1282e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type) 1283e710425bSDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) { 12840b57cec5SDimitry Andric __vdeallocate(); 1285349cc55cSDimitry Andric __move_assign_alloc(__c); // this can throw 12860b57cec5SDimitry Andric this->__begin_ = __c.__begin_; 12870b57cec5SDimitry Andric this->__end_ = __c.__end_; 12880b57cec5SDimitry Andric this->__end_cap() = __c.__end_cap(); 12890b57cec5SDimitry Andric __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr; 12900b57cec5SDimitry Andric} 12910b57cec5SDimitry Andric 12920b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1293e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>& 1294e710425bSDimitry Andricvector<_Tp, _Allocator>::operator=(const vector& __x) { 1295e710425bSDimitry Andric if (this != std::addressof(__x)) { 1296349cc55cSDimitry Andric __copy_assign_alloc(__x); 12970b57cec5SDimitry Andric assign(__x.__begin_, __x.__end_); 12980b57cec5SDimitry Andric } 12990b57cec5SDimitry Andric return *this; 13000b57cec5SDimitry Andric} 13010b57cec5SDimitry Andric 13020b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1303e710425bSDimitry Andrictemplate <class _InputIterator, 1304e710425bSDimitry Andric __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value && 1305bdd1243dSDimitry Andric is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value, 1306bdd1243dSDimitry Andric int> > 1307e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last) { 1308fe013be4SDimitry Andric __assign_with_sentinel(__first, __last); 1309fe013be4SDimitry Andric} 1310fe013be4SDimitry Andric 1311fe013be4SDimitry Andrictemplate <class _Tp, class _Allocator> 1312fe013be4SDimitry Andrictemplate <class _Iterator, class _Sentinel> 1313e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void 1314e710425bSDimitry Andricvector<_Tp, _Allocator>::__assign_with_sentinel(_Iterator __first, _Sentinel __last) { 13150b57cec5SDimitry Andric clear(); 13160b57cec5SDimitry Andric for (; __first != __last; ++__first) 131781ad6265SDimitry Andric emplace_back(*__first); 13180b57cec5SDimitry Andric} 13190b57cec5SDimitry Andric 13200b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1321e710425bSDimitry Andrictemplate <class _ForwardIterator, 1322e710425bSDimitry Andric __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value && 1323bdd1243dSDimitry Andric is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value, 1324bdd1243dSDimitry Andric int> > 1325e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) { 1326fe013be4SDimitry Andric __assign_with_size(__first, __last, std::distance(__first, __last)); 1327fe013be4SDimitry Andric} 1328fe013be4SDimitry Andric 1329fe013be4SDimitry Andrictemplate <class _Tp, class _Allocator> 1330fe013be4SDimitry Andrictemplate <class _ForwardIterator, class _Sentinel> 1331e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void 1332e710425bSDimitry Andricvector<_Tp, _Allocator>::__assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __n) { 1333fe013be4SDimitry Andric size_type __new_size = static_cast<size_type>(__n); 1334e710425bSDimitry Andric if (__new_size <= capacity()) { 1335e710425bSDimitry Andric if (__new_size > size()) { 1336fe013be4SDimitry Andric _ForwardIterator __mid = std::next(__first, size()); 1337fe013be4SDimitry Andric std::copy(__first, __mid, this->__begin_); 13380b57cec5SDimitry Andric __construct_at_end(__mid, __last, __new_size - size()); 1339e710425bSDimitry Andric } else { 1340fe013be4SDimitry Andric pointer __m = std::__copy<_ClassicAlgPolicy>(__first, __last, this->__begin_).second; 13410b57cec5SDimitry Andric this->__destruct_at_end(__m); 13420b57cec5SDimitry Andric } 1343e710425bSDimitry Andric } else { 13440b57cec5SDimitry Andric __vdeallocate(); 13450b57cec5SDimitry Andric __vallocate(__recommend(__new_size)); 13460b57cec5SDimitry Andric __construct_at_end(__first, __last, __new_size); 13470b57cec5SDimitry Andric } 13480b57cec5SDimitry Andric} 13490b57cec5SDimitry Andric 13500b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1351e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u) { 1352e710425bSDimitry Andric if (__n <= capacity()) { 13530b57cec5SDimitry Andric size_type __s = size(); 1354bdd1243dSDimitry Andric std::fill_n(this->__begin_, std::min(__n, __s), __u); 13550b57cec5SDimitry Andric if (__n > __s) 13560b57cec5SDimitry Andric __construct_at_end(__n - __s, __u); 13570b57cec5SDimitry Andric else 13580b57cec5SDimitry Andric this->__destruct_at_end(this->__begin_ + __n); 1359e710425bSDimitry Andric } else { 13600b57cec5SDimitry Andric __vdeallocate(); 13610b57cec5SDimitry Andric __vallocate(__recommend(static_cast<size_type>(__n))); 13620b57cec5SDimitry Andric __construct_at_end(__n, __u); 13630b57cec5SDimitry Andric } 13640b57cec5SDimitry Andric} 13650b57cec5SDimitry Andric 13660b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1367e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator 1368e710425bSDimitry Andricvector<_Tp, _Allocator>::begin() _NOEXCEPT { 1369bdd1243dSDimitry Andric return __make_iter(this->__begin_); 13700b57cec5SDimitry Andric} 13710b57cec5SDimitry Andric 13720b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1373e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::const_iterator 1374e710425bSDimitry Andricvector<_Tp, _Allocator>::begin() const _NOEXCEPT { 1375bdd1243dSDimitry Andric return __make_iter(this->__begin_); 13760b57cec5SDimitry Andric} 13770b57cec5SDimitry Andric 13780b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1379e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator 1380e710425bSDimitry Andricvector<_Tp, _Allocator>::end() _NOEXCEPT { 1381bdd1243dSDimitry Andric return __make_iter(this->__end_); 13820b57cec5SDimitry Andric} 13830b57cec5SDimitry Andric 13840b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1385e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::const_iterator 1386e710425bSDimitry Andricvector<_Tp, _Allocator>::end() const _NOEXCEPT { 1387bdd1243dSDimitry Andric return __make_iter(this->__end_); 13880b57cec5SDimitry Andric} 13890b57cec5SDimitry Andric 13900b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1391e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::reference 1392e710425bSDimitry Andricvector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT { 1393fe013be4SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < size(), "vector[] index out of bounds"); 13940b57cec5SDimitry Andric return this->__begin_[__n]; 13950b57cec5SDimitry Andric} 13960b57cec5SDimitry Andric 13970b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1398e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::const_reference 1399e710425bSDimitry Andricvector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT { 1400fe013be4SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < size(), "vector[] index out of bounds"); 14010b57cec5SDimitry Andric return this->__begin_[__n]; 14020b57cec5SDimitry Andric} 14030b57cec5SDimitry Andric 14040b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1405e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::reference vector<_Tp, _Allocator>::at(size_type __n) { 14060b57cec5SDimitry Andric if (__n >= size()) 14070b57cec5SDimitry Andric this->__throw_out_of_range(); 14080b57cec5SDimitry Andric return this->__begin_[__n]; 14090b57cec5SDimitry Andric} 14100b57cec5SDimitry Andric 14110b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1412e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::const_reference 1413e710425bSDimitry Andricvector<_Tp, _Allocator>::at(size_type __n) const { 14140b57cec5SDimitry Andric if (__n >= size()) 14150b57cec5SDimitry Andric this->__throw_out_of_range(); 14160b57cec5SDimitry Andric return this->__begin_[__n]; 14170b57cec5SDimitry Andric} 14180b57cec5SDimitry Andric 14190b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1420e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::reserve(size_type __n) { 1421e710425bSDimitry Andric if (__n > capacity()) { 1422349cc55cSDimitry Andric if (__n > max_size()) 1423349cc55cSDimitry Andric this->__throw_length_error(); 14240b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 14250b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__n, size(), __a); 14260b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 14270b57cec5SDimitry Andric } 14280b57cec5SDimitry Andric} 14290b57cec5SDimitry Andric 14300b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1431e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT { 1432e710425bSDimitry Andric if (capacity() > size()) { 1433fe013be4SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1434e710425bSDimitry Andric try { 1435fe013be4SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 14360b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 14370b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(size(), size(), __a); 14380b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 1439fe013be4SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1440e710425bSDimitry Andric } catch (...) { 14410b57cec5SDimitry Andric } 1442fe013be4SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 14430b57cec5SDimitry Andric } 14440b57cec5SDimitry Andric} 14450b57cec5SDimitry Andric 14460b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 14470b57cec5SDimitry Andrictemplate <class _Up> 1448e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::pointer 1449e710425bSDimitry Andricvector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x) { 14500b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 14510b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); 1452bdd1243dSDimitry Andric // __v.push_back(std::forward<_Up>(__x)); 1453bdd1243dSDimitry Andric __alloc_traits::construct(__a, std::__to_address(__v.__end_), std::forward<_Up>(__x)); 14540b57cec5SDimitry Andric __v.__end_++; 14550b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 1456c9157d92SDimitry Andric return this->__end_; 14570b57cec5SDimitry Andric} 14580b57cec5SDimitry Andric 14590b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1460e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI void 1461e710425bSDimitry Andricvector<_Tp, _Allocator>::push_back(const_reference __x) { 1462c9157d92SDimitry Andric pointer __end = this->__end_; 1463c9157d92SDimitry Andric if (__end < this->__end_cap()) { 1464e40139ffSDimitry Andric __construct_one_at_end(__x); 1465c9157d92SDimitry Andric ++__end; 1466c9157d92SDimitry Andric } else { 1467c9157d92SDimitry Andric __end = __push_back_slow_path(__x); 14680b57cec5SDimitry Andric } 1469c9157d92SDimitry Andric this->__end_ = __end; 14700b57cec5SDimitry Andric} 14710b57cec5SDimitry Andric 14720b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1473e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI void vector<_Tp, _Allocator>::push_back(value_type&& __x) { 1474c9157d92SDimitry Andric pointer __end = this->__end_; 1475c9157d92SDimitry Andric if (__end < this->__end_cap()) { 1476bdd1243dSDimitry Andric __construct_one_at_end(std::move(__x)); 1477c9157d92SDimitry Andric ++__end; 1478c9157d92SDimitry Andric } else { 1479c9157d92SDimitry Andric __end = __push_back_slow_path(std::move(__x)); 14800b57cec5SDimitry Andric } 1481c9157d92SDimitry Andric this->__end_ = __end; 14820b57cec5SDimitry Andric} 14830b57cec5SDimitry Andric 14840b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 14850b57cec5SDimitry Andrictemplate <class... _Args> 1486e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::pointer 1487e710425bSDimitry Andricvector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args) { 14880b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 14890b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); 1490bdd1243dSDimitry Andric // __v.emplace_back(std::forward<_Args>(__args)...); 1491bdd1243dSDimitry Andric __alloc_traits::construct(__a, std::__to_address(__v.__end_), std::forward<_Args>(__args)...); 14920b57cec5SDimitry Andric __v.__end_++; 14930b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 1494c9157d92SDimitry Andric return this->__end_; 14950b57cec5SDimitry Andric} 14960b57cec5SDimitry Andric 14970b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 14980b57cec5SDimitry Andrictemplate <class... _Args> 1499e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline 1500fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 17 15010b57cec5SDimitry Andric typename vector<_Tp, _Allocator>::reference 15020b57cec5SDimitry Andric#else 15030b57cec5SDimitry Andric void 15040b57cec5SDimitry Andric#endif 1505e710425bSDimitry Andric vector<_Tp, _Allocator>::emplace_back(_Args&&... __args) { 1506c9157d92SDimitry Andric pointer __end = this->__end_; 1507c9157d92SDimitry Andric if (__end < this->__end_cap()) { 1508bdd1243dSDimitry Andric __construct_one_at_end(std::forward<_Args>(__args)...); 1509c9157d92SDimitry Andric ++__end; 1510c9157d92SDimitry Andric } else { 1511c9157d92SDimitry Andric __end = __emplace_back_slow_path(std::forward<_Args>(__args)...); 15120b57cec5SDimitry Andric } 1513c9157d92SDimitry Andric this->__end_ = __end; 1514fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 17 1515c9157d92SDimitry Andric return *(__end - 1); 15160b57cec5SDimitry Andric#endif 15170b57cec5SDimitry Andric} 15180b57cec5SDimitry Andric 15190b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1520e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline void vector<_Tp, _Allocator>::pop_back() { 1521fe013be4SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "vector::pop_back called on an empty vector"); 15220b57cec5SDimitry Andric this->__destruct_at_end(this->__end_ - 1); 15230b57cec5SDimitry Andric} 15240b57cec5SDimitry Andric 15250b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1526e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator 1527e710425bSDimitry Andricvector<_Tp, _Allocator>::erase(const_iterator __position) { 1528e710425bSDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( 1529e710425bSDimitry Andric __position != end(), "vector::erase(iterator) called with a non-dereferenceable iterator"); 15300b57cec5SDimitry Andric difference_type __ps = __position - cbegin(); 15310b57cec5SDimitry Andric pointer __p = this->__begin_ + __ps; 1532bdd1243dSDimitry Andric this->__destruct_at_end(std::move(__p + 1, this->__end_, __p)); 1533bdd1243dSDimitry Andric return __make_iter(__p); 15340b57cec5SDimitry Andric} 15350b57cec5SDimitry Andric 15360b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1537e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator 1538e710425bSDimitry Andricvector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) { 1539fe013be4SDimitry Andric _LIBCPP_ASSERT_VALID_INPUT_RANGE(__first <= __last, "vector::erase(first, last) called with invalid range"); 15400b57cec5SDimitry Andric pointer __p = this->__begin_ + (__first - begin()); 15410b57cec5SDimitry Andric if (__first != __last) { 1542bdd1243dSDimitry Andric this->__destruct_at_end(std::move(__p + (__last - __first), this->__end_, __p)); 15430b57cec5SDimitry Andric } 1544bdd1243dSDimitry Andric return __make_iter(__p); 15450b57cec5SDimitry Andric} 15460b57cec5SDimitry Andric 15470b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1548e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void 1549e710425bSDimitry Andricvector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to) { 15500b57cec5SDimitry Andric pointer __old_last = this->__end_; 15510b57cec5SDimitry Andric difference_type __n = __old_last - __to; 1552e40139ffSDimitry Andric { 1553e40139ffSDimitry Andric pointer __i = __from_s + __n; 1554e40139ffSDimitry Andric _ConstructTransaction __tx(*this, __from_e - __i); 1555e710425bSDimitry Andric for (pointer __pos = __tx.__pos_; __i < __from_e; ++__i, (void)++__pos, __tx.__pos_ = __pos) { 1556e710425bSDimitry Andric __alloc_traits::construct(this->__alloc(), std::__to_address(__pos), std::move(*__i)); 1557e40139ffSDimitry Andric } 1558e40139ffSDimitry Andric } 1559bdd1243dSDimitry Andric std::move_backward(__from_s, __from_s + __n, __old_last); 15600b57cec5SDimitry Andric} 15610b57cec5SDimitry Andric 15620b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1563e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator 1564e710425bSDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) { 15650b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 156661cfbce3SDimitry Andric // We can't compare unrelated pointers inside constant expressions 1567e710425bSDimitry Andric if (!__libcpp_is_constant_evaluated() && this->__end_ < this->__end_cap()) { 1568e710425bSDimitry Andric if (__p == this->__end_) { 1569e40139ffSDimitry Andric __construct_one_at_end(__x); 1570e710425bSDimitry Andric } else { 15710b57cec5SDimitry Andric __move_range(__p, this->__end_, __p + 1); 15720b57cec5SDimitry Andric const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); 15730b57cec5SDimitry Andric if (__p <= __xr && __xr < this->__end_) 15740b57cec5SDimitry Andric ++__xr; 15750b57cec5SDimitry Andric *__p = *__xr; 15760b57cec5SDimitry Andric } 1577e710425bSDimitry Andric } else { 15780b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 15790b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 15800b57cec5SDimitry Andric __v.push_back(__x); 15810b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 15820b57cec5SDimitry Andric } 1583bdd1243dSDimitry Andric return __make_iter(__p); 15840b57cec5SDimitry Andric} 15850b57cec5SDimitry Andric 15860b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1587e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator 1588e710425bSDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) { 15890b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 1590e710425bSDimitry Andric if (this->__end_ < this->__end_cap()) { 1591e710425bSDimitry Andric if (__p == this->__end_) { 1592bdd1243dSDimitry Andric __construct_one_at_end(std::move(__x)); 1593e710425bSDimitry Andric } else { 15940b57cec5SDimitry Andric __move_range(__p, this->__end_, __p + 1); 1595bdd1243dSDimitry Andric *__p = std::move(__x); 15960b57cec5SDimitry Andric } 1597e710425bSDimitry Andric } else { 15980b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 15990b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 1600bdd1243dSDimitry Andric __v.push_back(std::move(__x)); 16010b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 16020b57cec5SDimitry Andric } 1603bdd1243dSDimitry Andric return __make_iter(__p); 16040b57cec5SDimitry Andric} 16050b57cec5SDimitry Andric 16060b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16070b57cec5SDimitry Andrictemplate <class... _Args> 1608e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator 1609e710425bSDimitry Andricvector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) { 16100b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 1611e710425bSDimitry Andric if (this->__end_ < this->__end_cap()) { 1612e710425bSDimitry Andric if (__p == this->__end_) { 1613bdd1243dSDimitry Andric __construct_one_at_end(std::forward<_Args>(__args)...); 1614e710425bSDimitry Andric } else { 1615bdd1243dSDimitry Andric __temp_value<value_type, _Allocator> __tmp(this->__alloc(), std::forward<_Args>(__args)...); 16160b57cec5SDimitry Andric __move_range(__p, this->__end_, __p + 1); 1617bdd1243dSDimitry Andric *__p = std::move(__tmp.get()); 16180b57cec5SDimitry Andric } 1619e710425bSDimitry Andric } else { 16200b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 16210b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 1622bdd1243dSDimitry Andric __v.emplace_back(std::forward<_Args>(__args)...); 16230b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 16240b57cec5SDimitry Andric } 1625bdd1243dSDimitry Andric return __make_iter(__p); 16260b57cec5SDimitry Andric} 16270b57cec5SDimitry Andric 16280b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1629e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator 1630e710425bSDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x) { 16310b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 1632e710425bSDimitry Andric if (__n > 0) { 163361cfbce3SDimitry Andric // We can't compare unrelated pointers inside constant expressions 1634e710425bSDimitry Andric if (!__libcpp_is_constant_evaluated() && __n <= static_cast<size_type>(this->__end_cap() - this->__end_)) { 16350b57cec5SDimitry Andric size_type __old_n = __n; 16360b57cec5SDimitry Andric pointer __old_last = this->__end_; 1637e710425bSDimitry Andric if (__n > static_cast<size_type>(this->__end_ - __p)) { 16380b57cec5SDimitry Andric size_type __cx = __n - (this->__end_ - __p); 16390b57cec5SDimitry Andric __construct_at_end(__cx, __x); 16400b57cec5SDimitry Andric __n -= __cx; 16410b57cec5SDimitry Andric } 1642e710425bSDimitry Andric if (__n > 0) { 16430b57cec5SDimitry Andric __move_range(__p, __old_last, __p + __old_n); 16440b57cec5SDimitry Andric const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); 16450b57cec5SDimitry Andric if (__p <= __xr && __xr < this->__end_) 16460b57cec5SDimitry Andric __xr += __old_n; 1647bdd1243dSDimitry Andric std::fill_n(__p, __n, *__xr); 16480b57cec5SDimitry Andric } 1649e710425bSDimitry Andric } else { 16500b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 16510b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); 16520b57cec5SDimitry Andric __v.__construct_at_end(__n, __x); 16530b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 16540b57cec5SDimitry Andric } 16550b57cec5SDimitry Andric } 1656bdd1243dSDimitry Andric return __make_iter(__p); 16570b57cec5SDimitry Andric} 16580b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1659e710425bSDimitry Andrictemplate <class _InputIterator, 1660e710425bSDimitry Andric __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value && 1661bdd1243dSDimitry Andric is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value, 1662bdd1243dSDimitry Andric int> > 1663bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator 1664e710425bSDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) { 1665fe013be4SDimitry Andric return __insert_with_sentinel(__position, __first, __last); 1666fe013be4SDimitry Andric} 1667fe013be4SDimitry Andric 1668fe013be4SDimitry Andrictemplate <class _Tp, class _Allocator> 1669fe013be4SDimitry Andrictemplate <class _InputIterator, class _Sentinel> 1670e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator 1671fe013be4SDimitry Andricvector<_Tp, _Allocator>::__insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last) { 16720b57cec5SDimitry Andric difference_type __off = __position - begin(); 16730b57cec5SDimitry Andric pointer __p = this->__begin_ + __off; 16740b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 16750b57cec5SDimitry Andric pointer __old_last = this->__end_; 1676e710425bSDimitry Andric for (; this->__end_ != this->__end_cap() && __first != __last; ++__first) { 1677e40139ffSDimitry Andric __construct_one_at_end(*__first); 16780b57cec5SDimitry Andric } 16790b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__a); 1680e710425bSDimitry Andric if (__first != __last) { 1681fe013be4SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1682e710425bSDimitry Andric try { 1683fe013be4SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 1684fe013be4SDimitry Andric __v.__construct_at_end_with_sentinel(std::move(__first), std::move(__last)); 16850b57cec5SDimitry Andric difference_type __old_size = __old_last - this->__begin_; 16860b57cec5SDimitry Andric difference_type __old_p = __p - this->__begin_; 16870b57cec5SDimitry Andric reserve(__recommend(size() + __v.size())); 16880b57cec5SDimitry Andric __p = this->__begin_ + __old_p; 16890b57cec5SDimitry Andric __old_last = this->__begin_ + __old_size; 1690fe013be4SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 1691e710425bSDimitry Andric } catch (...) { 1692bdd1243dSDimitry Andric erase(__make_iter(__old_last), end()); 16930b57cec5SDimitry Andric throw; 16940b57cec5SDimitry Andric } 1695fe013be4SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 16960b57cec5SDimitry Andric } 1697bdd1243dSDimitry Andric __p = std::rotate(__p, __old_last, this->__end_); 1698e710425bSDimitry Andric insert(__make_iter(__p), std::make_move_iterator(__v.begin()), std::make_move_iterator(__v.end())); 16990b57cec5SDimitry Andric return begin() + __off; 17000b57cec5SDimitry Andric} 17010b57cec5SDimitry Andric 17020b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1703e710425bSDimitry Andrictemplate <class _ForwardIterator, 1704e710425bSDimitry Andric __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value && 1705bdd1243dSDimitry Andric is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value, 1706bdd1243dSDimitry Andric int> > 1707bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator 1708e710425bSDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) { 1709fe013be4SDimitry Andric return __insert_with_size(__position, __first, __last, std::distance(__first, __last)); 1710fe013be4SDimitry Andric} 1711fe013be4SDimitry Andric 1712fe013be4SDimitry Andrictemplate <class _Tp, class _Allocator> 1713fe013be4SDimitry Andrictemplate <class _Iterator, class _Sentinel> 1714e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator 1715e710425bSDimitry Andricvector<_Tp, _Allocator>::__insert_with_size( 1716e710425bSDimitry Andric const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n) { 1717fe013be4SDimitry Andric auto __insertion_size = __n; 17180b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 1719e710425bSDimitry Andric if (__n > 0) { 1720e710425bSDimitry Andric if (__n <= this->__end_cap() - this->__end_) { 17210b57cec5SDimitry Andric size_type __old_n = __n; 17220b57cec5SDimitry Andric pointer __old_last = this->__end_; 1723fe013be4SDimitry Andric _Iterator __m = std::next(__first, __n); 17240b57cec5SDimitry Andric difference_type __dx = this->__end_ - __p; 1725e710425bSDimitry Andric if (__n > __dx) { 17260b57cec5SDimitry Andric __m = __first; 17270b57cec5SDimitry Andric difference_type __diff = this->__end_ - __p; 1728bdd1243dSDimitry Andric std::advance(__m, __diff); 17290b57cec5SDimitry Andric __construct_at_end(__m, __last, __n - __diff); 17300b57cec5SDimitry Andric __n = __dx; 17310b57cec5SDimitry Andric } 1732e710425bSDimitry Andric if (__n > 0) { 17330b57cec5SDimitry Andric __move_range(__p, __old_last, __p + __old_n); 1734bdd1243dSDimitry Andric std::copy(__first, __m, __p); 17350b57cec5SDimitry Andric } 1736e710425bSDimitry Andric } else { 17370b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 17380b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); 1739fe013be4SDimitry Andric __v.__construct_at_end_with_size(__first, __insertion_size); 17400b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 17410b57cec5SDimitry Andric } 17420b57cec5SDimitry Andric } 1743bdd1243dSDimitry Andric return __make_iter(__p); 17440b57cec5SDimitry Andric} 17450b57cec5SDimitry Andric 17460b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1747e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::resize(size_type __sz) { 17480b57cec5SDimitry Andric size_type __cs = size(); 17490b57cec5SDimitry Andric if (__cs < __sz) 17500b57cec5SDimitry Andric this->__append(__sz - __cs); 17510b57cec5SDimitry Andric else if (__cs > __sz) 17520b57cec5SDimitry Andric this->__destruct_at_end(this->__begin_ + __sz); 17530b57cec5SDimitry Andric} 17540b57cec5SDimitry Andric 17550b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1756e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x) { 17570b57cec5SDimitry Andric size_type __cs = size(); 17580b57cec5SDimitry Andric if (__cs < __sz) 17590b57cec5SDimitry Andric this->__append(__sz - __cs, __x); 17600b57cec5SDimitry Andric else if (__cs > __sz) 17610b57cec5SDimitry Andric this->__destruct_at_end(this->__begin_ + __sz); 17620b57cec5SDimitry Andric} 17630b57cec5SDimitry Andric 17640b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1765e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::swap(vector& __x) 17660b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 17670b57cec5SDimitry Andric _NOEXCEPT 17680b57cec5SDimitry Andric#else 1769e710425bSDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value) 17700b57cec5SDimitry Andric#endif 17710b57cec5SDimitry Andric{ 1772e710425bSDimitry Andric _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR( 1773e710425bSDimitry Andric __alloc_traits::propagate_on_container_swap::value || this->__alloc() == __x.__alloc(), 17740b57cec5SDimitry Andric "vector::swap: Either propagate_on_container_swap must be true" 17750b57cec5SDimitry Andric " or the allocators must compare equal"); 1776bdd1243dSDimitry Andric std::swap(this->__begin_, __x.__begin_); 1777bdd1243dSDimitry Andric std::swap(this->__end_, __x.__end_); 1778bdd1243dSDimitry Andric std::swap(this->__end_cap(), __x.__end_cap()); 1779e710425bSDimitry Andric std::__swap_allocator( 1780e710425bSDimitry Andric this->__alloc(), __x.__alloc(), integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>()); 17810b57cec5SDimitry Andric} 17820b57cec5SDimitry Andric 17830b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1784e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 bool vector<_Tp, _Allocator>::__invariants() const { 1785e710425bSDimitry Andric if (this->__begin_ == nullptr) { 17860b57cec5SDimitry Andric if (this->__end_ != nullptr || this->__end_cap() != nullptr) 17870b57cec5SDimitry Andric return false; 1788e710425bSDimitry Andric } else { 17890b57cec5SDimitry Andric if (this->__begin_ > this->__end_) 17900b57cec5SDimitry Andric return false; 17910b57cec5SDimitry Andric if (this->__begin_ == this->__end_cap()) 17920b57cec5SDimitry Andric return false; 17930b57cec5SDimitry Andric if (this->__end_ > this->__end_cap()) 17940b57cec5SDimitry Andric return false; 17950b57cec5SDimitry Andric } 17960b57cec5SDimitry Andric return true; 17970b57cec5SDimitry Andric} 17980b57cec5SDimitry Andric 17990b57cec5SDimitry Andric// vector<bool> 18000b57cec5SDimitry Andric 1801e710425bSDimitry Andrictemplate <class _Allocator> 1802e710425bSDimitry Andricclass vector<bool, _Allocator>; 18030b57cec5SDimitry Andric 18040b57cec5SDimitry Andrictemplate <class _Allocator> 1805e710425bSDimitry Andricstruct hash<vector<bool, _Allocator> >; 1806e710425bSDimitry Andric 1807e710425bSDimitry Andrictemplate <class _Allocator> 1808e710425bSDimitry Andricstruct __has_storage_type<vector<bool, _Allocator> > { 18090b57cec5SDimitry Andric static const bool value = true; 18100b57cec5SDimitry Andric}; 18110b57cec5SDimitry Andric 18120b57cec5SDimitry Andrictemplate <class _Allocator> 1813e710425bSDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> { 18140b57cec5SDimitry Andricpublic: 18150b57cec5SDimitry Andric typedef vector __self; 18160b57cec5SDimitry Andric typedef bool value_type; 18170b57cec5SDimitry Andric typedef _Allocator allocator_type; 18180b57cec5SDimitry Andric typedef allocator_traits<allocator_type> __alloc_traits; 18190b57cec5SDimitry Andric typedef typename __alloc_traits::size_type size_type; 18200b57cec5SDimitry Andric typedef typename __alloc_traits::difference_type difference_type; 18210b57cec5SDimitry Andric typedef size_type __storage_type; 18220b57cec5SDimitry Andric typedef __bit_iterator<vector, false> pointer; 18230b57cec5SDimitry Andric typedef __bit_iterator<vector, true> const_pointer; 18240b57cec5SDimitry Andric typedef pointer iterator; 18250b57cec5SDimitry Andric typedef const_pointer const_iterator; 1826bdd1243dSDimitry Andric typedef std::reverse_iterator<iterator> reverse_iterator; 1827bdd1243dSDimitry Andric typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 18280b57cec5SDimitry Andric 18290b57cec5SDimitry Andricprivate: 1830bdd1243dSDimitry Andric typedef __rebind_alloc<__alloc_traits, __storage_type> __storage_allocator; 18310b57cec5SDimitry Andric typedef allocator_traits<__storage_allocator> __storage_traits; 18320b57cec5SDimitry Andric typedef typename __storage_traits::pointer __storage_pointer; 18330b57cec5SDimitry Andric typedef typename __storage_traits::const_pointer __const_storage_pointer; 18340b57cec5SDimitry Andric 18350b57cec5SDimitry Andric __storage_pointer __begin_; 18360b57cec5SDimitry Andric size_type __size_; 18370b57cec5SDimitry Andric __compressed_pair<size_type, __storage_allocator> __cap_alloc_; 1838e710425bSDimitry Andric 18390b57cec5SDimitry Andricpublic: 18400b57cec5SDimitry Andric typedef __bit_reference<vector> reference; 184181ad6265SDimitry Andric#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL 184281ad6265SDimitry Andric using const_reference = bool; 184381ad6265SDimitry Andric#else 18440b57cec5SDimitry Andric typedef __bit_const_reference<vector> const_reference; 184581ad6265SDimitry Andric#endif 1846e710425bSDimitry Andric 18470b57cec5SDimitry Andricprivate: 1848e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type& __cap() _NOEXCEPT { return __cap_alloc_.first(); } 1849e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const size_type& __cap() const _NOEXCEPT { 1850e710425bSDimitry Andric return __cap_alloc_.first(); 1851e710425bSDimitry Andric } 1852e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __storage_allocator& __alloc() _NOEXCEPT { 1853e710425bSDimitry Andric return __cap_alloc_.second(); 1854e710425bSDimitry Andric } 1855e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const __storage_allocator& __alloc() const _NOEXCEPT { 1856e710425bSDimitry Andric return __cap_alloc_.second(); 1857e710425bSDimitry Andric } 18580b57cec5SDimitry Andric 18590b57cec5SDimitry Andric static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 18600b57cec5SDimitry Andric 1861e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type 1862e710425bSDimitry Andric __internal_cap_to_external(size_type __n) _NOEXCEPT { 1863e710425bSDimitry Andric return __n * __bits_per_word; 1864e710425bSDimitry Andric } 1865e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type 1866e710425bSDimitry Andric __external_cap_to_internal(size_type __n) _NOEXCEPT { 1867e710425bSDimitry Andric return (__n - 1) / __bits_per_word + 1; 1868e710425bSDimitry Andric } 18690b57cec5SDimitry Andric 18700b57cec5SDimitry Andricpublic: 1871e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector() 1872e710425bSDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); 18730b57cec5SDimitry Andric 1874bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(const allocator_type& __a) 18750b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 18760b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value); 18770b57cec5SDimitry Andric#else 18780b57cec5SDimitry Andric _NOEXCEPT; 18790b57cec5SDimitry Andric#endif 188050d7464cSDimitry Andric 188150d7464cSDimitry Andricprivate: 188250d7464cSDimitry Andric class __destroy_vector { 188350d7464cSDimitry Andric public: 1884fe013be4SDimitry Andric _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI __destroy_vector(vector& __vec) : __vec_(__vec) {} 188550d7464cSDimitry Andric 1886bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() { 188750d7464cSDimitry Andric if (__vec_.__begin_ != nullptr) 188850d7464cSDimitry Andric __storage_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.__cap()); 188950d7464cSDimitry Andric } 189050d7464cSDimitry Andric 189150d7464cSDimitry Andric private: 189250d7464cSDimitry Andric vector& __vec_; 189350d7464cSDimitry Andric }; 189450d7464cSDimitry Andric 189550d7464cSDimitry Andricpublic: 1896bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~vector() { __destroy_vector (*this)(); } 189750d7464cSDimitry Andric 1898bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n); 1899fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 14 1900bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n, const allocator_type& __a); 19010b57cec5SDimitry Andric#endif 1902bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(size_type __n, const value_type& __v); 1903e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 1904e710425bSDimitry Andric vector(size_type __n, const value_type& __v, const allocator_type& __a); 1905c9157d92SDimitry Andric template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0> 1906c9157d92SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_InputIterator __first, _InputIterator __last); 1907c9157d92SDimitry Andric template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0> 1908e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 1909e710425bSDimitry Andric vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a); 1910c9157d92SDimitry Andric template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0> 1911c9157d92SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_ForwardIterator __first, _ForwardIterator __last); 1912c9157d92SDimitry Andric template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0> 1913e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 1914e710425bSDimitry Andric vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a); 1915fe013be4SDimitry Andric 1916fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 23 1917fe013be4SDimitry Andric template <_ContainerCompatibleRange<bool> _Range> 1918e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr vector(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type()) 1919e710425bSDimitry Andric : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { 1920fe013be4SDimitry Andric if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) { 1921fe013be4SDimitry Andric auto __n = static_cast<size_type>(ranges::distance(__range)); 1922fe013be4SDimitry Andric __init_with_size(ranges::begin(__range), ranges::end(__range), __n); 1923fe013be4SDimitry Andric 1924fe013be4SDimitry Andric } else { 1925fe013be4SDimitry Andric __init_with_sentinel(ranges::begin(__range), ranges::end(__range)); 1926fe013be4SDimitry Andric } 1927fe013be4SDimitry Andric } 1928fe013be4SDimitry Andric#endif 19290b57cec5SDimitry Andric 1930bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(const vector& __v); 1931bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(const vector& __v, const allocator_type& __a); 1932bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector& operator=(const vector& __v); 19330b57cec5SDimitry Andric 19340b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 1935bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(initializer_list<value_type> __il); 1936bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 1937e710425bSDimitry Andric vector(initializer_list<value_type> __il, const allocator_type& __a); 1938e710425bSDimitry Andric 1939e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector& operator=(initializer_list<value_type> __il) { 1940e710425bSDimitry Andric assign(__il.begin(), __il.end()); 1941e710425bSDimitry Andric return *this; 1942e710425bSDimitry Andric } 19430b57cec5SDimitry Andric 19440b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG 19450b57cec5SDimitry Andric 1946e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(vector&& __v) 1947fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 17 194881ad6265SDimitry Andric noexcept; 194981ad6265SDimitry Andric#else 195081ad6265SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); 195181ad6265SDimitry Andric#endif 1952bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 1953e710425bSDimitry Andric vector(vector&& __v, const __type_identity_t<allocator_type>& __a); 1954e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector& operator=(vector&& __v) 195581ad6265SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); 195681ad6265SDimitry Andric 1957c9157d92SDimitry Andric template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0> 1958e710425bSDimitry Andric void _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 assign(_InputIterator __first, _InputIterator __last); 1959c9157d92SDimitry Andric template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0> 1960e710425bSDimitry Andric void _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 assign(_ForwardIterator __first, _ForwardIterator __last); 19610b57cec5SDimitry Andric 1962fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 23 1963fe013be4SDimitry Andric template <_ContainerCompatibleRange<bool> _Range> 1964e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr void assign_range(_Range&& __range) { 1965fe013be4SDimitry Andric if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) { 1966fe013be4SDimitry Andric auto __n = static_cast<size_type>(ranges::distance(__range)); 1967fe013be4SDimitry Andric __assign_with_size(ranges::begin(__range), ranges::end(__range), __n); 1968fe013be4SDimitry Andric 1969fe013be4SDimitry Andric } else { 1970fe013be4SDimitry Andric __assign_with_sentinel(ranges::begin(__range), ranges::end(__range)); 1971fe013be4SDimitry Andric } 1972fe013be4SDimitry Andric } 1973fe013be4SDimitry Andric#endif 1974fe013be4SDimitry Andric 1975bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void assign(size_type __n, const value_type& __x); 19760b57cec5SDimitry Andric 19770b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 1978e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void assign(initializer_list<value_type> __il) { 1979e710425bSDimitry Andric assign(__il.begin(), __il.end()); 1980e710425bSDimitry Andric } 19810b57cec5SDimitry Andric#endif 19820b57cec5SDimitry Andric 1983e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator_type get_allocator() const _NOEXCEPT { 1984e710425bSDimitry Andric return allocator_type(this->__alloc()); 1985e710425bSDimitry Andric } 19860b57cec5SDimitry Andric 1987bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type max_size() const _NOEXCEPT; 1988e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type capacity() const _NOEXCEPT { 1989e710425bSDimitry Andric return __internal_cap_to_external(__cap()); 1990e710425bSDimitry Andric } 1991e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type size() const _NOEXCEPT { return __size_; } 1992e710425bSDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool empty() const _NOEXCEPT { 1993e710425bSDimitry Andric return __size_ == 0; 1994e710425bSDimitry Andric } 1995bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void reserve(size_type __n); 1996bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void shrink_to_fit() _NOEXCEPT; 19970b57cec5SDimitry Andric 1998e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator begin() _NOEXCEPT { return __make_iter(0); } 1999e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator begin() const _NOEXCEPT { return __make_iter(0); } 2000e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator end() _NOEXCEPT { return __make_iter(__size_); } 2001e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator end() const _NOEXCEPT { 2002e710425bSDimitry Andric return __make_iter(__size_); 2003e710425bSDimitry Andric } 20040b57cec5SDimitry Andric 2005e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reverse_iterator rbegin() _NOEXCEPT { 2006e710425bSDimitry Andric return reverse_iterator(end()); 2007e710425bSDimitry Andric } 2008e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator rbegin() const _NOEXCEPT { 2009e710425bSDimitry Andric return const_reverse_iterator(end()); 2010e710425bSDimitry Andric } 2011e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reverse_iterator rend() _NOEXCEPT { 2012e710425bSDimitry Andric return reverse_iterator(begin()); 2013e710425bSDimitry Andric } 2014e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator rend() const _NOEXCEPT { 2015e710425bSDimitry Andric return const_reverse_iterator(begin()); 2016e710425bSDimitry Andric } 20170b57cec5SDimitry Andric 2018e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator cbegin() const _NOEXCEPT { return __make_iter(0); } 2019e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator cend() const _NOEXCEPT { 2020e710425bSDimitry Andric return __make_iter(__size_); 2021e710425bSDimitry Andric } 2022e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator crbegin() const _NOEXCEPT { 2023e710425bSDimitry Andric return rbegin(); 2024e710425bSDimitry Andric } 2025e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator crend() const _NOEXCEPT { return rend(); } 20260b57cec5SDimitry Andric 2027bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator[](size_type __n) { return __make_ref(__n); } 2028e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference operator[](size_type __n) const { 2029e710425bSDimitry Andric return __make_ref(__n); 2030e710425bSDimitry Andric } 2031bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI reference at(size_type __n); 2032bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __n) const; 20330b57cec5SDimitry Andric 2034bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference front() { return __make_ref(0); } 2035bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference front() const { return __make_ref(0); } 2036bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference back() { return __make_ref(__size_ - 1); } 2037bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference back() const { return __make_ref(__size_ - 1); } 20380b57cec5SDimitry Andric 2039bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void push_back(const value_type& __x); 2040fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 14 20410b57cec5SDimitry Andric template <class... _Args> 2042fe013be4SDimitry Andric# if _LIBCPP_STD_VER >= 17 2043bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference emplace_back(_Args&&... __args) 20440b57cec5SDimitry Andric# else 2045bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI void emplace_back(_Args&&... __args) 20460b57cec5SDimitry Andric# endif 20470b57cec5SDimitry Andric { 2048bdd1243dSDimitry Andric push_back(value_type(std::forward<_Args>(__args)...)); 2049fe013be4SDimitry Andric# if _LIBCPP_STD_VER >= 17 20500b57cec5SDimitry Andric return this->back(); 20510b57cec5SDimitry Andric# endif 20520b57cec5SDimitry Andric } 20530b57cec5SDimitry Andric#endif 20540b57cec5SDimitry Andric 2055fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 23 2056fe013be4SDimitry Andric template <_ContainerCompatibleRange<bool> _Range> 2057e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr void append_range(_Range&& __range) { 2058fe013be4SDimitry Andric insert_range(end(), std::forward<_Range>(__range)); 2059fe013be4SDimitry Andric } 2060fe013be4SDimitry Andric#endif 2061fe013be4SDimitry Andric 2062bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void pop_back() { --__size_; } 20630b57cec5SDimitry Andric 2064fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 14 20650b57cec5SDimitry Andric template <class... _Args> 2066e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator emplace(const_iterator __position, _Args&&... __args) { 2067e710425bSDimitry Andric return insert(__position, value_type(std::forward<_Args>(__args)...)); 2068e710425bSDimitry Andric } 20690b57cec5SDimitry Andric#endif 20700b57cec5SDimitry Andric 2071bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __position, const value_type& __x); 2072e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator 2073e710425bSDimitry Andric insert(const_iterator __position, size_type __n, const value_type& __x); 2074c9157d92SDimitry Andric template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0> 2075e710425bSDimitry Andric iterator _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 2076e710425bSDimitry Andric insert(const_iterator __position, _InputIterator __first, _InputIterator __last); 2077c9157d92SDimitry Andric template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0> 2078e710425bSDimitry Andric iterator _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 2079e710425bSDimitry Andric insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); 20800b57cec5SDimitry Andric 2081fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 23 2082fe013be4SDimitry Andric template <_ContainerCompatibleRange<bool> _Range> 2083e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr iterator insert_range(const_iterator __position, _Range&& __range) { 2084fe013be4SDimitry Andric if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) { 2085fe013be4SDimitry Andric auto __n = static_cast<size_type>(ranges::distance(__range)); 2086fe013be4SDimitry Andric return __insert_with_size(__position, ranges::begin(__range), ranges::end(__range), __n); 2087fe013be4SDimitry Andric 2088fe013be4SDimitry Andric } else { 2089fe013be4SDimitry Andric return __insert_with_sentinel(__position, ranges::begin(__range), ranges::end(__range)); 2090fe013be4SDimitry Andric } 2091fe013be4SDimitry Andric } 2092fe013be4SDimitry Andric#endif 2093fe013be4SDimitry Andric 20940b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 2095e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator 2096e710425bSDimitry Andric insert(const_iterator __position, initializer_list<value_type> __il) { 2097e710425bSDimitry Andric return insert(__position, __il.begin(), __il.end()); 2098e710425bSDimitry Andric } 20990b57cec5SDimitry Andric#endif 21000b57cec5SDimitry Andric 2101bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __position); 2102bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __first, const_iterator __last); 21030b57cec5SDimitry Andric 2104e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void clear() _NOEXCEPT { __size_ = 0; } 21050b57cec5SDimitry Andric 2106fe013be4SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(vector&) 21070b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 21080b57cec5SDimitry Andric _NOEXCEPT; 21090b57cec5SDimitry Andric#else 2110e710425bSDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value); 21110b57cec5SDimitry Andric#endif 2112e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void swap(reference __x, reference __y) _NOEXCEPT { 2113e710425bSDimitry Andric std::swap(__x, __y); 2114e710425bSDimitry Andric } 21150b57cec5SDimitry Andric 2116bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void resize(size_type __sz, value_type __x = false); 2117bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void flip() _NOEXCEPT; 21180b57cec5SDimitry Andric 2119bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __invariants() const; 21200b57cec5SDimitry Andric 21210b57cec5SDimitry Andricprivate: 2122e710425bSDimitry Andric _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_length_error() const { std::__throw_length_error("vector"); } 2123d56accc7SDimitry Andric 2124e710425bSDimitry Andric _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range() const { std::__throw_out_of_range("vector"); } 2125d56accc7SDimitry Andric 2126fe013be4SDimitry Andric template <class _InputIterator, class _Sentinel> 2127e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void 2128e710425bSDimitry Andric __init_with_size(_InputIterator __first, _Sentinel __last, size_type __n) { 2129fe013be4SDimitry Andric auto __guard = std::__make_exception_guard(__destroy_vector(*this)); 2130fe013be4SDimitry Andric 2131fe013be4SDimitry Andric if (__n > 0) { 2132fe013be4SDimitry Andric __vallocate(__n); 2133fe013be4SDimitry Andric __construct_at_end(std::move(__first), std::move(__last), __n); 2134fe013be4SDimitry Andric } 2135fe013be4SDimitry Andric 2136fe013be4SDimitry Andric __guard.__complete(); 2137fe013be4SDimitry Andric } 2138fe013be4SDimitry Andric 2139fe013be4SDimitry Andric template <class _InputIterator, class _Sentinel> 2140e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void 2141e710425bSDimitry Andric __init_with_sentinel(_InputIterator __first, _Sentinel __last) { 2142fe013be4SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 2143fe013be4SDimitry Andric try { 2144fe013be4SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 2145fe013be4SDimitry Andric for (; __first != __last; ++__first) 2146fe013be4SDimitry Andric push_back(*__first); 2147fe013be4SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 2148fe013be4SDimitry Andric } catch (...) { 2149fe013be4SDimitry Andric if (__begin_ != nullptr) 2150fe013be4SDimitry Andric __storage_traits::deallocate(__alloc(), __begin_, __cap()); 2151fe013be4SDimitry Andric throw; 2152fe013be4SDimitry Andric } 2153fe013be4SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 2154fe013be4SDimitry Andric } 2155fe013be4SDimitry Andric 2156fe013be4SDimitry Andric template <class _Iterator, class _Sentinel> 2157e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __assign_with_sentinel(_Iterator __first, _Sentinel __last); 2158fe013be4SDimitry Andric 2159fe013be4SDimitry Andric template <class _ForwardIterator, class _Sentinel> 2160e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void 2161e710425bSDimitry Andric __assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __ns); 2162fe013be4SDimitry Andric 2163fe013be4SDimitry Andric template <class _InputIterator, class _Sentinel> 2164e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator 2165e710425bSDimitry Andric __insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last); 2166fe013be4SDimitry Andric 2167fe013be4SDimitry Andric template <class _Iterator, class _Sentinel> 2168e710425bSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator 2169e710425bSDimitry Andric __insert_with_size(const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n); 2170fe013be4SDimitry Andric 217181ad6265SDimitry Andric // Allocate space for __n objects 217281ad6265SDimitry Andric // throws length_error if __n > max_size() 217381ad6265SDimitry Andric // throws (probably bad_alloc) if memory run out 217481ad6265SDimitry Andric // Precondition: __begin_ == __end_ == __cap() == 0 217581ad6265SDimitry Andric // Precondition: __n > 0 217681ad6265SDimitry Andric // Postcondition: capacity() >= __n 217781ad6265SDimitry Andric // Postcondition: size() == 0 2178bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __vallocate(size_type __n) { 217981ad6265SDimitry Andric if (__n > max_size()) 218081ad6265SDimitry Andric __throw_length_error(); 218181ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __external_cap_to_internal(__n)); 218281ad6265SDimitry Andric __begin_ = __allocation.ptr; 218381ad6265SDimitry Andric __size_ = 0; 218481ad6265SDimitry Andric __cap() = __allocation.count; 218561cfbce3SDimitry Andric if (__libcpp_is_constant_evaluated()) { 218661cfbce3SDimitry Andric for (size_type __i = 0; __i != __cap(); ++__i) 218761cfbce3SDimitry Andric std::__construct_at(std::__to_address(__begin_) + __i); 218861cfbce3SDimitry Andric } 218981ad6265SDimitry Andric } 219081ad6265SDimitry Andric 2191bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __vdeallocate() _NOEXCEPT; 2192e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type __align_it(size_type __new_size) _NOEXCEPT { 2193e710425bSDimitry Andric return (__new_size + (__bits_per_word - 1)) & ~((size_type)__bits_per_word - 1); 2194e710425bSDimitry Andric } 2195bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type __recommend(size_type __new_size) const; 2196bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __construct_at_end(size_type __n, bool __x); 2197fe013be4SDimitry Andric template <class _InputIterator, class _Sentinel> 2198e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void 2199e710425bSDimitry Andric __construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n); 2200bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __append(size_type __n, const_reference __x); 2201e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference __make_ref(size_type __pos) _NOEXCEPT { 2202e710425bSDimitry Andric return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word); 220381ad6265SDimitry Andric } 2204e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference __make_ref(size_type __pos) const _NOEXCEPT { 2205e710425bSDimitry Andric return __bit_const_reference<vector>( 2206e710425bSDimitry Andric __begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word); 2207e710425bSDimitry Andric } 2208e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator __make_iter(size_type __pos) _NOEXCEPT { 2209e710425bSDimitry Andric return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word)); 2210e710425bSDimitry Andric } 2211e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator __make_iter(size_type __pos) const _NOEXCEPT { 2212e710425bSDimitry Andric return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word)); 2213e710425bSDimitry Andric } 2214e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT { 2215e710425bSDimitry Andric return begin() + (__p - cbegin()); 2216e710425bSDimitry Andric } 22170b57cec5SDimitry Andric 2218e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __copy_assign_alloc(const vector& __v) { 2219e710425bSDimitry Andric __copy_assign_alloc( 2220e710425bSDimitry Andric __v, integral_constant<bool, __storage_traits::propagate_on_container_copy_assignment::value>()); 2221e710425bSDimitry Andric } 2222e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __copy_assign_alloc(const vector& __c, true_type) { 22230b57cec5SDimitry Andric if (__alloc() != __c.__alloc()) 22240b57cec5SDimitry Andric __vdeallocate(); 22250b57cec5SDimitry Andric __alloc() = __c.__alloc(); 22260b57cec5SDimitry Andric } 22270b57cec5SDimitry Andric 2228e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __copy_assign_alloc(const vector&, false_type) {} 22290b57cec5SDimitry Andric 2230bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign(vector& __c, false_type); 2231bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign(vector& __c, true_type) 22320b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); 2233e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign_alloc(vector& __c) 2234e710425bSDimitry Andric _NOEXCEPT_(!__storage_traits::propagate_on_container_move_assignment::value || 2235e710425bSDimitry Andric is_nothrow_move_assignable<allocator_type>::value) { 2236e710425bSDimitry Andric __move_assign_alloc( 2237e710425bSDimitry Andric __c, integral_constant<bool, __storage_traits::propagate_on_container_move_assignment::value>()); 2238e710425bSDimitry Andric } 2239e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign_alloc(vector& __c, true_type) 2240e710425bSDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) { 2241bdd1243dSDimitry Andric __alloc() = std::move(__c.__alloc()); 22420b57cec5SDimitry Andric } 22430b57cec5SDimitry Andric 2244e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign_alloc(vector&, false_type) _NOEXCEPT {} 22450b57cec5SDimitry Andric 2246bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t __hash_code() const _NOEXCEPT; 22470b57cec5SDimitry Andric 22480b57cec5SDimitry Andric friend class __bit_reference<vector>; 22490b57cec5SDimitry Andric friend class __bit_const_reference<vector>; 22500b57cec5SDimitry Andric friend class __bit_iterator<vector, false>; 22510b57cec5SDimitry Andric friend class __bit_iterator<vector, true>; 22520b57cec5SDimitry Andric friend struct __bit_array<vector>; 22530b57cec5SDimitry Andric friend struct _LIBCPP_TEMPLATE_VIS hash<vector>; 22540b57cec5SDimitry Andric}; 22550b57cec5SDimitry Andric 22560b57cec5SDimitry Andrictemplate <class _Allocator> 2257e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::__vdeallocate() _NOEXCEPT { 2258e710425bSDimitry Andric if (this->__begin_ != nullptr) { 22590b57cec5SDimitry Andric __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap()); 22600b57cec5SDimitry Andric this->__begin_ = nullptr; 22610b57cec5SDimitry Andric this->__size_ = this->__cap() = 0; 22620b57cec5SDimitry Andric } 22630b57cec5SDimitry Andric} 22640b57cec5SDimitry Andric 22650b57cec5SDimitry Andrictemplate <class _Allocator> 2266e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::size_type 2267e710425bSDimitry Andricvector<bool, _Allocator>::max_size() const _NOEXCEPT { 22680b57cec5SDimitry Andric size_type __amax = __storage_traits::max_size(__alloc()); 22690b57cec5SDimitry Andric size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always 22700b57cec5SDimitry Andric if (__nmax / __bits_per_word <= __amax) 22710b57cec5SDimitry Andric return __nmax; 22720b57cec5SDimitry Andric return __internal_cap_to_external(__amax); 22730b57cec5SDimitry Andric} 22740b57cec5SDimitry Andric 22750b57cec5SDimitry Andric// Precondition: __new_size > capacity() 22760b57cec5SDimitry Andrictemplate <class _Allocator> 2277e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::size_type 2278e710425bSDimitry Andricvector<bool, _Allocator>::__recommend(size_type __new_size) const { 22790b57cec5SDimitry Andric const size_type __ms = max_size(); 22800b57cec5SDimitry Andric if (__new_size > __ms) 22810b57cec5SDimitry Andric this->__throw_length_error(); 22820b57cec5SDimitry Andric const size_type __cap = capacity(); 22830b57cec5SDimitry Andric if (__cap >= __ms / 2) 22840b57cec5SDimitry Andric return __ms; 2285bdd1243dSDimitry Andric return std::max(2 * __cap, __align_it(__new_size)); 22860b57cec5SDimitry Andric} 22870b57cec5SDimitry Andric 22880b57cec5SDimitry Andric// Default constructs __n objects starting at __end_ 22890b57cec5SDimitry Andric// Precondition: __n > 0 22900b57cec5SDimitry Andric// Precondition: size() + __n <= capacity() 22910b57cec5SDimitry Andric// Postcondition: size() == size() + __n 22920b57cec5SDimitry Andrictemplate <class _Allocator> 2293e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void 2294e710425bSDimitry Andricvector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x) { 22950b57cec5SDimitry Andric size_type __old_size = this->__size_; 22960b57cec5SDimitry Andric this->__size_ += __n; 2297e710425bSDimitry Andric if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) { 22980b57cec5SDimitry Andric if (this->__size_ <= __bits_per_word) 22990b57cec5SDimitry Andric this->__begin_[0] = __storage_type(0); 23000b57cec5SDimitry Andric else 23010b57cec5SDimitry Andric this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0); 23020b57cec5SDimitry Andric } 2303bdd1243dSDimitry Andric std::fill_n(__make_iter(__old_size), __n, __x); 23040b57cec5SDimitry Andric} 23050b57cec5SDimitry Andric 23060b57cec5SDimitry Andrictemplate <class _Allocator> 2307fe013be4SDimitry Andrictemplate <class _InputIterator, class _Sentinel> 2308e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void 2309e710425bSDimitry Andricvector<bool, _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) { 23100b57cec5SDimitry Andric size_type __old_size = this->__size_; 2311fe013be4SDimitry Andric this->__size_ += __n; 2312e710425bSDimitry Andric if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) { 23130b57cec5SDimitry Andric if (this->__size_ <= __bits_per_word) 23140b57cec5SDimitry Andric this->__begin_[0] = __storage_type(0); 23150b57cec5SDimitry Andric else 23160b57cec5SDimitry Andric this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0); 23170b57cec5SDimitry Andric } 2318fe013be4SDimitry Andric std::__copy<_ClassicAlgPolicy>(__first, __last, __make_iter(__old_size)); 23190b57cec5SDimitry Andric} 23200b57cec5SDimitry Andric 23210b57cec5SDimitry Andrictemplate <class _Allocator> 2322e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector() 23230b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 2324e710425bSDimitry Andric : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) {} 23250b57cec5SDimitry Andric 23260b57cec5SDimitry Andrictemplate <class _Allocator> 2327e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(const allocator_type& __a) 23280b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 23290b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) 23300b57cec5SDimitry Andric#else 23310b57cec5SDimitry Andric _NOEXCEPT 23320b57cec5SDimitry Andric#endif 2333e710425bSDimitry Andric : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { 23340b57cec5SDimitry Andric} 23350b57cec5SDimitry Andric 23360b57cec5SDimitry Andrictemplate <class _Allocator> 2337e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(size_type __n) 2338e710425bSDimitry Andric : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) { 2339e710425bSDimitry Andric if (__n > 0) { 23400b57cec5SDimitry Andric __vallocate(__n); 23410b57cec5SDimitry Andric __construct_at_end(__n, false); 23420b57cec5SDimitry Andric } 23430b57cec5SDimitry Andric} 23440b57cec5SDimitry Andric 2345fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 14 23460b57cec5SDimitry Andrictemplate <class _Allocator> 2347e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a) 2348e710425bSDimitry Andric : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { 2349e710425bSDimitry Andric if (__n > 0) { 23500b57cec5SDimitry Andric __vallocate(__n); 23510b57cec5SDimitry Andric __construct_at_end(__n, false); 23520b57cec5SDimitry Andric } 23530b57cec5SDimitry Andric} 23540b57cec5SDimitry Andric#endif 23550b57cec5SDimitry Andric 23560b57cec5SDimitry Andrictemplate <class _Allocator> 2357e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x) 2358e710425bSDimitry Andric : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) { 2359e710425bSDimitry Andric if (__n > 0) { 23600b57cec5SDimitry Andric __vallocate(__n); 23610b57cec5SDimitry Andric __construct_at_end(__n, __x); 23620b57cec5SDimitry Andric } 23630b57cec5SDimitry Andric} 23640b57cec5SDimitry Andric 23650b57cec5SDimitry Andrictemplate <class _Allocator> 2366bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 23670b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a) 2368e710425bSDimitry Andric : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { 2369e710425bSDimitry Andric if (__n > 0) { 23700b57cec5SDimitry Andric __vallocate(__n); 23710b57cec5SDimitry Andric __construct_at_end(__n, __x); 23720b57cec5SDimitry Andric } 23730b57cec5SDimitry Andric} 23740b57cec5SDimitry Andric 23750b57cec5SDimitry Andrictemplate <class _Allocator> 2376c9157d92SDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> > 2377e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last) 2378e710425bSDimitry Andric : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) { 2379fe013be4SDimitry Andric __init_with_sentinel(__first, __last); 23800b57cec5SDimitry Andric} 23810b57cec5SDimitry Andric 23820b57cec5SDimitry Andrictemplate <class _Allocator> 2383c9157d92SDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> > 2384bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 2385c9157d92SDimitry Andricvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a) 2386e710425bSDimitry Andric : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { 2387fe013be4SDimitry Andric __init_with_sentinel(__first, __last); 23880b57cec5SDimitry Andric} 23890b57cec5SDimitry Andric 23900b57cec5SDimitry Andrictemplate <class _Allocator> 2391c9157d92SDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> > 2392e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last) 2393e710425bSDimitry Andric : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) { 2394fe013be4SDimitry Andric auto __n = static_cast<size_type>(std::distance(__first, __last)); 2395fe013be4SDimitry Andric __init_with_size(__first, __last, __n); 23960b57cec5SDimitry Andric} 23970b57cec5SDimitry Andric 23980b57cec5SDimitry Andrictemplate <class _Allocator> 2399c9157d92SDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> > 2400bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 2401c9157d92SDimitry Andricvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a) 2402e710425bSDimitry Andric : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { 2403fe013be4SDimitry Andric auto __n = static_cast<size_type>(std::distance(__first, __last)); 2404fe013be4SDimitry Andric __init_with_size(__first, __last, __n); 24050b57cec5SDimitry Andric} 24060b57cec5SDimitry Andric 24070b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 24080b57cec5SDimitry Andric 24090b57cec5SDimitry Andrictemplate <class _Allocator> 2410e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(initializer_list<value_type> __il) 2411e710425bSDimitry Andric : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) { 24120b57cec5SDimitry Andric size_type __n = static_cast<size_type>(__il.size()); 2413e710425bSDimitry Andric if (__n > 0) { 24140b57cec5SDimitry Andric __vallocate(__n); 2415fe013be4SDimitry Andric __construct_at_end(__il.begin(), __il.end(), __n); 24160b57cec5SDimitry Andric } 24170b57cec5SDimitry Andric} 24180b57cec5SDimitry Andric 24190b57cec5SDimitry Andrictemplate <class _Allocator> 2420bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 24210b57cec5SDimitry Andricvector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) 2422e710425bSDimitry Andric : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { 24230b57cec5SDimitry Andric size_type __n = static_cast<size_type>(__il.size()); 2424e710425bSDimitry Andric if (__n > 0) { 24250b57cec5SDimitry Andric __vallocate(__n); 2426fe013be4SDimitry Andric __construct_at_end(__il.begin(), __il.end(), __n); 24270b57cec5SDimitry Andric } 24280b57cec5SDimitry Andric} 24290b57cec5SDimitry Andric 24300b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 24310b57cec5SDimitry Andric 24320b57cec5SDimitry Andrictemplate <class _Allocator> 2433e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(const vector& __v) 24340b57cec5SDimitry Andric : __begin_(nullptr), 24350b57cec5SDimitry Andric __size_(0), 2436e710425bSDimitry Andric __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc())) { 2437e710425bSDimitry Andric if (__v.size() > 0) { 24380b57cec5SDimitry Andric __vallocate(__v.size()); 2439fe013be4SDimitry Andric __construct_at_end(__v.begin(), __v.end(), __v.size()); 24400b57cec5SDimitry Andric } 24410b57cec5SDimitry Andric} 24420b57cec5SDimitry Andric 24430b57cec5SDimitry Andrictemplate <class _Allocator> 2444e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a) 2445e710425bSDimitry Andric : __begin_(nullptr), __size_(0), __cap_alloc_(0, __a) { 2446e710425bSDimitry Andric if (__v.size() > 0) { 24470b57cec5SDimitry Andric __vallocate(__v.size()); 2448fe013be4SDimitry Andric __construct_at_end(__v.begin(), __v.end(), __v.size()); 24490b57cec5SDimitry Andric } 24500b57cec5SDimitry Andric} 24510b57cec5SDimitry Andric 24520b57cec5SDimitry Andrictemplate <class _Allocator> 2453e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>& vector<bool, _Allocator>::operator=(const vector& __v) { 2454e710425bSDimitry Andric if (this != std::addressof(__v)) { 24550b57cec5SDimitry Andric __copy_assign_alloc(__v); 2456e710425bSDimitry Andric if (__v.__size_) { 2457e710425bSDimitry Andric if (__v.__size_ > capacity()) { 24580b57cec5SDimitry Andric __vdeallocate(); 24590b57cec5SDimitry Andric __vallocate(__v.__size_); 24600b57cec5SDimitry Andric } 2461bdd1243dSDimitry Andric std::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_); 24620b57cec5SDimitry Andric } 24630b57cec5SDimitry Andric __size_ = __v.__size_; 24640b57cec5SDimitry Andric } 24650b57cec5SDimitry Andric return *this; 24660b57cec5SDimitry Andric} 24670b57cec5SDimitry Andric 24680b57cec5SDimitry Andrictemplate <class _Allocator> 2469bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(vector&& __v) 2470fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 17 24710b57cec5SDimitry Andric _NOEXCEPT 24720b57cec5SDimitry Andric#else 24730b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 24740b57cec5SDimitry Andric#endif 24750b57cec5SDimitry Andric : __begin_(__v.__begin_), 24760b57cec5SDimitry Andric __size_(__v.__size_), 2477bdd1243dSDimitry Andric __cap_alloc_(std::move(__v.__cap_alloc_)) { 24780b57cec5SDimitry Andric __v.__begin_ = nullptr; 24790b57cec5SDimitry Andric __v.__size_ = 0; 24800b57cec5SDimitry Andric __v.__cap() = 0; 24810b57cec5SDimitry Andric} 24820b57cec5SDimitry Andric 24830b57cec5SDimitry Andrictemplate <class _Allocator> 2484bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 248581ad6265SDimitry Andricvector<bool, _Allocator>::vector(vector&& __v, const __type_identity_t<allocator_type>& __a) 2486e710425bSDimitry Andric : __begin_(nullptr), __size_(0), __cap_alloc_(0, __a) { 2487e710425bSDimitry Andric if (__a == allocator_type(__v.__alloc())) { 24880b57cec5SDimitry Andric this->__begin_ = __v.__begin_; 24890b57cec5SDimitry Andric this->__size_ = __v.__size_; 24900b57cec5SDimitry Andric this->__cap() = __v.__cap(); 24910b57cec5SDimitry Andric __v.__begin_ = nullptr; 24920b57cec5SDimitry Andric __v.__cap() = __v.__size_ = 0; 2493e710425bSDimitry Andric } else if (__v.size() > 0) { 24940b57cec5SDimitry Andric __vallocate(__v.size()); 2495fe013be4SDimitry Andric __construct_at_end(__v.begin(), __v.end(), __v.size()); 24960b57cec5SDimitry Andric } 24970b57cec5SDimitry Andric} 24980b57cec5SDimitry Andric 24990b57cec5SDimitry Andrictemplate <class _Allocator> 2500e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>& 25010b57cec5SDimitry Andricvector<bool, _Allocator>::operator=(vector&& __v) 2502e710425bSDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) { 2503e710425bSDimitry Andric __move_assign(__v, integral_constant<bool, __storage_traits::propagate_on_container_move_assignment::value>()); 25040b57cec5SDimitry Andric return *this; 25050b57cec5SDimitry Andric} 25060b57cec5SDimitry Andric 25070b57cec5SDimitry Andrictemplate <class _Allocator> 2508e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::__move_assign(vector& __c, false_type) { 25090b57cec5SDimitry Andric if (__alloc() != __c.__alloc()) 25100b57cec5SDimitry Andric assign(__c.begin(), __c.end()); 25110b57cec5SDimitry Andric else 25120b57cec5SDimitry Andric __move_assign(__c, true_type()); 25130b57cec5SDimitry Andric} 25140b57cec5SDimitry Andric 25150b57cec5SDimitry Andrictemplate <class _Allocator> 2516e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::__move_assign(vector& __c, true_type) 2517e710425bSDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) { 25180b57cec5SDimitry Andric __vdeallocate(); 25190b57cec5SDimitry Andric __move_assign_alloc(__c); 25200b57cec5SDimitry Andric this->__begin_ = __c.__begin_; 25210b57cec5SDimitry Andric this->__size_ = __c.__size_; 25220b57cec5SDimitry Andric this->__cap() = __c.__cap(); 25230b57cec5SDimitry Andric __c.__begin_ = nullptr; 25240b57cec5SDimitry Andric __c.__cap() = __c.__size_ = 0; 25250b57cec5SDimitry Andric} 25260b57cec5SDimitry Andric 25270b57cec5SDimitry Andrictemplate <class _Allocator> 2528e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::assign(size_type __n, const value_type& __x) { 25290b57cec5SDimitry Andric __size_ = 0; 2530e710425bSDimitry Andric if (__n > 0) { 25310b57cec5SDimitry Andric size_type __c = capacity(); 25320b57cec5SDimitry Andric if (__n <= __c) 25330b57cec5SDimitry Andric __size_ = __n; 2534e710425bSDimitry Andric else { 2535349cc55cSDimitry Andric vector __v(get_allocator()); 25360b57cec5SDimitry Andric __v.reserve(__recommend(__n)); 25370b57cec5SDimitry Andric __v.__size_ = __n; 25380b57cec5SDimitry Andric swap(__v); 25390b57cec5SDimitry Andric } 2540bdd1243dSDimitry Andric std::fill_n(begin(), __n, __x); 25410b57cec5SDimitry Andric } 25420b57cec5SDimitry Andric} 25430b57cec5SDimitry Andric 25440b57cec5SDimitry Andrictemplate <class _Allocator> 2545c9157d92SDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> > 2546e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last) { 2547fe013be4SDimitry Andric __assign_with_sentinel(__first, __last); 2548fe013be4SDimitry Andric} 2549fe013be4SDimitry Andric 2550fe013be4SDimitry Andrictemplate <class _Allocator> 2551fe013be4SDimitry Andrictemplate <class _Iterator, class _Sentinel> 2552e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void 2553e710425bSDimitry Andricvector<bool, _Allocator>::__assign_with_sentinel(_Iterator __first, _Sentinel __last) { 25540b57cec5SDimitry Andric clear(); 25550b57cec5SDimitry Andric for (; __first != __last; ++__first) 25560b57cec5SDimitry Andric push_back(*__first); 25570b57cec5SDimitry Andric} 25580b57cec5SDimitry Andric 25590b57cec5SDimitry Andrictemplate <class _Allocator> 2560c9157d92SDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> > 2561e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) { 2562fe013be4SDimitry Andric __assign_with_size(__first, __last, std::distance(__first, __last)); 2563fe013be4SDimitry Andric} 2564fe013be4SDimitry Andric 2565fe013be4SDimitry Andrictemplate <class _Allocator> 2566fe013be4SDimitry Andrictemplate <class _ForwardIterator, class _Sentinel> 2567e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void 2568e710425bSDimitry Andricvector<bool, _Allocator>::__assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __ns) { 2569fe013be4SDimitry Andric _LIBCPP_ASSERT_VALID_INPUT_RANGE(__ns >= 0, "invalid range specified"); 2570fe013be4SDimitry Andric 25710b57cec5SDimitry Andric clear(); 2572fe013be4SDimitry Andric 25730b57cec5SDimitry Andric const size_t __n = static_cast<size_type>(__ns); 2574e710425bSDimitry Andric if (__n) { 2575e710425bSDimitry Andric if (__n > capacity()) { 25760b57cec5SDimitry Andric __vdeallocate(); 25770b57cec5SDimitry Andric __vallocate(__n); 25780b57cec5SDimitry Andric } 2579fe013be4SDimitry Andric __construct_at_end(__first, __last, __n); 25800b57cec5SDimitry Andric } 25810b57cec5SDimitry Andric} 25820b57cec5SDimitry Andric 25830b57cec5SDimitry Andrictemplate <class _Allocator> 2584e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::reserve(size_type __n) { 2585e710425bSDimitry Andric if (__n > capacity()) { 2586349cc55cSDimitry Andric if (__n > max_size()) 2587349cc55cSDimitry Andric this->__throw_length_error(); 2588349cc55cSDimitry Andric vector __v(this->get_allocator()); 25890b57cec5SDimitry Andric __v.__vallocate(__n); 2590fe013be4SDimitry Andric __v.__construct_at_end(this->begin(), this->end(), this->size()); 25910b57cec5SDimitry Andric swap(__v); 25920b57cec5SDimitry Andric } 25930b57cec5SDimitry Andric} 25940b57cec5SDimitry Andric 25950b57cec5SDimitry Andrictemplate <class _Allocator> 2596e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT { 2597e710425bSDimitry Andric if (__external_cap_to_internal(size()) > __cap()) { 2598fe013be4SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 2599e710425bSDimitry Andric try { 2600fe013be4SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 26010b57cec5SDimitry Andric vector(*this, allocator_type(__alloc())).swap(*this); 2602fe013be4SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 2603e710425bSDimitry Andric } catch (...) { 26040b57cec5SDimitry Andric } 2605fe013be4SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 26060b57cec5SDimitry Andric } 26070b57cec5SDimitry Andric} 26080b57cec5SDimitry Andric 26090b57cec5SDimitry Andrictemplate <class _Allocator> 2610e710425bSDimitry Andrictypename vector<bool, _Allocator>::reference vector<bool, _Allocator>::at(size_type __n) { 26110b57cec5SDimitry Andric if (__n >= size()) 26120b57cec5SDimitry Andric this->__throw_out_of_range(); 26130b57cec5SDimitry Andric return (*this)[__n]; 26140b57cec5SDimitry Andric} 26150b57cec5SDimitry Andric 26160b57cec5SDimitry Andrictemplate <class _Allocator> 2617e710425bSDimitry Andrictypename vector<bool, _Allocator>::const_reference vector<bool, _Allocator>::at(size_type __n) const { 26180b57cec5SDimitry Andric if (__n >= size()) 26190b57cec5SDimitry Andric this->__throw_out_of_range(); 26200b57cec5SDimitry Andric return (*this)[__n]; 26210b57cec5SDimitry Andric} 26220b57cec5SDimitry Andric 26230b57cec5SDimitry Andrictemplate <class _Allocator> 2624e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::push_back(const value_type& __x) { 26250b57cec5SDimitry Andric if (this->__size_ == this->capacity()) 26260b57cec5SDimitry Andric reserve(__recommend(this->__size_ + 1)); 26270b57cec5SDimitry Andric ++this->__size_; 26280b57cec5SDimitry Andric back() = __x; 26290b57cec5SDimitry Andric} 26300b57cec5SDimitry Andric 26310b57cec5SDimitry Andrictemplate <class _Allocator> 2632bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator 2633e710425bSDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x) { 26340b57cec5SDimitry Andric iterator __r; 2635e710425bSDimitry Andric if (size() < capacity()) { 26360b57cec5SDimitry Andric const_iterator __old_end = end(); 26370b57cec5SDimitry Andric ++__size_; 2638bdd1243dSDimitry Andric std::copy_backward(__position, __old_end, end()); 26390b57cec5SDimitry Andric __r = __const_iterator_cast(__position); 2640e710425bSDimitry Andric } else { 2641349cc55cSDimitry Andric vector __v(get_allocator()); 26420b57cec5SDimitry Andric __v.reserve(__recommend(__size_ + 1)); 26430b57cec5SDimitry Andric __v.__size_ = __size_ + 1; 2644bdd1243dSDimitry Andric __r = std::copy(cbegin(), __position, __v.begin()); 2645bdd1243dSDimitry Andric std::copy_backward(__position, cend(), __v.end()); 26460b57cec5SDimitry Andric swap(__v); 26470b57cec5SDimitry Andric } 26480b57cec5SDimitry Andric *__r = __x; 26490b57cec5SDimitry Andric return __r; 26500b57cec5SDimitry Andric} 26510b57cec5SDimitry Andric 26520b57cec5SDimitry Andrictemplate <class _Allocator> 2653bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator 2654e710425bSDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x) { 26550b57cec5SDimitry Andric iterator __r; 26560b57cec5SDimitry Andric size_type __c = capacity(); 2657e710425bSDimitry Andric if (__n <= __c && size() <= __c - __n) { 26580b57cec5SDimitry Andric const_iterator __old_end = end(); 26590b57cec5SDimitry Andric __size_ += __n; 2660bdd1243dSDimitry Andric std::copy_backward(__position, __old_end, end()); 26610b57cec5SDimitry Andric __r = __const_iterator_cast(__position); 2662e710425bSDimitry Andric } else { 2663349cc55cSDimitry Andric vector __v(get_allocator()); 26640b57cec5SDimitry Andric __v.reserve(__recommend(__size_ + __n)); 26650b57cec5SDimitry Andric __v.__size_ = __size_ + __n; 2666bdd1243dSDimitry Andric __r = std::copy(cbegin(), __position, __v.begin()); 2667bdd1243dSDimitry Andric std::copy_backward(__position, cend(), __v.end()); 26680b57cec5SDimitry Andric swap(__v); 26690b57cec5SDimitry Andric } 2670bdd1243dSDimitry Andric std::fill_n(__r, __n, __x); 26710b57cec5SDimitry Andric return __r; 26720b57cec5SDimitry Andric} 26730b57cec5SDimitry Andric 26740b57cec5SDimitry Andrictemplate <class _Allocator> 2675c9157d92SDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> > 2676e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator 2677e710425bSDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) { 2678fe013be4SDimitry Andric return __insert_with_sentinel(__position, __first, __last); 2679fe013be4SDimitry Andric} 2680fe013be4SDimitry Andric 2681fe013be4SDimitry Andrictemplate <class _Allocator> 2682fe013be4SDimitry Andrictemplate <class _InputIterator, class _Sentinel> 2683e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector<bool, _Allocator>::iterator 2684fe013be4SDimitry Andricvector<bool, _Allocator>::__insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last) { 26850b57cec5SDimitry Andric difference_type __off = __position - begin(); 26860b57cec5SDimitry Andric iterator __p = __const_iterator_cast(__position); 26870b57cec5SDimitry Andric iterator __old_end = end(); 2688e710425bSDimitry Andric for (; size() != capacity() && __first != __last; ++__first) { 26890b57cec5SDimitry Andric ++this->__size_; 26900b57cec5SDimitry Andric back() = *__first; 26910b57cec5SDimitry Andric } 2692349cc55cSDimitry Andric vector __v(get_allocator()); 2693e710425bSDimitry Andric if (__first != __last) { 2694fe013be4SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 2695e710425bSDimitry Andric try { 2696fe013be4SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 2697fe013be4SDimitry Andric __v.__assign_with_sentinel(std::move(__first), std::move(__last)); 26980b57cec5SDimitry Andric difference_type __old_size = static_cast<difference_type>(__old_end - begin()); 26990b57cec5SDimitry Andric difference_type __old_p = __p - begin(); 27000b57cec5SDimitry Andric reserve(__recommend(size() + __v.size())); 27010b57cec5SDimitry Andric __p = begin() + __old_p; 27020b57cec5SDimitry Andric __old_end = begin() + __old_size; 2703fe013be4SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 2704e710425bSDimitry Andric } catch (...) { 27050b57cec5SDimitry Andric erase(__old_end, end()); 27060b57cec5SDimitry Andric throw; 27070b57cec5SDimitry Andric } 2708fe013be4SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 27090b57cec5SDimitry Andric } 2710bdd1243dSDimitry Andric __p = std::rotate(__p, __old_end, end()); 27110b57cec5SDimitry Andric insert(__p, __v.begin(), __v.end()); 27120b57cec5SDimitry Andric return begin() + __off; 27130b57cec5SDimitry Andric} 27140b57cec5SDimitry Andric 27150b57cec5SDimitry Andrictemplate <class _Allocator> 2716c9157d92SDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> > 2717e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator 2718e710425bSDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) { 2719fe013be4SDimitry Andric return __insert_with_size(__position, __first, __last, std::distance(__first, __last)); 2720fe013be4SDimitry Andric} 2721fe013be4SDimitry Andric 2722fe013be4SDimitry Andrictemplate <class _Allocator> 2723fe013be4SDimitry Andrictemplate <class _ForwardIterator, class _Sentinel> 2724e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector<bool, _Allocator>::iterator 2725e710425bSDimitry Andricvector<bool, _Allocator>::__insert_with_size( 2726e710425bSDimitry Andric const_iterator __position, _ForwardIterator __first, _Sentinel __last, difference_type __n_signed) { 2727fe013be4SDimitry Andric _LIBCPP_ASSERT_VALID_INPUT_RANGE(__n_signed >= 0, "invalid range specified"); 27280b57cec5SDimitry Andric const size_type __n = static_cast<size_type>(__n_signed); 27290b57cec5SDimitry Andric iterator __r; 27300b57cec5SDimitry Andric size_type __c = capacity(); 2731e710425bSDimitry Andric if (__n <= __c && size() <= __c - __n) { 27320b57cec5SDimitry Andric const_iterator __old_end = end(); 27330b57cec5SDimitry Andric __size_ += __n; 2734bdd1243dSDimitry Andric std::copy_backward(__position, __old_end, end()); 27350b57cec5SDimitry Andric __r = __const_iterator_cast(__position); 2736e710425bSDimitry Andric } else { 2737349cc55cSDimitry Andric vector __v(get_allocator()); 27380b57cec5SDimitry Andric __v.reserve(__recommend(__size_ + __n)); 27390b57cec5SDimitry Andric __v.__size_ = __size_ + __n; 2740bdd1243dSDimitry Andric __r = std::copy(cbegin(), __position, __v.begin()); 2741bdd1243dSDimitry Andric std::copy_backward(__position, cend(), __v.end()); 27420b57cec5SDimitry Andric swap(__v); 27430b57cec5SDimitry Andric } 2744fe013be4SDimitry Andric std::__copy<_ClassicAlgPolicy>(__first, __last, __r); 27450b57cec5SDimitry Andric return __r; 27460b57cec5SDimitry Andric} 27470b57cec5SDimitry Andric 27480b57cec5SDimitry Andrictemplate <class _Allocator> 2749e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator 2750e710425bSDimitry Andricvector<bool, _Allocator>::erase(const_iterator __position) { 27510b57cec5SDimitry Andric iterator __r = __const_iterator_cast(__position); 2752bdd1243dSDimitry Andric std::copy(__position + 1, this->cend(), __r); 27530b57cec5SDimitry Andric --__size_; 27540b57cec5SDimitry Andric return __r; 27550b57cec5SDimitry Andric} 27560b57cec5SDimitry Andric 27570b57cec5SDimitry Andrictemplate <class _Allocator> 2758e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator 2759e710425bSDimitry Andricvector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last) { 27600b57cec5SDimitry Andric iterator __r = __const_iterator_cast(__first); 27610b57cec5SDimitry Andric difference_type __d = __last - __first; 2762bdd1243dSDimitry Andric std::copy(__last, this->cend(), __r); 27630b57cec5SDimitry Andric __size_ -= __d; 27640b57cec5SDimitry Andric return __r; 27650b57cec5SDimitry Andric} 27660b57cec5SDimitry Andric 27670b57cec5SDimitry Andrictemplate <class _Allocator> 2768e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::swap(vector& __x) 27690b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 27700b57cec5SDimitry Andric _NOEXCEPT 27710b57cec5SDimitry Andric#else 2772e710425bSDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value) 27730b57cec5SDimitry Andric#endif 27740b57cec5SDimitry Andric{ 2775bdd1243dSDimitry Andric std::swap(this->__begin_, __x.__begin_); 2776bdd1243dSDimitry Andric std::swap(this->__size_, __x.__size_); 2777bdd1243dSDimitry Andric std::swap(this->__cap(), __x.__cap()); 2778e710425bSDimitry Andric std::__swap_allocator( 2779e710425bSDimitry Andric this->__alloc(), __x.__alloc(), integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>()); 27800b57cec5SDimitry Andric} 27810b57cec5SDimitry Andric 27820b57cec5SDimitry Andrictemplate <class _Allocator> 2783e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::resize(size_type __sz, value_type __x) { 27840b57cec5SDimitry Andric size_type __cs = size(); 2785e710425bSDimitry Andric if (__cs < __sz) { 27860b57cec5SDimitry Andric iterator __r; 27870b57cec5SDimitry Andric size_type __c = capacity(); 27880b57cec5SDimitry Andric size_type __n = __sz - __cs; 2789e710425bSDimitry Andric if (__n <= __c && __cs <= __c - __n) { 27900b57cec5SDimitry Andric __r = end(); 27910b57cec5SDimitry Andric __size_ += __n; 2792e710425bSDimitry Andric } else { 2793349cc55cSDimitry Andric vector __v(get_allocator()); 27940b57cec5SDimitry Andric __v.reserve(__recommend(__size_ + __n)); 27950b57cec5SDimitry Andric __v.__size_ = __size_ + __n; 2796bdd1243dSDimitry Andric __r = std::copy(cbegin(), cend(), __v.begin()); 27970b57cec5SDimitry Andric swap(__v); 27980b57cec5SDimitry Andric } 2799bdd1243dSDimitry Andric std::fill_n(__r, __n, __x); 2800e710425bSDimitry Andric } else 28010b57cec5SDimitry Andric __size_ = __sz; 28020b57cec5SDimitry Andric} 28030b57cec5SDimitry Andric 28040b57cec5SDimitry Andrictemplate <class _Allocator> 2805e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::flip() _NOEXCEPT { 28060b57cec5SDimitry Andric // do middle whole words 28070b57cec5SDimitry Andric size_type __n = __size_; 28080b57cec5SDimitry Andric __storage_pointer __p = __begin_; 28090b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 28100b57cec5SDimitry Andric *__p = ~*__p; 28110b57cec5SDimitry Andric // do last partial word 2812e710425bSDimitry Andric if (__n > 0) { 28130b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 28140b57cec5SDimitry Andric __storage_type __b = *__p & __m; 28150b57cec5SDimitry Andric *__p &= ~__m; 28160b57cec5SDimitry Andric *__p |= ~__b & __m; 28170b57cec5SDimitry Andric } 28180b57cec5SDimitry Andric} 28190b57cec5SDimitry Andric 28200b57cec5SDimitry Andrictemplate <class _Allocator> 2821e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 bool vector<bool, _Allocator>::__invariants() const { 2822e710425bSDimitry Andric if (this->__begin_ == nullptr) { 28230b57cec5SDimitry Andric if (this->__size_ != 0 || this->__cap() != 0) 28240b57cec5SDimitry Andric return false; 2825e710425bSDimitry Andric } else { 28260b57cec5SDimitry Andric if (this->__cap() == 0) 28270b57cec5SDimitry Andric return false; 28280b57cec5SDimitry Andric if (this->__size_ > this->capacity()) 28290b57cec5SDimitry Andric return false; 28300b57cec5SDimitry Andric } 28310b57cec5SDimitry Andric return true; 28320b57cec5SDimitry Andric} 28330b57cec5SDimitry Andric 28340b57cec5SDimitry Andrictemplate <class _Allocator> 2835e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 size_t vector<bool, _Allocator>::__hash_code() const _NOEXCEPT { 28360b57cec5SDimitry Andric size_t __h = 0; 28370b57cec5SDimitry Andric // do middle whole words 28380b57cec5SDimitry Andric size_type __n = __size_; 28390b57cec5SDimitry Andric __storage_pointer __p = __begin_; 28400b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 28410b57cec5SDimitry Andric __h ^= *__p; 28420b57cec5SDimitry Andric // do last partial word 2843e710425bSDimitry Andric if (__n > 0) { 28440b57cec5SDimitry Andric const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 28450b57cec5SDimitry Andric __h ^= *__p & __m; 28460b57cec5SDimitry Andric } 28470b57cec5SDimitry Andric return __h; 28480b57cec5SDimitry Andric} 28490b57cec5SDimitry Andric 28500b57cec5SDimitry Andrictemplate <class _Allocator> 28510b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> > 2852e710425bSDimitry Andric : public __unary_function<vector<bool, _Allocator>, size_t> { 2853e710425bSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t 2854e710425bSDimitry Andric operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT { 2855e710425bSDimitry Andric return __vec.__hash_code(); 2856e710425bSDimitry Andric } 28570b57cec5SDimitry Andric}; 28580b57cec5SDimitry Andric 28590b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 2860e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI bool 2861e710425bSDimitry Andricoperator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { 28620b57cec5SDimitry Andric const typename vector<_Tp, _Allocator>::size_type __sz = __x.size(); 2863bdd1243dSDimitry Andric return __sz == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin()); 28640b57cec5SDimitry Andric} 28650b57cec5SDimitry Andric 2866fe013be4SDimitry Andric#if _LIBCPP_STD_VER <= 17 2867fe013be4SDimitry Andric 28680b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 2869e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { 28700b57cec5SDimitry Andric return !(__x == __y); 28710b57cec5SDimitry Andric} 28720b57cec5SDimitry Andric 28730b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 2874e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator<(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { 2875bdd1243dSDimitry Andric return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); 28760b57cec5SDimitry Andric} 28770b57cec5SDimitry Andric 28780b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 2879e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator>(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { 28800b57cec5SDimitry Andric return __y < __x; 28810b57cec5SDimitry Andric} 28820b57cec5SDimitry Andric 28830b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 2884e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { 28850b57cec5SDimitry Andric return !(__x < __y); 28860b57cec5SDimitry Andric} 28870b57cec5SDimitry Andric 28880b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 2889e710425bSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { 28900b57cec5SDimitry Andric return !(__y < __x); 28910b57cec5SDimitry Andric} 28920b57cec5SDimitry Andric 2893fe013be4SDimitry Andric#else // _LIBCPP_STD_VER <= 17 2894fe013be4SDimitry Andric 2895fe013be4SDimitry Andrictemplate <class _Tp, class _Allocator> 2896fe013be4SDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr __synth_three_way_result<_Tp> 2897fe013be4SDimitry Andricoperator<=>(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { 2898fe013be4SDimitry Andric return std::lexicographical_compare_three_way( 2899fe013be4SDimitry Andric __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way<_Tp, _Tp>); 2900fe013be4SDimitry Andric} 2901fe013be4SDimitry Andric 2902fe013be4SDimitry Andric#endif // _LIBCPP_STD_VER <= 17 2903fe013be4SDimitry Andric 29040b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 2905e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI void 2906e710425bSDimitry Andricswap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) { 29070b57cec5SDimitry Andric __x.swap(__y); 29080b57cec5SDimitry Andric} 29090b57cec5SDimitry Andric 2910fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 20 29110b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Up> 2912e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type 29135ffd83dbSDimitry Andricerase(vector<_Tp, _Allocator>& __c, const _Up& __v) { 29145ffd83dbSDimitry Andric auto __old_size = __c.size(); 2915bdd1243dSDimitry Andric __c.erase(std::remove(__c.begin(), __c.end(), __v), __c.end()); 29165ffd83dbSDimitry Andric return __old_size - __c.size(); 29175ffd83dbSDimitry Andric} 29180b57cec5SDimitry Andric 29190b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Predicate> 2920e710425bSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type 29215ffd83dbSDimitry Andricerase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) { 29225ffd83dbSDimitry Andric auto __old_size = __c.size(); 2923bdd1243dSDimitry Andric __c.erase(std::remove_if(__c.begin(), __c.end(), __pred), __c.end()); 29245ffd83dbSDimitry Andric return __old_size - __c.size(); 29255ffd83dbSDimitry Andric} 292681ad6265SDimitry Andric 292781ad6265SDimitry Andrictemplate <> 2928bdd1243dSDimitry Andricinline constexpr bool __format::__enable_insertable<vector<char>> = true; 292981ad6265SDimitry Andric# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 293081ad6265SDimitry Andrictemplate <> 2931bdd1243dSDimitry Andricinline constexpr bool __format::__enable_insertable<vector<wchar_t>> = true; 29320b57cec5SDimitry Andric# endif 29330b57cec5SDimitry Andric 2934fe013be4SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 293581ad6265SDimitry Andric 2936fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 23 2937fe013be4SDimitry Andrictemplate <class _Tp, class _CharT> 2938bdd1243dSDimitry Andric// Since is-vector-bool-reference is only used once it's inlined here. 2939bdd1243dSDimitry Andric requires same_as<typename _Tp::__container, vector<bool, typename _Tp::__container::allocator_type>> 2940fe013be4SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS formatter<_Tp, _CharT> { 2941bdd1243dSDimitry Andricprivate: 2942fe013be4SDimitry Andric formatter<bool, _CharT> __underlying_; 2943bdd1243dSDimitry Andric 2944bdd1243dSDimitry Andricpublic: 2945bdd1243dSDimitry Andric template <class _ParseContext> 2946bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { 2947bdd1243dSDimitry Andric return __underlying_.parse(__ctx); 2948bdd1243dSDimitry Andric } 2949bdd1243dSDimitry Andric 2950bdd1243dSDimitry Andric template <class _FormatContext> 2951bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(const _Tp& __ref, _FormatContext& __ctx) const { 2952bdd1243dSDimitry Andric return __underlying_.format(__ref, __ctx); 2953bdd1243dSDimitry Andric } 2954bdd1243dSDimitry Andric}; 2955fe013be4SDimitry Andric#endif // _LIBCPP_STD_VER >= 23 2956bdd1243dSDimitry Andric 29570b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 29580b57cec5SDimitry Andric 2959fe013be4SDimitry Andric#if _LIBCPP_STD_VER >= 17 2960bdd1243dSDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 2961bdd1243dSDimitry Andricnamespace pmr { 2962bdd1243dSDimitry Andrictemplate <class _ValueT> 2963fe013be4SDimitry Andricusing vector _LIBCPP_AVAILABILITY_PMR = std::vector<_ValueT, polymorphic_allocator<_ValueT>>; 2964bdd1243dSDimitry Andric} // namespace pmr 2965bdd1243dSDimitry Andric_LIBCPP_END_NAMESPACE_STD 2966bdd1243dSDimitry Andric#endif 2967bdd1243dSDimitry Andric 29680b57cec5SDimitry Andric_LIBCPP_POP_MACROS 29690b57cec5SDimitry Andric 2970bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 2971bdd1243dSDimitry Andric# include <algorithm> 2972bdd1243dSDimitry Andric# include <atomic> 2973bdd1243dSDimitry Andric# include <concepts> 2974fe013be4SDimitry Andric# include <cstdlib> 2975fe013be4SDimitry Andric# include <type_traits> 2976bdd1243dSDimitry Andric# include <typeinfo> 2977bdd1243dSDimitry Andric# include <utility> 2978bdd1243dSDimitry Andric#endif 2979bdd1243dSDimitry Andric 29800b57cec5SDimitry Andric#endif // _LIBCPP_VECTOR 2981