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 13*5f757f3fSDimitry Andric// clang-format off 14*5f757f3fSDimitry 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()); 4606c3fb27SDimitry Andric template<container-compatible-range<T> R> 4706c3fb27SDimitry 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); 6206c3fb27SDimitry Andric template<container-compatible-range<T> R> 6306c3fb27SDimitry 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 10806c3fb27SDimitry Andric template<container-compatible-range<T> R> 10906c3fb27SDimitry 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); 11806c3fb27SDimitry Andric template<container-compatible-range<T> R> 11906c3fb27SDimitry 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()); 17806c3fb27SDimitry Andric template<container-compatible-range<bool> R> 17906c3fb27SDimitry 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); 19406c3fb27SDimitry Andric template<container-compatible-range<T> R> 19506c3fb27SDimitry 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 23506c3fb27SDimitry Andric template<container-compatible-range<T> R> 23606c3fb27SDimitry 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); 24406c3fb27SDimitry Andric template<container-compatible-range<T> R> 24506c3fb27SDimitry 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 26806c3fb27SDimitry Andrictemplate<ranges::input_range R, class Allocator = allocator<ranges::range_value_t<R>>> 26906c3fb27SDimitry Andric vector(from_range_t, R&&, Allocator = Allocator()) 27006c3fb27SDimitry Andric -> vector<ranges::range_value_t<R>, Allocator>; // C++23 27106c3fb27SDimitry Andric 2720b57cec5SDimitry Andrictemplate <class Allocator> struct hash<std::vector<bool, Allocator>>; 2730b57cec5SDimitry Andric 27406c3fb27SDimitry Andrictemplate <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y); // constexpr since C++20 27506c3fb27SDimitry Andrictemplate <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); // removed in C++20 27606c3fb27SDimitry Andrictemplate <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y); // removed in C++20 27706c3fb27SDimitry Andrictemplate <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y); // removed in C++20 27806c3fb27SDimitry Andrictemplate <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); // removed in C++20 27906c3fb27SDimitry Andrictemplate <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); // removed in C++20 28006c3fb27SDimitry Andrictemplate <class T, class Allocator> constexpr 28106c3fb27SDimitry Andric constexpr synth-three-way-result<T> operator<=>(const vector<T, Allocator>& x, 28206c3fb27SDimitry 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 29006c3fb27SDimitry 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 29306c3fb27SDimitry 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 306*5f757f3fSDimitry Andric// clang-format on 307*5f757f3fSDimitry Andric 30881ad6265SDimitry Andric#include <__algorithm/copy.h> 30981ad6265SDimitry Andric#include <__algorithm/equal.h> 31081ad6265SDimitry Andric#include <__algorithm/fill_n.h> 31106c3fb27SDimitry Andric#include <__algorithm/iterator_operations.h> 31281ad6265SDimitry Andric#include <__algorithm/lexicographical_compare.h> 31306c3fb27SDimitry 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 31906c3fb27SDimitry 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> 32506c3fb27SDimitry 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> 32906c3fb27SDimitry 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> 33306c3fb27SDimitry Andric#include <__memory/addressof.h> 33481ad6265SDimitry Andric#include <__memory/allocate_at_least.h> 33506c3fb27SDimitry 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> 34106c3fb27SDimitry Andric#include <__ranges/access.h> 34206c3fb27SDimitry Andric#include <__ranges/concepts.h> 34306c3fb27SDimitry Andric#include <__ranges/container_compatible_range.h> 34406c3fb27SDimitry Andric#include <__ranges/from_range.h> 34506c3fb27SDimitry Andric#include <__ranges/size.h> 346fe6060f1SDimitry Andric#include <__split_buffer> 347bdd1243dSDimitry Andric#include <__type_traits/is_allocator.h> 34806c3fb27SDimitry Andric#include <__type_traits/is_constructible.h> 34906c3fb27SDimitry Andric#include <__type_traits/is_nothrow_move_assignable.h> 350bdd1243dSDimitry Andric#include <__type_traits/noexcept_move_assign_container.h> 35106c3fb27SDimitry 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> 35506c3fb27SDimitry 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> */> 3870b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector 3880b57cec5SDimitry Andric{ 3890b57cec5SDimitry Andricprivate: 3900b57cec5SDimitry Andric typedef allocator<_Tp> __default_allocator_type; 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 415bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 4160b57cec5SDimitry Andric vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 4170b57cec5SDimitry Andric { 4180b57cec5SDimitry Andric } 419bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(const allocator_type& __a) 4200b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 4210b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) 4220b57cec5SDimitry Andric#else 4230b57cec5SDimitry Andric _NOEXCEPT 4240b57cec5SDimitry Andric#endif 425d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 4260b57cec5SDimitry Andric { 4270b57cec5SDimitry Andric } 428bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n); 42906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 430bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n, const allocator_type& __a); 4310b57cec5SDimitry Andric#endif 432bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(size_type __n, const value_type& __x); 4334824e7fdSDimitry Andric 4344824e7fdSDimitry Andric template <class = __enable_if_t<__is_allocator<_Allocator>::value> > 435bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 4364824e7fdSDimitry Andric vector(size_type __n, const value_type& __x, const allocator_type& __a) 437d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 4384824e7fdSDimitry Andric { 4394824e7fdSDimitry Andric if (__n > 0) 4404824e7fdSDimitry Andric { 4414824e7fdSDimitry Andric __vallocate(__n); 4424824e7fdSDimitry Andric __construct_at_end(__n, __x); 4434824e7fdSDimitry Andric } 4444824e7fdSDimitry Andric } 4454824e7fdSDimitry Andric 446bdd1243dSDimitry Andric template <class _InputIterator, 44706c3fb27SDimitry 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 vector(_InputIterator __first, _InputIterator __last); 451bdd1243dSDimitry Andric template <class _InputIterator, 45206c3fb27SDimitry Andric __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value && 453bdd1243dSDimitry Andric is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value, 454bdd1243dSDimitry Andric int> = 0> 455bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 456bdd1243dSDimitry Andric vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a); 457bdd1243dSDimitry Andric 458bdd1243dSDimitry Andric template < 459bdd1243dSDimitry Andric class _ForwardIterator, 46006c3fb27SDimitry Andric __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value && 461bdd1243dSDimitry Andric is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value, 462bdd1243dSDimitry Andric int> = 0> 463bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(_ForwardIterator __first, _ForwardIterator __last); 464bdd1243dSDimitry Andric 465bdd1243dSDimitry Andric template <class _ForwardIterator, 46606c3fb27SDimitry Andric __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value && 467bdd1243dSDimitry Andric is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value, 468bdd1243dSDimitry Andric int> = 0> 469bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 470bdd1243dSDimitry Andric vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a); 4710b57cec5SDimitry Andric 47206c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 47306c3fb27SDimitry Andric template <_ContainerCompatibleRange<_Tp> _Range> 47406c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr vector(from_range_t, _Range&& __range, 47506c3fb27SDimitry Andric const allocator_type& __alloc = allocator_type()) : __end_cap_(nullptr, __alloc) { 47606c3fb27SDimitry Andric if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) { 47706c3fb27SDimitry Andric auto __n = static_cast<size_type>(ranges::distance(__range)); 47806c3fb27SDimitry Andric __init_with_size(ranges::begin(__range), ranges::end(__range), __n); 47906c3fb27SDimitry Andric 48006c3fb27SDimitry Andric } else { 48106c3fb27SDimitry Andric __init_with_sentinel(ranges::begin(__range), ranges::end(__range)); 48206c3fb27SDimitry Andric } 48306c3fb27SDimitry Andric } 48406c3fb27SDimitry Andric#endif 48506c3fb27SDimitry Andric 48650d7464cSDimitry Andricprivate: 48750d7464cSDimitry Andric class __destroy_vector { 48850d7464cSDimitry Andric public: 48906c3fb27SDimitry Andric _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI __destroy_vector(vector& __vec) : __vec_(__vec) {} 490349cc55cSDimitry Andric 491bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() { 49250d7464cSDimitry Andric if (__vec_.__begin_ != nullptr) { 49350d7464cSDimitry Andric __vec_.__clear(); 49406c3fb27SDimitry Andric __vec_.__annotate_delete(); 49550d7464cSDimitry Andric __alloc_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.capacity()); 496349cc55cSDimitry Andric } 4970b57cec5SDimitry Andric } 4980b57cec5SDimitry Andric 49950d7464cSDimitry Andric private: 50050d7464cSDimitry Andric vector& __vec_; 50150d7464cSDimitry Andric }; 50250d7464cSDimitry Andric 50350d7464cSDimitry Andricpublic: 504bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~vector() { __destroy_vector(*this)(); } 50550d7464cSDimitry Andric 506bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(const vector& __x); 507bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(const vector& __x, const __type_identity_t<allocator_type>& __a); 508bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 5090b57cec5SDimitry Andric vector& operator=(const vector& __x); 5100b57cec5SDimitry Andric 5110b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 512bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 5130b57cec5SDimitry Andric vector(initializer_list<value_type> __il); 5140b57cec5SDimitry Andric 515bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 5160b57cec5SDimitry Andric vector(initializer_list<value_type> __il, const allocator_type& __a); 5170b57cec5SDimitry Andric 518bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 51981ad6265SDimitry Andric vector& operator=(initializer_list<value_type> __il) 52081ad6265SDimitry Andric {assign(__il.begin(), __il.end()); return *this;} 52181ad6265SDimitry Andric#endif // !_LIBCPP_CXX03_LANG 52281ad6265SDimitry Andric 523bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 5240b57cec5SDimitry Andric vector(vector&& __x) 52506c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 52681ad6265SDimitry Andric noexcept; 5270b57cec5SDimitry Andric#else 5280b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); 5290b57cec5SDimitry Andric#endif 5300b57cec5SDimitry Andric 531bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 53281ad6265SDimitry Andric vector(vector&& __x, const __type_identity_t<allocator_type>& __a); 533bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 5340b57cec5SDimitry Andric vector& operator=(vector&& __x) 5350b57cec5SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); 5360b57cec5SDimitry Andric 537bdd1243dSDimitry Andric template <class _InputIterator, 53806c3fb27SDimitry Andric __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value && 539bdd1243dSDimitry Andric is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value, 540bdd1243dSDimitry Andric int> = 0> 541bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(_InputIterator __first, _InputIterator __last); 542bdd1243dSDimitry Andric template < 543bdd1243dSDimitry Andric class _ForwardIterator, 54406c3fb27SDimitry Andric __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value && 545bdd1243dSDimitry Andric is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value, 546bdd1243dSDimitry Andric int> = 0> 547bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(_ForwardIterator __first, _ForwardIterator __last); 5480b57cec5SDimitry Andric 54906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 55006c3fb27SDimitry Andric template <_ContainerCompatibleRange<_Tp> _Range> 55106c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 55206c3fb27SDimitry Andric constexpr void assign_range(_Range&& __range) { 55306c3fb27SDimitry Andric if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) { 55406c3fb27SDimitry Andric auto __n = static_cast<size_type>(ranges::distance(__range)); 55506c3fb27SDimitry Andric __assign_with_size(ranges::begin(__range), ranges::end(__range), __n); 55606c3fb27SDimitry Andric 55706c3fb27SDimitry Andric } else { 55806c3fb27SDimitry Andric __assign_with_sentinel(ranges::begin(__range), ranges::end(__range)); 55906c3fb27SDimitry Andric } 56006c3fb27SDimitry Andric } 56106c3fb27SDimitry Andric#endif 56206c3fb27SDimitry Andric 563bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const_reference __u); 5640b57cec5SDimitry Andric 5650b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 566bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 5670b57cec5SDimitry Andric void assign(initializer_list<value_type> __il) 5680b57cec5SDimitry Andric {assign(__il.begin(), __il.end());} 5690b57cec5SDimitry Andric#endif 5700b57cec5SDimitry Andric 571bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 5720b57cec5SDimitry Andric allocator_type get_allocator() const _NOEXCEPT 5730b57cec5SDimitry Andric {return this->__alloc();} 5740b57cec5SDimitry Andric 575bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT; 576bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT; 577bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT; 578bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT; 5790b57cec5SDimitry Andric 580bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 5810b57cec5SDimitry Andric reverse_iterator rbegin() _NOEXCEPT 5820b57cec5SDimitry Andric {return reverse_iterator(end());} 583bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 5840b57cec5SDimitry Andric const_reverse_iterator rbegin() const _NOEXCEPT 5850b57cec5SDimitry Andric {return const_reverse_iterator(end());} 586bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 5870b57cec5SDimitry Andric reverse_iterator rend() _NOEXCEPT 5880b57cec5SDimitry Andric {return reverse_iterator(begin());} 589bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 5900b57cec5SDimitry Andric const_reverse_iterator rend() const _NOEXCEPT 5910b57cec5SDimitry Andric {return const_reverse_iterator(begin());} 5920b57cec5SDimitry Andric 593bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 5940b57cec5SDimitry Andric const_iterator cbegin() const _NOEXCEPT 5950b57cec5SDimitry Andric {return begin();} 596bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 5970b57cec5SDimitry Andric const_iterator cend() const _NOEXCEPT 5980b57cec5SDimitry Andric {return end();} 599bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 6000b57cec5SDimitry Andric const_reverse_iterator crbegin() const _NOEXCEPT 6010b57cec5SDimitry Andric {return rbegin();} 602bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 6030b57cec5SDimitry Andric const_reverse_iterator crend() const _NOEXCEPT 6040b57cec5SDimitry Andric {return rend();} 6050b57cec5SDimitry Andric 606bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 6070b57cec5SDimitry Andric size_type size() const _NOEXCEPT 6080b57cec5SDimitry Andric {return static_cast<size_type>(this->__end_ - this->__begin_);} 609bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 6100b57cec5SDimitry Andric size_type capacity() const _NOEXCEPT 611349cc55cSDimitry Andric {return static_cast<size_type>(__end_cap() - this->__begin_);} 612bdd1243dSDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 6130b57cec5SDimitry Andric bool empty() const _NOEXCEPT 6140b57cec5SDimitry Andric {return this->__begin_ == this->__end_;} 615bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT; 616bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void reserve(size_type __n); 617bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void shrink_to_fit() _NOEXCEPT; 6180b57cec5SDimitry Andric 619bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference operator[](size_type __n) _NOEXCEPT; 620bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference operator[](size_type __n) const _NOEXCEPT; 621bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference at(size_type __n); 622bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __n) const; 6230b57cec5SDimitry Andric 624bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference front() _NOEXCEPT 6250b57cec5SDimitry Andric { 62606c3fb27SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "front() called on an empty vector"); 6270b57cec5SDimitry Andric return *this->__begin_; 6280b57cec5SDimitry Andric } 629bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference front() const _NOEXCEPT 6300b57cec5SDimitry Andric { 63106c3fb27SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "front() called on an empty vector"); 6320b57cec5SDimitry Andric return *this->__begin_; 6330b57cec5SDimitry Andric } 634bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference back() _NOEXCEPT 6350b57cec5SDimitry Andric { 63606c3fb27SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "back() called on an empty vector"); 6370b57cec5SDimitry Andric return *(this->__end_ - 1); 6380b57cec5SDimitry Andric } 639bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference back() const _NOEXCEPT 6400b57cec5SDimitry Andric { 64106c3fb27SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "back() called on an empty vector"); 6420b57cec5SDimitry Andric return *(this->__end_ - 1); 6430b57cec5SDimitry Andric } 6440b57cec5SDimitry Andric 645bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 6460b57cec5SDimitry Andric value_type* data() _NOEXCEPT 647bdd1243dSDimitry Andric {return std::__to_address(this->__begin_);} 64861cfbce3SDimitry Andric 649bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 6500b57cec5SDimitry Andric const value_type* data() const _NOEXCEPT 651bdd1243dSDimitry Andric {return std::__to_address(this->__begin_);} 6520b57cec5SDimitry Andric 653bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_back(const_reference __x); 6540b57cec5SDimitry Andric 655bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __x); 6560b57cec5SDimitry Andric 6570b57cec5SDimitry Andric template <class... _Args> 658bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 65906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 6600b57cec5SDimitry Andric reference emplace_back(_Args&&... __args); 6610b57cec5SDimitry Andric#else 6620b57cec5SDimitry Andric void emplace_back(_Args&&... __args); 6630b57cec5SDimitry Andric#endif 6640b57cec5SDimitry Andric 66506c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 66606c3fb27SDimitry Andric template <_ContainerCompatibleRange<_Tp> _Range> 66706c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 66806c3fb27SDimitry Andric constexpr void append_range(_Range&& __range) { 66906c3fb27SDimitry Andric insert_range(end(), std::forward<_Range>(__range)); 67006c3fb27SDimitry Andric } 67106c3fb27SDimitry Andric#endif 67206c3fb27SDimitry Andric 673bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 6740b57cec5SDimitry Andric void pop_back(); 6750b57cec5SDimitry Andric 676bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, const_reference __x); 6770b57cec5SDimitry Andric 678bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, value_type&& __x); 6790b57cec5SDimitry Andric template <class... _Args> 680bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __position, _Args&&... __args); 6810b57cec5SDimitry Andric 682bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 683bdd1243dSDimitry Andric iterator insert(const_iterator __position, size_type __n, const_reference __x); 684bdd1243dSDimitry Andric 685bdd1243dSDimitry Andric template <class _InputIterator, 68606c3fb27SDimitry Andric __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value && 687bdd1243dSDimitry Andric is_constructible< value_type, typename iterator_traits<_InputIterator>::reference>::value, 688bdd1243dSDimitry Andric int> = 0> 689bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator 6900b57cec5SDimitry Andric insert(const_iterator __position, _InputIterator __first, _InputIterator __last); 691bdd1243dSDimitry Andric 69206c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 69306c3fb27SDimitry Andric template <_ContainerCompatibleRange<_Tp> _Range> 69406c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 69506c3fb27SDimitry Andric constexpr iterator insert_range(const_iterator __position, _Range&& __range) { 69606c3fb27SDimitry Andric if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) { 69706c3fb27SDimitry Andric auto __n = static_cast<size_type>(ranges::distance(__range)); 69806c3fb27SDimitry Andric return __insert_with_size(__position, ranges::begin(__range), ranges::end(__range), __n); 69906c3fb27SDimitry Andric 70006c3fb27SDimitry Andric } else { 70106c3fb27SDimitry Andric return __insert_with_sentinel(__position, ranges::begin(__range), ranges::end(__range)); 70206c3fb27SDimitry Andric } 70306c3fb27SDimitry Andric } 70406c3fb27SDimitry Andric#endif 70506c3fb27SDimitry Andric 706bdd1243dSDimitry Andric template < 707bdd1243dSDimitry Andric class _ForwardIterator, 70806c3fb27SDimitry Andric __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value && 709bdd1243dSDimitry Andric is_constructible< value_type, typename iterator_traits<_ForwardIterator>::reference>::value, 710bdd1243dSDimitry Andric int> = 0> 711bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator 7120b57cec5SDimitry Andric insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); 7130b57cec5SDimitry Andric 7140b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 715bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 7160b57cec5SDimitry Andric iterator insert(const_iterator __position, initializer_list<value_type> __il) 7170b57cec5SDimitry Andric {return insert(__position, __il.begin(), __il.end());} 7180b57cec5SDimitry Andric#endif 7190b57cec5SDimitry Andric 720bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __position); 721bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last); 7220b57cec5SDimitry Andric 723bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 7240b57cec5SDimitry Andric void clear() _NOEXCEPT 7250b57cec5SDimitry Andric { 7260b57cec5SDimitry Andric size_type __old_size = size(); 727349cc55cSDimitry Andric __clear(); 7280b57cec5SDimitry Andric __annotate_shrink(__old_size); 7290b57cec5SDimitry Andric } 7300b57cec5SDimitry Andric 731bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz); 732bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz, const_reference __x); 7330b57cec5SDimitry Andric 734bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void swap(vector&) 7350b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 7360b57cec5SDimitry Andric _NOEXCEPT; 7370b57cec5SDimitry Andric#else 7380b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 7390b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value); 7400b57cec5SDimitry Andric#endif 7410b57cec5SDimitry Andric 742bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool __invariants() const; 7430b57cec5SDimitry Andric 7440b57cec5SDimitry Andricprivate: 745d56accc7SDimitry Andric pointer __begin_ = nullptr; 746d56accc7SDimitry Andric pointer __end_ = nullptr; 747d56accc7SDimitry Andric __compressed_pair<pointer, allocator_type> __end_cap_ = 748d56accc7SDimitry Andric __compressed_pair<pointer, allocator_type>(nullptr, __default_init_tag()); 749d56accc7SDimitry Andric 75081ad6265SDimitry Andric // Allocate space for __n objects 75181ad6265SDimitry Andric // throws length_error if __n > max_size() 75281ad6265SDimitry Andric // throws (probably bad_alloc) if memory run out 75381ad6265SDimitry Andric // Precondition: __begin_ == __end_ == __end_cap() == 0 75481ad6265SDimitry Andric // Precondition: __n > 0 75581ad6265SDimitry Andric // Postcondition: capacity() >= __n 75681ad6265SDimitry Andric // Postcondition: size() == 0 757bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) { 75881ad6265SDimitry Andric if (__n > max_size()) 75981ad6265SDimitry Andric __throw_length_error(); 76081ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __n); 76181ad6265SDimitry Andric __begin_ = __allocation.ptr; 76281ad6265SDimitry Andric __end_ = __allocation.ptr; 76381ad6265SDimitry Andric __end_cap() = __begin_ + __allocation.count; 76481ad6265SDimitry Andric __annotate_new(0); 76581ad6265SDimitry Andric } 76681ad6265SDimitry Andric 767bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __vdeallocate() _NOEXCEPT; 768bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type __recommend(size_type __new_size) const; 769bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_at_end(size_type __n); 770bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 7710b57cec5SDimitry Andric void __construct_at_end(size_type __n, const_reference __x); 772bdd1243dSDimitry Andric 77306c3fb27SDimitry Andric template <class _InputIterator, class _Sentinel> 77406c3fb27SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 77506c3fb27SDimitry Andric void __init_with_size(_InputIterator __first, _Sentinel __last, size_type __n) { 77606c3fb27SDimitry Andric auto __guard = std::__make_exception_guard(__destroy_vector(*this)); 77706c3fb27SDimitry Andric 77806c3fb27SDimitry Andric if (__n > 0) { 77906c3fb27SDimitry Andric __vallocate(__n); 78006c3fb27SDimitry Andric __construct_at_end(__first, __last, __n); 78106c3fb27SDimitry Andric } 78206c3fb27SDimitry Andric 78306c3fb27SDimitry Andric __guard.__complete(); 78406c3fb27SDimitry Andric } 78506c3fb27SDimitry Andric 78606c3fb27SDimitry Andric template <class _InputIterator, class _Sentinel> 78706c3fb27SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 78806c3fb27SDimitry Andric void __init_with_sentinel(_InputIterator __first, _Sentinel __last) { 78906c3fb27SDimitry Andric auto __guard = std::__make_exception_guard(__destroy_vector(*this)); 79006c3fb27SDimitry Andric 79106c3fb27SDimitry Andric for (; __first != __last; ++__first) 79206c3fb27SDimitry Andric emplace_back(*__first); 79306c3fb27SDimitry Andric 79406c3fb27SDimitry Andric __guard.__complete(); 79506c3fb27SDimitry Andric } 79606c3fb27SDimitry Andric 79706c3fb27SDimitry Andric template <class _Iterator, class _Sentinel> 79806c3fb27SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 79906c3fb27SDimitry Andric void __assign_with_sentinel(_Iterator __first, _Sentinel __last); 80006c3fb27SDimitry Andric 80106c3fb27SDimitry Andric template <class _ForwardIterator, class _Sentinel> 80206c3fb27SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 80306c3fb27SDimitry Andric void __assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __n); 80406c3fb27SDimitry Andric 80506c3fb27SDimitry Andric template <class _InputIterator, class _Sentinel> 80606c3fb27SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 80706c3fb27SDimitry Andric iterator __insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last); 80806c3fb27SDimitry Andric 80906c3fb27SDimitry Andric template <class _Iterator, class _Sentinel> 81006c3fb27SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 81106c3fb27SDimitry Andric iterator __insert_with_size(const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n); 81206c3fb27SDimitry Andric 81306c3fb27SDimitry Andric template <class _InputIterator, class _Sentinel> 81406c3fb27SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 81506c3fb27SDimitry Andric void __construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n); 816bdd1243dSDimitry Andric 817bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __append(size_type __n); 818bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __append(size_type __n, const_reference __x); 819bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 82006c3fb27SDimitry Andric iterator __make_iter(pointer __p) _NOEXCEPT { return iterator(__p); } 821bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 82206c3fb27SDimitry Andric const_iterator __make_iter(const_pointer __p) const _NOEXCEPT { return const_iterator(__p); } 823bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v); 824bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p); 825bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_range(pointer __from_s, pointer __from_e, pointer __to); 826bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, true_type) 8270b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); 828bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, false_type) 8290b57cec5SDimitry Andric _NOEXCEPT_(__alloc_traits::is_always_equal::value); 830bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 8310b57cec5SDimitry Andric void __destruct_at_end(pointer __new_last) _NOEXCEPT 8320b57cec5SDimitry Andric { 8330b57cec5SDimitry Andric size_type __old_size = size(); 834349cc55cSDimitry Andric __base_destruct_at_end(__new_last); 8350b57cec5SDimitry Andric __annotate_shrink(__old_size); 8360b57cec5SDimitry Andric } 8370b57cec5SDimitry Andric 8380b57cec5SDimitry Andric template <class _Up> 839bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 840*5f757f3fSDimitry Andric inline pointer __push_back_slow_path(_Up&& __x); 8410b57cec5SDimitry Andric 8420b57cec5SDimitry Andric template <class... _Args> 843bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 844*5f757f3fSDimitry Andric inline pointer __emplace_back_slow_path(_Args&&... __args); 8450b57cec5SDimitry Andric 8460b57cec5SDimitry Andric // The following functions are no-ops outside of AddressSanitizer mode. 84706c3fb27SDimitry Andric // We call annotations for every allocator, unless explicitly disabled. 84806c3fb27SDimitry Andric // 84906c3fb27SDimitry Andric // To disable annotations for a particular allocator, change value of 85006c3fb27SDimitry Andric // __asan_annotate_container_with_allocator to false. 85106c3fb27SDimitry Andric // For more details, see the "Using libc++" documentation page or 85206c3fb27SDimitry Andric // the documentation for __sanitizer_annotate_contiguous_container. 853*5f757f3fSDimitry Andric 854*5f757f3fSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 855*5f757f3fSDimitry Andric void __annotate_contiguous_container(const void *__beg, 856*5f757f3fSDimitry Andric const void *__end, 8570b57cec5SDimitry Andric const void *__old_mid, 8580b57cec5SDimitry Andric const void *__new_mid) const 8590b57cec5SDimitry Andric { 860*5f757f3fSDimitry Andric (void)__beg; 861*5f757f3fSDimitry Andric (void)__end; 862*5f757f3fSDimitry Andric (void)__old_mid; 863*5f757f3fSDimitry Andric (void)__new_mid; 864*5f757f3fSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN 86506c3fb27SDimitry Andric if (!__libcpp_is_constant_evaluated() && __beg != nullptr && __asan_annotate_container_with_allocator<_Allocator>::value) 8660b57cec5SDimitry Andric __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid); 8670b57cec5SDimitry Andric#endif 868*5f757f3fSDimitry Andric } 869*5f757f3fSDimitry Andric 870bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 871e40139ffSDimitry Andric void __annotate_new(size_type __current_size) const _NOEXCEPT { 8720b57cec5SDimitry Andric __annotate_contiguous_container(data(), data() + capacity(), 8730b57cec5SDimitry Andric data() + capacity(), data() + __current_size); 8740b57cec5SDimitry Andric } 8750b57cec5SDimitry Andric 876bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 877e40139ffSDimitry Andric void __annotate_delete() const _NOEXCEPT { 8780b57cec5SDimitry Andric __annotate_contiguous_container(data(), data() + capacity(), 8790b57cec5SDimitry Andric data() + size(), data() + capacity()); 8800b57cec5SDimitry Andric } 8810b57cec5SDimitry Andric 882bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 883e40139ffSDimitry Andric void __annotate_increase(size_type __n) const _NOEXCEPT 8840b57cec5SDimitry Andric { 8850b57cec5SDimitry Andric __annotate_contiguous_container(data(), data() + capacity(), 8860b57cec5SDimitry Andric data() + size(), data() + size() + __n); 8870b57cec5SDimitry Andric } 8880b57cec5SDimitry Andric 889bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 890e40139ffSDimitry Andric void __annotate_shrink(size_type __old_size) const _NOEXCEPT 8910b57cec5SDimitry Andric { 8920b57cec5SDimitry Andric __annotate_contiguous_container(data(), data() + capacity(), 8930b57cec5SDimitry Andric data() + __old_size, data() + size()); 8940b57cec5SDimitry Andric } 8950b57cec5SDimitry Andric 896e40139ffSDimitry Andric struct _ConstructTransaction { 897bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 898e40139ffSDimitry Andric explicit _ConstructTransaction(vector &__v, size_type __n) 899e40139ffSDimitry Andric : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) { 900e40139ffSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN 901e40139ffSDimitry Andric __v_.__annotate_increase(__n); 902e40139ffSDimitry Andric#endif 903e40139ffSDimitry Andric } 904bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~_ConstructTransaction() { 905e40139ffSDimitry Andric __v_.__end_ = __pos_; 906e40139ffSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN 907e40139ffSDimitry Andric if (__pos_ != __new_end_) { 908e40139ffSDimitry Andric __v_.__annotate_shrink(__new_end_ - __v_.__begin_); 909e40139ffSDimitry Andric } 910e40139ffSDimitry Andric#endif 911e40139ffSDimitry Andric } 912e40139ffSDimitry Andric 913e40139ffSDimitry Andric vector &__v_; 914e40139ffSDimitry Andric pointer __pos_; 915e40139ffSDimitry Andric const_pointer const __new_end_; 916e40139ffSDimitry Andric 917e40139ffSDimitry Andric private: 918e40139ffSDimitry Andric _ConstructTransaction(_ConstructTransaction const&) = delete; 919e40139ffSDimitry Andric _ConstructTransaction& operator=(_ConstructTransaction const&) = delete; 920e40139ffSDimitry Andric }; 921e40139ffSDimitry Andric 922e40139ffSDimitry Andric template <class ..._Args> 923bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 924e40139ffSDimitry Andric void __construct_one_at_end(_Args&& ...__args) { 925e40139ffSDimitry Andric _ConstructTransaction __tx(*this, 1); 926bdd1243dSDimitry Andric __alloc_traits::construct(this->__alloc(), std::__to_address(__tx.__pos_), 927bdd1243dSDimitry Andric std::forward<_Args>(__args)...); 928e40139ffSDimitry Andric ++__tx.__pos_; 929e40139ffSDimitry Andric } 930349cc55cSDimitry Andric 931bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 932349cc55cSDimitry Andric allocator_type& __alloc() _NOEXCEPT 933349cc55cSDimitry Andric {return this->__end_cap_.second();} 934bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 935349cc55cSDimitry Andric const allocator_type& __alloc() const _NOEXCEPT 936349cc55cSDimitry Andric {return this->__end_cap_.second();} 937bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 938349cc55cSDimitry Andric pointer& __end_cap() _NOEXCEPT 939349cc55cSDimitry Andric {return this->__end_cap_.first();} 940bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 941349cc55cSDimitry Andric const pointer& __end_cap() const _NOEXCEPT 942349cc55cSDimitry Andric {return this->__end_cap_.first();} 943349cc55cSDimitry Andric 944bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 945349cc55cSDimitry Andric void __clear() _NOEXCEPT {__base_destruct_at_end(this->__begin_);} 946349cc55cSDimitry Andric 947bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 948349cc55cSDimitry Andric void __base_destruct_at_end(pointer __new_last) _NOEXCEPT { 949349cc55cSDimitry Andric pointer __soon_to_be_end = this->__end_; 950349cc55cSDimitry Andric while (__new_last != __soon_to_be_end) 951bdd1243dSDimitry Andric __alloc_traits::destroy(__alloc(), std::__to_address(--__soon_to_be_end)); 952349cc55cSDimitry Andric this->__end_ = __new_last; 953349cc55cSDimitry Andric } 954349cc55cSDimitry Andric 955bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 956349cc55cSDimitry Andric void __copy_assign_alloc(const vector& __c) 957349cc55cSDimitry Andric {__copy_assign_alloc(__c, integral_constant<bool, 958349cc55cSDimitry Andric __alloc_traits::propagate_on_container_copy_assignment::value>());} 959349cc55cSDimitry Andric 960bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 961349cc55cSDimitry Andric void __move_assign_alloc(vector& __c) 962349cc55cSDimitry Andric _NOEXCEPT_( 963349cc55cSDimitry Andric !__alloc_traits::propagate_on_container_move_assignment::value || 964349cc55cSDimitry Andric is_nothrow_move_assignable<allocator_type>::value) 965349cc55cSDimitry Andric {__move_assign_alloc(__c, integral_constant<bool, 966349cc55cSDimitry Andric __alloc_traits::propagate_on_container_move_assignment::value>());} 967349cc55cSDimitry Andric 968349cc55cSDimitry Andric _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI 969349cc55cSDimitry Andric void __throw_length_error() const { 970bdd1243dSDimitry Andric std::__throw_length_error("vector"); 971349cc55cSDimitry Andric } 972349cc55cSDimitry Andric 973349cc55cSDimitry Andric _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI 974349cc55cSDimitry Andric void __throw_out_of_range() const { 975bdd1243dSDimitry Andric std::__throw_out_of_range("vector"); 976349cc55cSDimitry Andric } 977349cc55cSDimitry Andric 978bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 979349cc55cSDimitry Andric void __copy_assign_alloc(const vector& __c, true_type) 980349cc55cSDimitry Andric { 981349cc55cSDimitry Andric if (__alloc() != __c.__alloc()) 982349cc55cSDimitry Andric { 983349cc55cSDimitry Andric __clear(); 98406c3fb27SDimitry Andric __annotate_delete(); 985349cc55cSDimitry Andric __alloc_traits::deallocate(__alloc(), this->__begin_, capacity()); 986349cc55cSDimitry Andric this->__begin_ = this->__end_ = __end_cap() = nullptr; 987349cc55cSDimitry Andric } 988349cc55cSDimitry Andric __alloc() = __c.__alloc(); 989349cc55cSDimitry Andric } 990349cc55cSDimitry Andric 991bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 992349cc55cSDimitry Andric void __copy_assign_alloc(const vector&, false_type) 993349cc55cSDimitry Andric {} 994349cc55cSDimitry Andric 995bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 996349cc55cSDimitry Andric void __move_assign_alloc(vector& __c, true_type) 997349cc55cSDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 998349cc55cSDimitry Andric { 999bdd1243dSDimitry Andric __alloc() = std::move(__c.__alloc()); 1000349cc55cSDimitry Andric } 1001349cc55cSDimitry Andric 1002bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 1003349cc55cSDimitry Andric void __move_assign_alloc(vector&, false_type) 1004349cc55cSDimitry Andric _NOEXCEPT 1005349cc55cSDimitry Andric {} 10060b57cec5SDimitry Andric}; 10070b57cec5SDimitry Andric 1008349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17 10090b57cec5SDimitry Andrictemplate<class _InputIterator, 1010fe6060f1SDimitry Andric class _Alloc = allocator<__iter_value_type<_InputIterator>>, 101106c3fb27SDimitry Andric class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>, 1012349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Alloc>::value> 10130b57cec5SDimitry Andric > 10140b57cec5SDimitry Andricvector(_InputIterator, _InputIterator) 1015fe6060f1SDimitry Andric -> vector<__iter_value_type<_InputIterator>, _Alloc>; 10160b57cec5SDimitry Andric 10170b57cec5SDimitry Andrictemplate<class _InputIterator, 10180b57cec5SDimitry Andric class _Alloc, 101906c3fb27SDimitry Andric class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>, 1020349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Alloc>::value> 10210b57cec5SDimitry Andric > 10220b57cec5SDimitry Andricvector(_InputIterator, _InputIterator, _Alloc) 1023fe6060f1SDimitry Andric -> vector<__iter_value_type<_InputIterator>, _Alloc>; 10240b57cec5SDimitry Andric#endif 10250b57cec5SDimitry Andric 102606c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 102706c3fb27SDimitry Andrictemplate <ranges::input_range _Range, 102806c3fb27SDimitry Andric class _Alloc = allocator<ranges::range_value_t<_Range>>, 102906c3fb27SDimitry Andric class = enable_if_t<__is_allocator<_Alloc>::value> 103006c3fb27SDimitry Andric > 103106c3fb27SDimitry Andricvector(from_range_t, _Range&&, _Alloc = _Alloc()) 103206c3fb27SDimitry Andric -> vector<ranges::range_value_t<_Range>, _Alloc>; 103306c3fb27SDimitry Andric#endif 103406c3fb27SDimitry Andric 10350b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1036bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 10370b57cec5SDimitry Andricvoid 10380b57cec5SDimitry Andricvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v) 10390b57cec5SDimitry Andric{ 10400b57cec5SDimitry Andric __annotate_delete(); 1041972a253aSDimitry Andric using _RevIter = std::reverse_iterator<pointer>; 1042972a253aSDimitry Andric __v.__begin_ = std::__uninitialized_allocator_move_if_noexcept( 1043972a253aSDimitry Andric __alloc(), _RevIter(__end_), _RevIter(__begin_), _RevIter(__v.__begin_)) 1044972a253aSDimitry Andric .base(); 1045bdd1243dSDimitry Andric std::swap(this->__begin_, __v.__begin_); 1046bdd1243dSDimitry Andric std::swap(this->__end_, __v.__end_); 1047bdd1243dSDimitry Andric std::swap(this->__end_cap(), __v.__end_cap()); 10480b57cec5SDimitry Andric __v.__first_ = __v.__begin_; 10490b57cec5SDimitry Andric __annotate_new(size()); 10500b57cec5SDimitry Andric} 10510b57cec5SDimitry Andric 10520b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1053bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 10540b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::pointer 10550b57cec5SDimitry Andricvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p) 10560b57cec5SDimitry Andric{ 10570b57cec5SDimitry Andric __annotate_delete(); 10580b57cec5SDimitry Andric pointer __r = __v.__begin_; 1059972a253aSDimitry Andric using _RevIter = std::reverse_iterator<pointer>; 1060972a253aSDimitry Andric __v.__begin_ = std::__uninitialized_allocator_move_if_noexcept( 1061972a253aSDimitry Andric __alloc(), _RevIter(__p), _RevIter(__begin_), _RevIter(__v.__begin_)) 1062972a253aSDimitry Andric .base(); 1063972a253aSDimitry Andric __v.__end_ = std::__uninitialized_allocator_move_if_noexcept(__alloc(), __p, __end_, __v.__end_); 1064bdd1243dSDimitry Andric std::swap(this->__begin_, __v.__begin_); 1065bdd1243dSDimitry Andric std::swap(this->__end_, __v.__end_); 1066bdd1243dSDimitry Andric std::swap(this->__end_cap(), __v.__end_cap()); 10670b57cec5SDimitry Andric __v.__first_ = __v.__begin_; 10680b57cec5SDimitry Andric __annotate_new(size()); 10690b57cec5SDimitry Andric return __r; 10700b57cec5SDimitry Andric} 10710b57cec5SDimitry Andric 10720b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1073bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 10740b57cec5SDimitry Andricvoid 10750b57cec5SDimitry Andricvector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT 10760b57cec5SDimitry Andric{ 10770b57cec5SDimitry Andric if (this->__begin_ != nullptr) 10780b57cec5SDimitry Andric { 10790b57cec5SDimitry Andric clear(); 108006c3fb27SDimitry Andric __annotate_delete(); 10810b57cec5SDimitry Andric __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity()); 10820b57cec5SDimitry Andric this->__begin_ = this->__end_ = this->__end_cap() = nullptr; 10830b57cec5SDimitry Andric } 10840b57cec5SDimitry Andric} 10850b57cec5SDimitry Andric 10860b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1087bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 10880b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::size_type 10890b57cec5SDimitry Andricvector<_Tp, _Allocator>::max_size() const _NOEXCEPT 10900b57cec5SDimitry Andric{ 1091bdd1243dSDimitry Andric return std::min<size_type>(__alloc_traits::max_size(this->__alloc()), 10920b57cec5SDimitry Andric numeric_limits<difference_type>::max()); 10930b57cec5SDimitry Andric} 10940b57cec5SDimitry Andric 10950b57cec5SDimitry Andric// Precondition: __new_size > capacity() 10960b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1097bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1098bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 10990b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::size_type 11000b57cec5SDimitry Andricvector<_Tp, _Allocator>::__recommend(size_type __new_size) const 11010b57cec5SDimitry Andric{ 11020b57cec5SDimitry Andric const size_type __ms = max_size(); 11030b57cec5SDimitry Andric if (__new_size > __ms) 11040b57cec5SDimitry Andric this->__throw_length_error(); 11050b57cec5SDimitry Andric const size_type __cap = capacity(); 11060b57cec5SDimitry Andric if (__cap >= __ms / 2) 11070b57cec5SDimitry Andric return __ms; 1108bdd1243dSDimitry Andric return std::max<size_type>(2 * __cap, __new_size); 11090b57cec5SDimitry Andric} 11100b57cec5SDimitry Andric 11110b57cec5SDimitry Andric// Default constructs __n objects starting at __end_ 11120b57cec5SDimitry Andric// throws if construction throws 11130b57cec5SDimitry Andric// Precondition: __n > 0 11140b57cec5SDimitry Andric// Precondition: size() + __n <= capacity() 11150b57cec5SDimitry Andric// Postcondition: size() == size() + __n 11160b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1117bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 11180b57cec5SDimitry Andricvoid 11190b57cec5SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(size_type __n) 11200b57cec5SDimitry Andric{ 1121e40139ffSDimitry Andric _ConstructTransaction __tx(*this, __n); 11225ffd83dbSDimitry Andric const_pointer __new_end = __tx.__new_end_; 1123349cc55cSDimitry Andric for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) { 1124bdd1243dSDimitry Andric __alloc_traits::construct(this->__alloc(), std::__to_address(__pos)); 1125e40139ffSDimitry Andric } 11260b57cec5SDimitry Andric} 11270b57cec5SDimitry Andric 11280b57cec5SDimitry Andric// Copy constructs __n objects starting at __end_ from __x 11290b57cec5SDimitry Andric// throws if construction throws 11300b57cec5SDimitry Andric// Precondition: __n > 0 11310b57cec5SDimitry Andric// Precondition: size() + __n <= capacity() 11320b57cec5SDimitry Andric// Postcondition: size() == old size() + __n 11330b57cec5SDimitry Andric// Postcondition: [i] == __x for all i in [size() - __n, __n) 11340b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1135bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 11360b57cec5SDimitry Andricinline 11370b57cec5SDimitry Andricvoid 11380b57cec5SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) 11390b57cec5SDimitry Andric{ 1140e40139ffSDimitry Andric _ConstructTransaction __tx(*this, __n); 11415ffd83dbSDimitry Andric const_pointer __new_end = __tx.__new_end_; 1142349cc55cSDimitry Andric for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) { 1143bdd1243dSDimitry Andric __alloc_traits::construct(this->__alloc(), std::__to_address(__pos), __x); 1144e40139ffSDimitry Andric } 11450b57cec5SDimitry Andric} 11460b57cec5SDimitry Andric 11470b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 114806c3fb27SDimitry Andrictemplate <class _InputIterator, class _Sentinel> 1149bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void 115006c3fb27SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) { 1151e40139ffSDimitry Andric _ConstructTransaction __tx(*this, __n); 1152972a253aSDimitry Andric __tx.__pos_ = std::__uninitialized_allocator_copy(__alloc(), __first, __last, __tx.__pos_); 11530b57cec5SDimitry Andric} 11540b57cec5SDimitry Andric 11550b57cec5SDimitry Andric// Default constructs __n objects starting at __end_ 11560b57cec5SDimitry Andric// throws if construction throws 11570b57cec5SDimitry Andric// Postcondition: size() == size() + __n 11580b57cec5SDimitry Andric// Exception safety: strong. 11590b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1160bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 11610b57cec5SDimitry Andricvoid 11620b57cec5SDimitry Andricvector<_Tp, _Allocator>::__append(size_type __n) 11630b57cec5SDimitry Andric{ 11640b57cec5SDimitry Andric if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) 11650b57cec5SDimitry Andric this->__construct_at_end(__n); 11660b57cec5SDimitry Andric else 11670b57cec5SDimitry Andric { 11680b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 11690b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); 11700b57cec5SDimitry Andric __v.__construct_at_end(__n); 11710b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 11720b57cec5SDimitry Andric } 11730b57cec5SDimitry Andric} 11740b57cec5SDimitry Andric 11750b57cec5SDimitry Andric// Default constructs __n objects starting at __end_ 11760b57cec5SDimitry Andric// throws if construction throws 11770b57cec5SDimitry Andric// Postcondition: size() == size() + __n 11780b57cec5SDimitry Andric// Exception safety: strong. 11790b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1180bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 11810b57cec5SDimitry Andricvoid 11820b57cec5SDimitry Andricvector<_Tp, _Allocator>::__append(size_type __n, const_reference __x) 11830b57cec5SDimitry Andric{ 11840b57cec5SDimitry Andric if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) 11850b57cec5SDimitry Andric this->__construct_at_end(__n, __x); 11860b57cec5SDimitry Andric else 11870b57cec5SDimitry Andric { 11880b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 11890b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); 11900b57cec5SDimitry Andric __v.__construct_at_end(__n, __x); 11910b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 11920b57cec5SDimitry Andric } 11930b57cec5SDimitry Andric} 11940b57cec5SDimitry Andric 11950b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1196bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 11970b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n) 11980b57cec5SDimitry Andric{ 1199bdd1243dSDimitry Andric auto __guard = std::__make_exception_guard(__destroy_vector(*this)); 12000b57cec5SDimitry Andric if (__n > 0) 12010b57cec5SDimitry Andric { 12020b57cec5SDimitry Andric __vallocate(__n); 12030b57cec5SDimitry Andric __construct_at_end(__n); 12040b57cec5SDimitry Andric } 120550d7464cSDimitry Andric __guard.__complete(); 12060b57cec5SDimitry Andric} 12070b57cec5SDimitry Andric 120806c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 12090b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1210bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 12110b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a) 1212d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 12130b57cec5SDimitry Andric{ 1214bdd1243dSDimitry Andric auto __guard = std::__make_exception_guard(__destroy_vector(*this)); 12150b57cec5SDimitry Andric if (__n > 0) 12160b57cec5SDimitry Andric { 12170b57cec5SDimitry Andric __vallocate(__n); 12180b57cec5SDimitry Andric __construct_at_end(__n); 12190b57cec5SDimitry Andric } 122050d7464cSDimitry Andric __guard.__complete(); 12210b57cec5SDimitry Andric} 12220b57cec5SDimitry Andric#endif 12230b57cec5SDimitry Andric 12240b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1225bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 12260b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x) 12270b57cec5SDimitry Andric{ 1228bdd1243dSDimitry Andric auto __guard = std::__make_exception_guard(__destroy_vector(*this)); 12290b57cec5SDimitry Andric if (__n > 0) 12300b57cec5SDimitry Andric { 12310b57cec5SDimitry Andric __vallocate(__n); 12320b57cec5SDimitry Andric __construct_at_end(__n, __x); 12330b57cec5SDimitry Andric } 123450d7464cSDimitry Andric __guard.__complete(); 12350b57cec5SDimitry Andric} 12360b57cec5SDimitry Andric 12370b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 123806c3fb27SDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value && 1239bdd1243dSDimitry Andric is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value, 1240bdd1243dSDimitry Andric int> > 1241bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1242bdd1243dSDimitry Andricvector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last) 12430b57cec5SDimitry Andric{ 124406c3fb27SDimitry Andric __init_with_sentinel(__first, __last); 12450b57cec5SDimitry Andric} 12460b57cec5SDimitry Andric 12470b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 124806c3fb27SDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value && 1249bdd1243dSDimitry Andric is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value, 1250bdd1243dSDimitry Andric int> > 1251bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1252bdd1243dSDimitry Andricvector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a) 1253d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 12540b57cec5SDimitry Andric{ 125506c3fb27SDimitry Andric __init_with_sentinel(__first, __last); 12560b57cec5SDimitry Andric} 12570b57cec5SDimitry Andric 12580b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 125906c3fb27SDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value && 1260bdd1243dSDimitry Andric is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value, 1261bdd1243dSDimitry Andric int> > 1262bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1263bdd1243dSDimitry Andricvector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last) 12640b57cec5SDimitry Andric{ 126550d7464cSDimitry Andric size_type __n = static_cast<size_type>(std::distance(__first, __last)); 126606c3fb27SDimitry Andric __init_with_size(__first, __last, __n); 12670b57cec5SDimitry Andric} 12680b57cec5SDimitry Andric 12690b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 127006c3fb27SDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value && 1271bdd1243dSDimitry Andric is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value, 1272bdd1243dSDimitry Andric int> > 1273bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1274bdd1243dSDimitry Andricvector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a) 1275d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 12760b57cec5SDimitry Andric{ 127750d7464cSDimitry Andric size_type __n = static_cast<size_type>(std::distance(__first, __last)); 127806c3fb27SDimitry Andric __init_with_size(__first, __last, __n); 12790b57cec5SDimitry Andric} 12800b57cec5SDimitry Andric 12810b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1282bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 12830b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(const vector& __x) 1284d56accc7SDimitry Andric : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc())) 12850b57cec5SDimitry Andric{ 128606c3fb27SDimitry Andric __init_with_size(__x.__begin_, __x.__end_, __x.size()); 12870b57cec5SDimitry Andric} 12880b57cec5SDimitry Andric 12890b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1290bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 129181ad6265SDimitry Andricvector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t<allocator_type>& __a) 1292d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 12930b57cec5SDimitry Andric{ 129406c3fb27SDimitry Andric __init_with_size(__x.__begin_, __x.__end_, __x.size()); 12950b57cec5SDimitry Andric} 12960b57cec5SDimitry Andric 12970b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1298bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1299bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 13000b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(vector&& __x) 130106c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 130281ad6265SDimitry Andric noexcept 13030b57cec5SDimitry Andric#else 13040b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 13050b57cec5SDimitry Andric#endif 1306bdd1243dSDimitry Andric : __end_cap_(nullptr, std::move(__x.__alloc())) 13070b57cec5SDimitry Andric{ 13080b57cec5SDimitry Andric this->__begin_ = __x.__begin_; 13090b57cec5SDimitry Andric this->__end_ = __x.__end_; 13100b57cec5SDimitry Andric this->__end_cap() = __x.__end_cap(); 13110b57cec5SDimitry Andric __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; 13120b57cec5SDimitry Andric} 13130b57cec5SDimitry Andric 13140b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1315bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1316bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 131781ad6265SDimitry Andricvector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_type>& __a) 1318d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 13190b57cec5SDimitry Andric{ 13200b57cec5SDimitry Andric if (__a == __x.__alloc()) 13210b57cec5SDimitry Andric { 13220b57cec5SDimitry Andric this->__begin_ = __x.__begin_; 13230b57cec5SDimitry Andric this->__end_ = __x.__end_; 13240b57cec5SDimitry Andric this->__end_cap() = __x.__end_cap(); 13250b57cec5SDimitry Andric __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; 13260b57cec5SDimitry Andric } 13270b57cec5SDimitry Andric else 13280b57cec5SDimitry Andric { 13290b57cec5SDimitry Andric typedef move_iterator<iterator> _Ip; 1330bdd1243dSDimitry Andric auto __guard = std::__make_exception_guard(__destroy_vector(*this)); 13310b57cec5SDimitry Andric assign(_Ip(__x.begin()), _Ip(__x.end())); 133250d7464cSDimitry Andric __guard.__complete(); 13330b57cec5SDimitry Andric } 13340b57cec5SDimitry Andric} 13350b57cec5SDimitry Andric 133681ad6265SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 133781ad6265SDimitry Andric 13380b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1339bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1340bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 13410b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il) 13420b57cec5SDimitry Andric{ 1343bdd1243dSDimitry Andric auto __guard = std::__make_exception_guard(__destroy_vector(*this)); 13440b57cec5SDimitry Andric if (__il.size() > 0) 13450b57cec5SDimitry Andric { 13460b57cec5SDimitry Andric __vallocate(__il.size()); 13470b57cec5SDimitry Andric __construct_at_end(__il.begin(), __il.end(), __il.size()); 13480b57cec5SDimitry Andric } 134950d7464cSDimitry Andric __guard.__complete(); 13500b57cec5SDimitry Andric} 13510b57cec5SDimitry Andric 13520b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1353bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1354bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 13550b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) 1356d56accc7SDimitry Andric : __end_cap_(nullptr, __a) 13570b57cec5SDimitry Andric{ 1358bdd1243dSDimitry Andric auto __guard = std::__make_exception_guard(__destroy_vector(*this)); 13590b57cec5SDimitry Andric if (__il.size() > 0) 13600b57cec5SDimitry Andric { 13610b57cec5SDimitry Andric __vallocate(__il.size()); 13620b57cec5SDimitry Andric __construct_at_end(__il.begin(), __il.end(), __il.size()); 13630b57cec5SDimitry Andric } 136450d7464cSDimitry Andric __guard.__complete(); 13650b57cec5SDimitry Andric} 13660b57cec5SDimitry Andric 136781ad6265SDimitry Andric#endif // _LIBCPP_CXX03_LANG 136881ad6265SDimitry Andric 13690b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1370bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1371bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 13720b57cec5SDimitry Andricvector<_Tp, _Allocator>& 13730b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator=(vector&& __x) 13740b57cec5SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) 13750b57cec5SDimitry Andric{ 13760b57cec5SDimitry Andric __move_assign(__x, integral_constant<bool, 13770b57cec5SDimitry Andric __alloc_traits::propagate_on_container_move_assignment::value>()); 13780b57cec5SDimitry Andric return *this; 13790b57cec5SDimitry Andric} 13800b57cec5SDimitry Andric 13810b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1382bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 13830b57cec5SDimitry Andricvoid 13840b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_assign(vector& __c, false_type) 13850b57cec5SDimitry Andric _NOEXCEPT_(__alloc_traits::is_always_equal::value) 13860b57cec5SDimitry Andric{ 1387349cc55cSDimitry Andric if (__alloc() != __c.__alloc()) 13880b57cec5SDimitry Andric { 13890b57cec5SDimitry Andric typedef move_iterator<iterator> _Ip; 13900b57cec5SDimitry Andric assign(_Ip(__c.begin()), _Ip(__c.end())); 13910b57cec5SDimitry Andric } 13920b57cec5SDimitry Andric else 13930b57cec5SDimitry Andric __move_assign(__c, true_type()); 13940b57cec5SDimitry Andric} 13950b57cec5SDimitry Andric 13960b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1397bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 13980b57cec5SDimitry Andricvoid 13990b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_assign(vector& __c, true_type) 14000b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 14010b57cec5SDimitry Andric{ 14020b57cec5SDimitry Andric __vdeallocate(); 1403349cc55cSDimitry Andric __move_assign_alloc(__c); // this can throw 14040b57cec5SDimitry Andric this->__begin_ = __c.__begin_; 14050b57cec5SDimitry Andric this->__end_ = __c.__end_; 14060b57cec5SDimitry Andric this->__end_cap() = __c.__end_cap(); 14070b57cec5SDimitry Andric __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr; 14080b57cec5SDimitry Andric} 14090b57cec5SDimitry Andric 14100b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1411bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1412bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 14130b57cec5SDimitry Andricvector<_Tp, _Allocator>& 14140b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator=(const vector& __x) 14150b57cec5SDimitry Andric{ 1416bdd1243dSDimitry Andric if (this != std::addressof(__x)) 14170b57cec5SDimitry Andric { 1418349cc55cSDimitry Andric __copy_assign_alloc(__x); 14190b57cec5SDimitry Andric assign(__x.__begin_, __x.__end_); 14200b57cec5SDimitry Andric } 14210b57cec5SDimitry Andric return *this; 14220b57cec5SDimitry Andric} 14230b57cec5SDimitry Andric 14240b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 142506c3fb27SDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value && 1426bdd1243dSDimitry Andric is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value, 1427bdd1243dSDimitry Andric int> > 1428bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void 14290b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last) 14300b57cec5SDimitry Andric{ 143106c3fb27SDimitry Andric __assign_with_sentinel(__first, __last); 143206c3fb27SDimitry Andric} 143306c3fb27SDimitry Andric 143406c3fb27SDimitry Andrictemplate <class _Tp, class _Allocator> 143506c3fb27SDimitry Andrictemplate <class _Iterator, class _Sentinel> 143606c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 143706c3fb27SDimitry Andricvoid vector<_Tp, _Allocator>::__assign_with_sentinel(_Iterator __first, _Sentinel __last) { 14380b57cec5SDimitry Andric clear(); 14390b57cec5SDimitry Andric for (; __first != __last; ++__first) 144081ad6265SDimitry Andric emplace_back(*__first); 14410b57cec5SDimitry Andric} 14420b57cec5SDimitry Andric 14430b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 144406c3fb27SDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value && 1445bdd1243dSDimitry Andric is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value, 1446bdd1243dSDimitry Andric int> > 1447bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void 14480b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) 14490b57cec5SDimitry Andric{ 145006c3fb27SDimitry Andric __assign_with_size(__first, __last, std::distance(__first, __last)); 145106c3fb27SDimitry Andric} 145206c3fb27SDimitry Andric 145306c3fb27SDimitry Andrictemplate <class _Tp, class _Allocator> 145406c3fb27SDimitry Andrictemplate <class _ForwardIterator, class _Sentinel> 145506c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 145606c3fb27SDimitry Andricvoid vector<_Tp, _Allocator>::__assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __n) { 145706c3fb27SDimitry Andric size_type __new_size = static_cast<size_type>(__n); 14580b57cec5SDimitry Andric if (__new_size <= capacity()) 14590b57cec5SDimitry Andric { 14600b57cec5SDimitry Andric if (__new_size > size()) 14610b57cec5SDimitry Andric { 146206c3fb27SDimitry Andric _ForwardIterator __mid = std::next(__first, size()); 146306c3fb27SDimitry Andric std::copy(__first, __mid, this->__begin_); 14640b57cec5SDimitry Andric __construct_at_end(__mid, __last, __new_size - size()); 146506c3fb27SDimitry Andric } 14660b57cec5SDimitry Andric else 146706c3fb27SDimitry Andric { 146806c3fb27SDimitry Andric pointer __m = std::__copy<_ClassicAlgPolicy>(__first, __last, this->__begin_).second; 14690b57cec5SDimitry Andric this->__destruct_at_end(__m); 14700b57cec5SDimitry Andric } 147106c3fb27SDimitry Andric } 14720b57cec5SDimitry Andric else 14730b57cec5SDimitry Andric { 14740b57cec5SDimitry Andric __vdeallocate(); 14750b57cec5SDimitry Andric __vallocate(__recommend(__new_size)); 14760b57cec5SDimitry Andric __construct_at_end(__first, __last, __new_size); 14770b57cec5SDimitry Andric } 14780b57cec5SDimitry Andric} 14790b57cec5SDimitry Andric 14800b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1481bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 14820b57cec5SDimitry Andricvoid 14830b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(size_type __n, const_reference __u) 14840b57cec5SDimitry Andric{ 14850b57cec5SDimitry Andric if (__n <= capacity()) 14860b57cec5SDimitry Andric { 14870b57cec5SDimitry Andric size_type __s = size(); 1488bdd1243dSDimitry Andric std::fill_n(this->__begin_, std::min(__n, __s), __u); 14890b57cec5SDimitry Andric if (__n > __s) 14900b57cec5SDimitry Andric __construct_at_end(__n - __s, __u); 14910b57cec5SDimitry Andric else 14920b57cec5SDimitry Andric this->__destruct_at_end(this->__begin_ + __n); 14930b57cec5SDimitry Andric } 14940b57cec5SDimitry Andric else 14950b57cec5SDimitry Andric { 14960b57cec5SDimitry Andric __vdeallocate(); 14970b57cec5SDimitry Andric __vallocate(__recommend(static_cast<size_type>(__n))); 14980b57cec5SDimitry Andric __construct_at_end(__n, __u); 14990b57cec5SDimitry Andric } 15000b57cec5SDimitry Andric} 15010b57cec5SDimitry Andric 15020b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1503bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1504bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 15050b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 15060b57cec5SDimitry Andricvector<_Tp, _Allocator>::begin() _NOEXCEPT 15070b57cec5SDimitry Andric{ 1508bdd1243dSDimitry Andric return __make_iter(this->__begin_); 15090b57cec5SDimitry Andric} 15100b57cec5SDimitry Andric 15110b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1512bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1513bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 15140b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_iterator 15150b57cec5SDimitry Andricvector<_Tp, _Allocator>::begin() const _NOEXCEPT 15160b57cec5SDimitry Andric{ 1517bdd1243dSDimitry Andric return __make_iter(this->__begin_); 15180b57cec5SDimitry Andric} 15190b57cec5SDimitry Andric 15200b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1521bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1522bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 15230b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 15240b57cec5SDimitry Andricvector<_Tp, _Allocator>::end() _NOEXCEPT 15250b57cec5SDimitry Andric{ 1526bdd1243dSDimitry Andric return __make_iter(this->__end_); 15270b57cec5SDimitry Andric} 15280b57cec5SDimitry Andric 15290b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1530bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1531bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 15320b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_iterator 15330b57cec5SDimitry Andricvector<_Tp, _Allocator>::end() const _NOEXCEPT 15340b57cec5SDimitry Andric{ 1535bdd1243dSDimitry Andric return __make_iter(this->__end_); 15360b57cec5SDimitry Andric} 15370b57cec5SDimitry Andric 15380b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1539bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1540bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 15410b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference 15420b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT 15430b57cec5SDimitry Andric{ 154406c3fb27SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < size(), "vector[] index out of bounds"); 15450b57cec5SDimitry Andric return this->__begin_[__n]; 15460b57cec5SDimitry Andric} 15470b57cec5SDimitry Andric 15480b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1549bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1550bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 15510b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_reference 15520b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT 15530b57cec5SDimitry Andric{ 155406c3fb27SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < size(), "vector[] index out of bounds"); 15550b57cec5SDimitry Andric return this->__begin_[__n]; 15560b57cec5SDimitry Andric} 15570b57cec5SDimitry Andric 15580b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1559bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 15600b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference 15610b57cec5SDimitry Andricvector<_Tp, _Allocator>::at(size_type __n) 15620b57cec5SDimitry Andric{ 15630b57cec5SDimitry Andric if (__n >= size()) 15640b57cec5SDimitry Andric this->__throw_out_of_range(); 15650b57cec5SDimitry Andric return this->__begin_[__n]; 15660b57cec5SDimitry Andric} 15670b57cec5SDimitry Andric 15680b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1569bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 15700b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_reference 15710b57cec5SDimitry Andricvector<_Tp, _Allocator>::at(size_type __n) const 15720b57cec5SDimitry Andric{ 15730b57cec5SDimitry Andric if (__n >= size()) 15740b57cec5SDimitry Andric this->__throw_out_of_range(); 15750b57cec5SDimitry Andric return this->__begin_[__n]; 15760b57cec5SDimitry Andric} 15770b57cec5SDimitry Andric 15780b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1579bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 15800b57cec5SDimitry Andricvoid 15810b57cec5SDimitry Andricvector<_Tp, _Allocator>::reserve(size_type __n) 15820b57cec5SDimitry Andric{ 15830b57cec5SDimitry Andric if (__n > capacity()) 15840b57cec5SDimitry Andric { 1585349cc55cSDimitry Andric if (__n > max_size()) 1586349cc55cSDimitry Andric this->__throw_length_error(); 15870b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 15880b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__n, size(), __a); 15890b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 15900b57cec5SDimitry Andric } 15910b57cec5SDimitry Andric} 15920b57cec5SDimitry Andric 15930b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1594bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 15950b57cec5SDimitry Andricvoid 15960b57cec5SDimitry Andricvector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT 15970b57cec5SDimitry Andric{ 15980b57cec5SDimitry Andric if (capacity() > size()) 15990b57cec5SDimitry Andric { 160006c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 16010b57cec5SDimitry Andric try 16020b57cec5SDimitry Andric { 160306c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 16040b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 16050b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(size(), size(), __a); 16060b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 160706c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 16080b57cec5SDimitry Andric } 16090b57cec5SDimitry Andric catch (...) 16100b57cec5SDimitry Andric { 16110b57cec5SDimitry Andric } 161206c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 16130b57cec5SDimitry Andric } 16140b57cec5SDimitry Andric} 16150b57cec5SDimitry Andric 16160b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16170b57cec5SDimitry Andrictemplate <class _Up> 1618bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1619*5f757f3fSDimitry Andrictypename vector<_Tp, _Allocator>::pointer 16200b57cec5SDimitry Andricvector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x) 16210b57cec5SDimitry Andric{ 16220b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 16230b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); 1624bdd1243dSDimitry Andric // __v.push_back(std::forward<_Up>(__x)); 1625bdd1243dSDimitry Andric __alloc_traits::construct(__a, std::__to_address(__v.__end_), std::forward<_Up>(__x)); 16260b57cec5SDimitry Andric __v.__end_++; 16270b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 1628*5f757f3fSDimitry Andric return this->__end_; 16290b57cec5SDimitry Andric} 16300b57cec5SDimitry Andric 16310b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1632bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1633bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 16340b57cec5SDimitry Andricvoid 16350b57cec5SDimitry Andricvector<_Tp, _Allocator>::push_back(const_reference __x) 16360b57cec5SDimitry Andric{ 1637*5f757f3fSDimitry Andric pointer __end = this->__end_; 1638*5f757f3fSDimitry Andric if (__end < this->__end_cap()) { 1639e40139ffSDimitry Andric __construct_one_at_end(__x); 1640*5f757f3fSDimitry Andric ++__end; 1641*5f757f3fSDimitry Andric } else { 1642*5f757f3fSDimitry Andric __end = __push_back_slow_path(__x); 16430b57cec5SDimitry Andric } 1644*5f757f3fSDimitry Andric this->__end_ = __end; 16450b57cec5SDimitry Andric} 16460b57cec5SDimitry Andric 16470b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1648bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1649bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 16500b57cec5SDimitry Andricvoid 16510b57cec5SDimitry Andricvector<_Tp, _Allocator>::push_back(value_type&& __x) 16520b57cec5SDimitry Andric{ 1653*5f757f3fSDimitry Andric pointer __end = this->__end_; 1654*5f757f3fSDimitry Andric if (__end < this->__end_cap()) { 1655bdd1243dSDimitry Andric __construct_one_at_end(std::move(__x)); 1656*5f757f3fSDimitry Andric ++__end; 1657*5f757f3fSDimitry Andric } else { 1658*5f757f3fSDimitry Andric __end = __push_back_slow_path(std::move(__x)); 16590b57cec5SDimitry Andric } 1660*5f757f3fSDimitry Andric this->__end_ = __end; 16610b57cec5SDimitry Andric} 16620b57cec5SDimitry Andric 16630b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16640b57cec5SDimitry Andrictemplate <class... _Args> 1665bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1666*5f757f3fSDimitry Andrictypename vector<_Tp, _Allocator>::pointer 16670b57cec5SDimitry Andricvector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args) 16680b57cec5SDimitry Andric{ 16690b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 16700b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); 1671bdd1243dSDimitry Andric// __v.emplace_back(std::forward<_Args>(__args)...); 1672bdd1243dSDimitry Andric __alloc_traits::construct(__a, std::__to_address(__v.__end_), std::forward<_Args>(__args)...); 16730b57cec5SDimitry Andric __v.__end_++; 16740b57cec5SDimitry Andric __swap_out_circular_buffer(__v); 1675*5f757f3fSDimitry Andric return this->__end_; 16760b57cec5SDimitry Andric} 16770b57cec5SDimitry Andric 16780b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 16790b57cec5SDimitry Andrictemplate <class... _Args> 1680bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 16810b57cec5SDimitry Andricinline 168206c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 16830b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference 16840b57cec5SDimitry Andric#else 16850b57cec5SDimitry Andricvoid 16860b57cec5SDimitry Andric#endif 16870b57cec5SDimitry Andricvector<_Tp, _Allocator>::emplace_back(_Args&&... __args) 16880b57cec5SDimitry Andric{ 1689*5f757f3fSDimitry Andric pointer __end = this->__end_; 1690*5f757f3fSDimitry Andric if (__end < this->__end_cap()) { 1691bdd1243dSDimitry Andric __construct_one_at_end(std::forward<_Args>(__args)...); 1692*5f757f3fSDimitry Andric ++__end; 1693*5f757f3fSDimitry Andric } else { 1694*5f757f3fSDimitry Andric __end = __emplace_back_slow_path(std::forward<_Args>(__args)...); 16950b57cec5SDimitry Andric } 1696*5f757f3fSDimitry Andric this->__end_ = __end; 169706c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 1698*5f757f3fSDimitry Andric return *(__end - 1); 16990b57cec5SDimitry Andric#endif 17000b57cec5SDimitry Andric} 17010b57cec5SDimitry Andric 17020b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1703bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 17040b57cec5SDimitry Andricinline 17050b57cec5SDimitry Andricvoid 17060b57cec5SDimitry Andricvector<_Tp, _Allocator>::pop_back() 17070b57cec5SDimitry Andric{ 170806c3fb27SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "vector::pop_back called on an empty vector"); 17090b57cec5SDimitry Andric this->__destruct_at_end(this->__end_ - 1); 17100b57cec5SDimitry Andric} 17110b57cec5SDimitry Andric 17120b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1713bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 1714bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 17150b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 17160b57cec5SDimitry Andricvector<_Tp, _Allocator>::erase(const_iterator __position) 17170b57cec5SDimitry Andric{ 171806c3fb27SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__position != end(), 17190b57cec5SDimitry Andric "vector::erase(iterator) called with a non-dereferenceable iterator"); 17200b57cec5SDimitry Andric difference_type __ps = __position - cbegin(); 17210b57cec5SDimitry Andric pointer __p = this->__begin_ + __ps; 1722bdd1243dSDimitry Andric this->__destruct_at_end(std::move(__p + 1, this->__end_, __p)); 1723bdd1243dSDimitry Andric return __make_iter(__p); 17240b57cec5SDimitry Andric} 17250b57cec5SDimitry Andric 17260b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1727bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 17280b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 17290b57cec5SDimitry Andricvector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) 17300b57cec5SDimitry Andric{ 173106c3fb27SDimitry Andric _LIBCPP_ASSERT_VALID_INPUT_RANGE(__first <= __last, "vector::erase(first, last) called with invalid range"); 17320b57cec5SDimitry Andric pointer __p = this->__begin_ + (__first - begin()); 17330b57cec5SDimitry Andric if (__first != __last) { 1734bdd1243dSDimitry Andric this->__destruct_at_end(std::move(__p + (__last - __first), this->__end_, __p)); 17350b57cec5SDimitry Andric } 1736bdd1243dSDimitry Andric return __make_iter(__p); 17370b57cec5SDimitry Andric} 17380b57cec5SDimitry Andric 17390b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1740bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 17410b57cec5SDimitry Andricvoid 17420b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to) 17430b57cec5SDimitry Andric{ 17440b57cec5SDimitry Andric pointer __old_last = this->__end_; 17450b57cec5SDimitry Andric difference_type __n = __old_last - __to; 1746e40139ffSDimitry Andric { 1747e40139ffSDimitry Andric pointer __i = __from_s + __n; 1748e40139ffSDimitry Andric _ConstructTransaction __tx(*this, __from_e - __i); 17495ffd83dbSDimitry Andric for (pointer __pos = __tx.__pos_; __i < __from_e; 1750349cc55cSDimitry Andric ++__i, (void) ++__pos, __tx.__pos_ = __pos) { 17510b57cec5SDimitry Andric __alloc_traits::construct(this->__alloc(), 1752bdd1243dSDimitry Andric std::__to_address(__pos), 1753bdd1243dSDimitry Andric std::move(*__i)); 1754e40139ffSDimitry Andric } 1755e40139ffSDimitry Andric } 1756bdd1243dSDimitry Andric std::move_backward(__from_s, __from_s + __n, __old_last); 17570b57cec5SDimitry Andric} 17580b57cec5SDimitry Andric 17590b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1760bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 17610b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 17620b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) 17630b57cec5SDimitry Andric{ 17640b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 176561cfbce3SDimitry Andric // We can't compare unrelated pointers inside constant expressions 176661cfbce3SDimitry Andric if (!__libcpp_is_constant_evaluated() && this->__end_ < this->__end_cap()) 17670b57cec5SDimitry Andric { 17680b57cec5SDimitry Andric if (__p == this->__end_) 17690b57cec5SDimitry Andric { 1770e40139ffSDimitry Andric __construct_one_at_end(__x); 17710b57cec5SDimitry Andric } 17720b57cec5SDimitry Andric else 17730b57cec5SDimitry Andric { 17740b57cec5SDimitry Andric __move_range(__p, this->__end_, __p + 1); 17750b57cec5SDimitry Andric const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); 17760b57cec5SDimitry Andric if (__p <= __xr && __xr < this->__end_) 17770b57cec5SDimitry Andric ++__xr; 17780b57cec5SDimitry Andric *__p = *__xr; 17790b57cec5SDimitry Andric } 17800b57cec5SDimitry Andric } 17810b57cec5SDimitry Andric else 17820b57cec5SDimitry Andric { 17830b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 17840b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 17850b57cec5SDimitry Andric __v.push_back(__x); 17860b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 17870b57cec5SDimitry Andric } 1788bdd1243dSDimitry Andric return __make_iter(__p); 17890b57cec5SDimitry Andric} 17900b57cec5SDimitry Andric 17910b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1792bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 17930b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 17940b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) 17950b57cec5SDimitry Andric{ 17960b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 17970b57cec5SDimitry Andric if (this->__end_ < this->__end_cap()) 17980b57cec5SDimitry Andric { 17990b57cec5SDimitry Andric if (__p == this->__end_) 18000b57cec5SDimitry Andric { 1801bdd1243dSDimitry Andric __construct_one_at_end(std::move(__x)); 18020b57cec5SDimitry Andric } 18030b57cec5SDimitry Andric else 18040b57cec5SDimitry Andric { 18050b57cec5SDimitry Andric __move_range(__p, this->__end_, __p + 1); 1806bdd1243dSDimitry Andric *__p = std::move(__x); 18070b57cec5SDimitry Andric } 18080b57cec5SDimitry Andric } 18090b57cec5SDimitry Andric else 18100b57cec5SDimitry Andric { 18110b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 18120b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 1813bdd1243dSDimitry Andric __v.push_back(std::move(__x)); 18140b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 18150b57cec5SDimitry Andric } 1816bdd1243dSDimitry Andric return __make_iter(__p); 18170b57cec5SDimitry Andric} 18180b57cec5SDimitry Andric 18190b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 18200b57cec5SDimitry Andrictemplate <class... _Args> 1821bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 18220b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 18230b57cec5SDimitry Andricvector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) 18240b57cec5SDimitry Andric{ 18250b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 18260b57cec5SDimitry Andric if (this->__end_ < this->__end_cap()) 18270b57cec5SDimitry Andric { 18280b57cec5SDimitry Andric if (__p == this->__end_) 18290b57cec5SDimitry Andric { 1830bdd1243dSDimitry Andric __construct_one_at_end(std::forward<_Args>(__args)...); 18310b57cec5SDimitry Andric } 18320b57cec5SDimitry Andric else 18330b57cec5SDimitry Andric { 1834bdd1243dSDimitry Andric __temp_value<value_type, _Allocator> __tmp(this->__alloc(), std::forward<_Args>(__args)...); 18350b57cec5SDimitry Andric __move_range(__p, this->__end_, __p + 1); 1836bdd1243dSDimitry Andric *__p = std::move(__tmp.get()); 18370b57cec5SDimitry Andric } 18380b57cec5SDimitry Andric } 18390b57cec5SDimitry Andric else 18400b57cec5SDimitry Andric { 18410b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 18420b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); 1843bdd1243dSDimitry Andric __v.emplace_back(std::forward<_Args>(__args)...); 18440b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 18450b57cec5SDimitry Andric } 1846bdd1243dSDimitry Andric return __make_iter(__p); 18470b57cec5SDimitry Andric} 18480b57cec5SDimitry Andric 18490b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1850bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 18510b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 18520b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x) 18530b57cec5SDimitry Andric{ 18540b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 18550b57cec5SDimitry Andric if (__n > 0) 18560b57cec5SDimitry Andric { 185761cfbce3SDimitry Andric // We can't compare unrelated pointers inside constant expressions 185861cfbce3SDimitry Andric if (!__libcpp_is_constant_evaluated() && __n <= static_cast<size_type>(this->__end_cap() - this->__end_)) 18590b57cec5SDimitry Andric { 18600b57cec5SDimitry Andric size_type __old_n = __n; 18610b57cec5SDimitry Andric pointer __old_last = this->__end_; 18620b57cec5SDimitry Andric if (__n > static_cast<size_type>(this->__end_ - __p)) 18630b57cec5SDimitry Andric { 18640b57cec5SDimitry Andric size_type __cx = __n - (this->__end_ - __p); 18650b57cec5SDimitry Andric __construct_at_end(__cx, __x); 18660b57cec5SDimitry Andric __n -= __cx; 18670b57cec5SDimitry Andric } 18680b57cec5SDimitry Andric if (__n > 0) 18690b57cec5SDimitry Andric { 18700b57cec5SDimitry Andric __move_range(__p, __old_last, __p + __old_n); 18710b57cec5SDimitry Andric const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); 18720b57cec5SDimitry Andric if (__p <= __xr && __xr < this->__end_) 18730b57cec5SDimitry Andric __xr += __old_n; 1874bdd1243dSDimitry Andric std::fill_n(__p, __n, *__xr); 18750b57cec5SDimitry Andric } 18760b57cec5SDimitry Andric } 18770b57cec5SDimitry Andric else 18780b57cec5SDimitry Andric { 18790b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 18800b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); 18810b57cec5SDimitry Andric __v.__construct_at_end(__n, __x); 18820b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 18830b57cec5SDimitry Andric } 18840b57cec5SDimitry Andric } 1885bdd1243dSDimitry Andric return __make_iter(__p); 18860b57cec5SDimitry Andric} 18870b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 188806c3fb27SDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value && 1889bdd1243dSDimitry Andric is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value, 1890bdd1243dSDimitry Andric int> > 1891bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator 18920b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) 18930b57cec5SDimitry Andric{ 189406c3fb27SDimitry Andric return __insert_with_sentinel(__position, __first, __last); 189506c3fb27SDimitry Andric} 189606c3fb27SDimitry Andric 189706c3fb27SDimitry Andrictemplate <class _Tp, class _Allocator> 189806c3fb27SDimitry Andrictemplate <class _InputIterator, class _Sentinel> 189906c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 190006c3fb27SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 190106c3fb27SDimitry Andricvector<_Tp, _Allocator>::__insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last) { 19020b57cec5SDimitry Andric difference_type __off = __position - begin(); 19030b57cec5SDimitry Andric pointer __p = this->__begin_ + __off; 19040b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 19050b57cec5SDimitry Andric pointer __old_last = this->__end_; 19060b57cec5SDimitry Andric for (; this->__end_ != this->__end_cap() && __first != __last; ++__first) 19070b57cec5SDimitry Andric { 1908e40139ffSDimitry Andric __construct_one_at_end(*__first); 19090b57cec5SDimitry Andric } 19100b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__a); 19110b57cec5SDimitry Andric if (__first != __last) 19120b57cec5SDimitry Andric { 191306c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 19140b57cec5SDimitry Andric try 19150b57cec5SDimitry Andric { 191606c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 191706c3fb27SDimitry Andric __v.__construct_at_end_with_sentinel(std::move(__first), std::move(__last)); 19180b57cec5SDimitry Andric difference_type __old_size = __old_last - this->__begin_; 19190b57cec5SDimitry Andric difference_type __old_p = __p - this->__begin_; 19200b57cec5SDimitry Andric reserve(__recommend(size() + __v.size())); 19210b57cec5SDimitry Andric __p = this->__begin_ + __old_p; 19220b57cec5SDimitry Andric __old_last = this->__begin_ + __old_size; 192306c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 19240b57cec5SDimitry Andric } 19250b57cec5SDimitry Andric catch (...) 19260b57cec5SDimitry Andric { 1927bdd1243dSDimitry Andric erase(__make_iter(__old_last), end()); 19280b57cec5SDimitry Andric throw; 19290b57cec5SDimitry Andric } 193006c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 19310b57cec5SDimitry Andric } 1932bdd1243dSDimitry Andric __p = std::rotate(__p, __old_last, this->__end_); 1933bdd1243dSDimitry Andric insert(__make_iter(__p), std::make_move_iterator(__v.begin()), 1934bdd1243dSDimitry Andric std::make_move_iterator(__v.end())); 19350b57cec5SDimitry Andric return begin() + __off; 19360b57cec5SDimitry Andric} 19370b57cec5SDimitry Andric 19380b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 193906c3fb27SDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value && 1940bdd1243dSDimitry Andric is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value, 1941bdd1243dSDimitry Andric int> > 1942bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator 19430b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) 19440b57cec5SDimitry Andric{ 194506c3fb27SDimitry Andric return __insert_with_size(__position, __first, __last, std::distance(__first, __last)); 194606c3fb27SDimitry Andric} 194706c3fb27SDimitry Andric 194806c3fb27SDimitry Andrictemplate <class _Tp, class _Allocator> 194906c3fb27SDimitry Andrictemplate <class _Iterator, class _Sentinel> 195006c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 195106c3fb27SDimitry Andrictypename vector<_Tp, _Allocator>::iterator 195206c3fb27SDimitry Andricvector<_Tp, _Allocator>::__insert_with_size(const_iterator __position, _Iterator __first, _Sentinel __last, 195306c3fb27SDimitry Andric difference_type __n) { 195406c3fb27SDimitry Andric auto __insertion_size = __n; 19550b57cec5SDimitry Andric pointer __p = this->__begin_ + (__position - begin()); 19560b57cec5SDimitry Andric if (__n > 0) 19570b57cec5SDimitry Andric { 19580b57cec5SDimitry Andric if (__n <= this->__end_cap() - this->__end_) 19590b57cec5SDimitry Andric { 19600b57cec5SDimitry Andric size_type __old_n = __n; 19610b57cec5SDimitry Andric pointer __old_last = this->__end_; 196206c3fb27SDimitry Andric _Iterator __m = std::next(__first, __n); 19630b57cec5SDimitry Andric difference_type __dx = this->__end_ - __p; 19640b57cec5SDimitry Andric if (__n > __dx) 19650b57cec5SDimitry Andric { 19660b57cec5SDimitry Andric __m = __first; 19670b57cec5SDimitry Andric difference_type __diff = this->__end_ - __p; 1968bdd1243dSDimitry Andric std::advance(__m, __diff); 19690b57cec5SDimitry Andric __construct_at_end(__m, __last, __n - __diff); 19700b57cec5SDimitry Andric __n = __dx; 19710b57cec5SDimitry Andric } 19720b57cec5SDimitry Andric if (__n > 0) 19730b57cec5SDimitry Andric { 19740b57cec5SDimitry Andric __move_range(__p, __old_last, __p + __old_n); 1975bdd1243dSDimitry Andric std::copy(__first, __m, __p); 19760b57cec5SDimitry Andric } 19770b57cec5SDimitry Andric } 19780b57cec5SDimitry Andric else 19790b57cec5SDimitry Andric { 19800b57cec5SDimitry Andric allocator_type& __a = this->__alloc(); 19810b57cec5SDimitry Andric __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); 198206c3fb27SDimitry Andric __v.__construct_at_end_with_size(__first, __insertion_size); 19830b57cec5SDimitry Andric __p = __swap_out_circular_buffer(__v, __p); 19840b57cec5SDimitry Andric } 19850b57cec5SDimitry Andric } 1986bdd1243dSDimitry Andric return __make_iter(__p); 19870b57cec5SDimitry Andric} 19880b57cec5SDimitry Andric 19890b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 1990bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 19910b57cec5SDimitry Andricvoid 19920b57cec5SDimitry Andricvector<_Tp, _Allocator>::resize(size_type __sz) 19930b57cec5SDimitry Andric{ 19940b57cec5SDimitry Andric size_type __cs = size(); 19950b57cec5SDimitry Andric if (__cs < __sz) 19960b57cec5SDimitry Andric this->__append(__sz - __cs); 19970b57cec5SDimitry Andric else if (__cs > __sz) 19980b57cec5SDimitry Andric this->__destruct_at_end(this->__begin_ + __sz); 19990b57cec5SDimitry Andric} 20000b57cec5SDimitry Andric 20010b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 2002bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 20030b57cec5SDimitry Andricvoid 20040b57cec5SDimitry Andricvector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x) 20050b57cec5SDimitry Andric{ 20060b57cec5SDimitry Andric size_type __cs = size(); 20070b57cec5SDimitry Andric if (__cs < __sz) 20080b57cec5SDimitry Andric this->__append(__sz - __cs, __x); 20090b57cec5SDimitry Andric else if (__cs > __sz) 20100b57cec5SDimitry Andric this->__destruct_at_end(this->__begin_ + __sz); 20110b57cec5SDimitry Andric} 20120b57cec5SDimitry Andric 20130b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 2014bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 20150b57cec5SDimitry Andricvoid 20160b57cec5SDimitry Andricvector<_Tp, _Allocator>::swap(vector& __x) 20170b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 20180b57cec5SDimitry Andric _NOEXCEPT 20190b57cec5SDimitry Andric#else 20200b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 20210b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value) 20220b57cec5SDimitry Andric#endif 20230b57cec5SDimitry Andric{ 202406c3fb27SDimitry Andric _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__alloc_traits::propagate_on_container_swap::value || 20250b57cec5SDimitry Andric this->__alloc() == __x.__alloc(), 20260b57cec5SDimitry Andric "vector::swap: Either propagate_on_container_swap must be true" 20270b57cec5SDimitry Andric " or the allocators must compare equal"); 2028bdd1243dSDimitry Andric std::swap(this->__begin_, __x.__begin_); 2029bdd1243dSDimitry Andric std::swap(this->__end_, __x.__end_); 2030bdd1243dSDimitry Andric std::swap(this->__end_cap(), __x.__end_cap()); 2031bdd1243dSDimitry Andric std::__swap_allocator(this->__alloc(), __x.__alloc(), 20320b57cec5SDimitry Andric integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>()); 20330b57cec5SDimitry Andric} 20340b57cec5SDimitry Andric 20350b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 2036bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 20370b57cec5SDimitry Andricbool 20380b57cec5SDimitry Andricvector<_Tp, _Allocator>::__invariants() const 20390b57cec5SDimitry Andric{ 20400b57cec5SDimitry Andric if (this->__begin_ == nullptr) 20410b57cec5SDimitry Andric { 20420b57cec5SDimitry Andric if (this->__end_ != nullptr || this->__end_cap() != nullptr) 20430b57cec5SDimitry Andric return false; 20440b57cec5SDimitry Andric } 20450b57cec5SDimitry Andric else 20460b57cec5SDimitry Andric { 20470b57cec5SDimitry Andric if (this->__begin_ > this->__end_) 20480b57cec5SDimitry Andric return false; 20490b57cec5SDimitry Andric if (this->__begin_ == this->__end_cap()) 20500b57cec5SDimitry Andric return false; 20510b57cec5SDimitry Andric if (this->__end_ > this->__end_cap()) 20520b57cec5SDimitry Andric return false; 20530b57cec5SDimitry Andric } 20540b57cec5SDimitry Andric return true; 20550b57cec5SDimitry Andric} 20560b57cec5SDimitry Andric 20570b57cec5SDimitry Andric// vector<bool> 20580b57cec5SDimitry Andric 20590b57cec5SDimitry Andrictemplate <class _Allocator> class vector<bool, _Allocator>; 20600b57cec5SDimitry Andric 20610b57cec5SDimitry Andrictemplate <class _Allocator> struct hash<vector<bool, _Allocator> >; 20620b57cec5SDimitry Andric 20630b57cec5SDimitry Andrictemplate <class _Allocator> 20640b57cec5SDimitry Andricstruct __has_storage_type<vector<bool, _Allocator> > 20650b57cec5SDimitry Andric{ 20660b57cec5SDimitry Andric static const bool value = true; 20670b57cec5SDimitry Andric}; 20680b57cec5SDimitry Andric 20690b57cec5SDimitry Andrictemplate <class _Allocator> 20700b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> 20710b57cec5SDimitry Andric{ 20720b57cec5SDimitry Andricpublic: 20730b57cec5SDimitry Andric typedef vector __self; 20740b57cec5SDimitry Andric typedef bool value_type; 20750b57cec5SDimitry Andric typedef _Allocator allocator_type; 20760b57cec5SDimitry Andric typedef allocator_traits<allocator_type> __alloc_traits; 20770b57cec5SDimitry Andric typedef typename __alloc_traits::size_type size_type; 20780b57cec5SDimitry Andric typedef typename __alloc_traits::difference_type difference_type; 20790b57cec5SDimitry Andric typedef size_type __storage_type; 20800b57cec5SDimitry Andric typedef __bit_iterator<vector, false> pointer; 20810b57cec5SDimitry Andric typedef __bit_iterator<vector, true> const_pointer; 20820b57cec5SDimitry Andric typedef pointer iterator; 20830b57cec5SDimitry Andric typedef const_pointer const_iterator; 2084bdd1243dSDimitry Andric typedef std::reverse_iterator<iterator> reverse_iterator; 2085bdd1243dSDimitry Andric typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 20860b57cec5SDimitry Andric 20870b57cec5SDimitry Andricprivate: 2088bdd1243dSDimitry Andric typedef __rebind_alloc<__alloc_traits, __storage_type> __storage_allocator; 20890b57cec5SDimitry Andric typedef allocator_traits<__storage_allocator> __storage_traits; 20900b57cec5SDimitry Andric typedef typename __storage_traits::pointer __storage_pointer; 20910b57cec5SDimitry Andric typedef typename __storage_traits::const_pointer __const_storage_pointer; 20920b57cec5SDimitry Andric 20930b57cec5SDimitry Andric __storage_pointer __begin_; 20940b57cec5SDimitry Andric size_type __size_; 20950b57cec5SDimitry Andric __compressed_pair<size_type, __storage_allocator> __cap_alloc_; 20960b57cec5SDimitry Andricpublic: 20970b57cec5SDimitry Andric typedef __bit_reference<vector> reference; 209881ad6265SDimitry Andric#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL 209981ad6265SDimitry Andric using const_reference = bool; 210081ad6265SDimitry Andric#else 21010b57cec5SDimitry Andric typedef __bit_const_reference<vector> const_reference; 210281ad6265SDimitry Andric#endif 21030b57cec5SDimitry Andricprivate: 2104bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 21050b57cec5SDimitry Andric size_type& __cap() _NOEXCEPT 21060b57cec5SDimitry Andric {return __cap_alloc_.first();} 2107bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 21080b57cec5SDimitry Andric const size_type& __cap() const _NOEXCEPT 21090b57cec5SDimitry Andric {return __cap_alloc_.first();} 2110bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 21110b57cec5SDimitry Andric __storage_allocator& __alloc() _NOEXCEPT 21120b57cec5SDimitry Andric {return __cap_alloc_.second();} 2113bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 21140b57cec5SDimitry Andric const __storage_allocator& __alloc() const _NOEXCEPT 21150b57cec5SDimitry Andric {return __cap_alloc_.second();} 21160b57cec5SDimitry Andric 21170b57cec5SDimitry Andric static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); 21180b57cec5SDimitry Andric 2119bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 21200b57cec5SDimitry Andric static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT 21210b57cec5SDimitry Andric {return __n * __bits_per_word;} 2122bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 21230b57cec5SDimitry Andric static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT 21240b57cec5SDimitry Andric {return (__n - 1) / __bits_per_word + 1;} 21250b57cec5SDimitry Andric 21260b57cec5SDimitry Andricpublic: 2127bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 21280b57cec5SDimitry Andric vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); 21290b57cec5SDimitry Andric 2130bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(const allocator_type& __a) 21310b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 21320b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value); 21330b57cec5SDimitry Andric#else 21340b57cec5SDimitry Andric _NOEXCEPT; 21350b57cec5SDimitry Andric#endif 213650d7464cSDimitry Andric 213750d7464cSDimitry Andricprivate: 213850d7464cSDimitry Andric class __destroy_vector { 213950d7464cSDimitry Andric public: 214006c3fb27SDimitry Andric _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI __destroy_vector(vector& __vec) : __vec_(__vec) {} 214150d7464cSDimitry Andric 2142bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() { 214350d7464cSDimitry Andric if (__vec_.__begin_ != nullptr) 214450d7464cSDimitry Andric __storage_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.__cap()); 214550d7464cSDimitry Andric } 214650d7464cSDimitry Andric 214750d7464cSDimitry Andric private: 214850d7464cSDimitry Andric vector& __vec_; 214950d7464cSDimitry Andric }; 215050d7464cSDimitry Andric 215150d7464cSDimitry Andricpublic: 2152bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~vector() { __destroy_vector(*this)(); } 215350d7464cSDimitry Andric 2154bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n); 215506c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 2156bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n, const allocator_type& __a); 21570b57cec5SDimitry Andric#endif 2158bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(size_type __n, const value_type& __v); 2159bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(size_type __n, const value_type& __v, const allocator_type& __a); 2160*5f757f3fSDimitry Andric template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0> 2161*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_InputIterator __first, _InputIterator __last); 2162*5f757f3fSDimitry Andric template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0> 2163*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a); 2164*5f757f3fSDimitry Andric template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0> 2165*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_ForwardIterator __first, _ForwardIterator __last); 2166*5f757f3fSDimitry Andric template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0> 2167*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a); 216806c3fb27SDimitry Andric 216906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 217006c3fb27SDimitry Andric template <_ContainerCompatibleRange<bool> _Range> 217106c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 217206c3fb27SDimitry Andric vector(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type()) 217306c3fb27SDimitry Andric : __begin_(nullptr), 217406c3fb27SDimitry Andric __size_(0), 217506c3fb27SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) { 217606c3fb27SDimitry Andric if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) { 217706c3fb27SDimitry Andric auto __n = static_cast<size_type>(ranges::distance(__range)); 217806c3fb27SDimitry Andric __init_with_size(ranges::begin(__range), ranges::end(__range), __n); 217906c3fb27SDimitry Andric 218006c3fb27SDimitry Andric } else { 218106c3fb27SDimitry Andric __init_with_sentinel(ranges::begin(__range), ranges::end(__range)); 218206c3fb27SDimitry Andric } 218306c3fb27SDimitry Andric } 218406c3fb27SDimitry Andric#endif 21850b57cec5SDimitry Andric 2186bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(const vector& __v); 2187bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(const vector& __v, const allocator_type& __a); 2188bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector& operator=(const vector& __v); 21890b57cec5SDimitry Andric 21900b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 2191bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(initializer_list<value_type> __il); 2192bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(initializer_list<value_type> __il, const allocator_type& __a); 21930b57cec5SDimitry Andric 2194bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 21950b57cec5SDimitry Andric vector& operator=(initializer_list<value_type> __il) 21960b57cec5SDimitry Andric {assign(__il.begin(), __il.end()); return *this;} 21970b57cec5SDimitry Andric 21980b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG 21990b57cec5SDimitry Andric 2200bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 220181ad6265SDimitry Andric vector(vector&& __v) 220206c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 220381ad6265SDimitry Andric noexcept; 220481ad6265SDimitry Andric#else 220581ad6265SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); 220681ad6265SDimitry Andric#endif 2207bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(vector&& __v, const __type_identity_t<allocator_type>& __a); 2208bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 220981ad6265SDimitry Andric vector& operator=(vector&& __v) 221081ad6265SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); 221181ad6265SDimitry Andric 2212*5f757f3fSDimitry Andric template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0> 22130b57cec5SDimitry Andric void 2214bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 assign(_InputIterator __first, _InputIterator __last); 2215*5f757f3fSDimitry Andric template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0> 22160b57cec5SDimitry Andric void 2217bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 assign(_ForwardIterator __first, _ForwardIterator __last); 22180b57cec5SDimitry Andric 221906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 222006c3fb27SDimitry Andric template <_ContainerCompatibleRange<bool> _Range> 222106c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 222206c3fb27SDimitry Andric constexpr void assign_range(_Range&& __range) { 222306c3fb27SDimitry Andric if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) { 222406c3fb27SDimitry Andric auto __n = static_cast<size_type>(ranges::distance(__range)); 222506c3fb27SDimitry Andric __assign_with_size(ranges::begin(__range), ranges::end(__range), __n); 222606c3fb27SDimitry Andric 222706c3fb27SDimitry Andric } else { 222806c3fb27SDimitry Andric __assign_with_sentinel(ranges::begin(__range), ranges::end(__range)); 222906c3fb27SDimitry Andric } 223006c3fb27SDimitry Andric } 223106c3fb27SDimitry Andric#endif 223206c3fb27SDimitry Andric 2233bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void assign(size_type __n, const value_type& __x); 22340b57cec5SDimitry Andric 22350b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 2236bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 22370b57cec5SDimitry Andric void assign(initializer_list<value_type> __il) 22380b57cec5SDimitry Andric {assign(__il.begin(), __il.end());} 22390b57cec5SDimitry Andric#endif 22400b57cec5SDimitry Andric 2241bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator_type get_allocator() const _NOEXCEPT 22420b57cec5SDimitry Andric {return allocator_type(this->__alloc());} 22430b57cec5SDimitry Andric 2244bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type max_size() const _NOEXCEPT; 2245bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 22460b57cec5SDimitry Andric size_type capacity() const _NOEXCEPT 22470b57cec5SDimitry Andric {return __internal_cap_to_external(__cap());} 2248bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 22490b57cec5SDimitry Andric size_type size() const _NOEXCEPT 22500b57cec5SDimitry Andric {return __size_;} 2251bdd1243dSDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 22520b57cec5SDimitry Andric bool empty() const _NOEXCEPT 22530b57cec5SDimitry Andric {return __size_ == 0;} 2254bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void reserve(size_type __n); 2255bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void shrink_to_fit() _NOEXCEPT; 22560b57cec5SDimitry Andric 2257bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 22580b57cec5SDimitry Andric iterator begin() _NOEXCEPT 22590b57cec5SDimitry Andric {return __make_iter(0);} 2260bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 22610b57cec5SDimitry Andric const_iterator begin() const _NOEXCEPT 22620b57cec5SDimitry Andric {return __make_iter(0);} 2263bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 22640b57cec5SDimitry Andric iterator end() _NOEXCEPT 22650b57cec5SDimitry Andric {return __make_iter(__size_);} 2266bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 22670b57cec5SDimitry Andric const_iterator end() const _NOEXCEPT 22680b57cec5SDimitry Andric {return __make_iter(__size_);} 22690b57cec5SDimitry Andric 2270bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 22710b57cec5SDimitry Andric reverse_iterator rbegin() _NOEXCEPT 22720b57cec5SDimitry Andric {return reverse_iterator(end());} 2273bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 22740b57cec5SDimitry Andric const_reverse_iterator rbegin() const _NOEXCEPT 22750b57cec5SDimitry Andric {return const_reverse_iterator(end());} 2276bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 22770b57cec5SDimitry Andric reverse_iterator rend() _NOEXCEPT 22780b57cec5SDimitry Andric {return reverse_iterator(begin());} 2279bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 22800b57cec5SDimitry Andric const_reverse_iterator rend() const _NOEXCEPT 22810b57cec5SDimitry Andric {return const_reverse_iterator(begin());} 22820b57cec5SDimitry Andric 2283bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 22840b57cec5SDimitry Andric const_iterator cbegin() const _NOEXCEPT 22850b57cec5SDimitry Andric {return __make_iter(0);} 2286bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 22870b57cec5SDimitry Andric const_iterator cend() const _NOEXCEPT 22880b57cec5SDimitry Andric {return __make_iter(__size_);} 2289bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 22900b57cec5SDimitry Andric const_reverse_iterator crbegin() const _NOEXCEPT 22910b57cec5SDimitry Andric {return rbegin();} 2292bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 22930b57cec5SDimitry Andric const_reverse_iterator crend() const _NOEXCEPT 22940b57cec5SDimitry Andric {return rend();} 22950b57cec5SDimitry Andric 2296bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator[](size_type __n) {return __make_ref(__n);} 2297bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference operator[](size_type __n) const {return __make_ref(__n);} 2298bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI reference at(size_type __n); 2299bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __n) const; 23000b57cec5SDimitry Andric 2301bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference front() {return __make_ref(0);} 2302bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference front() const {return __make_ref(0);} 2303bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference back() {return __make_ref(__size_ - 1);} 2304bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference back() const {return __make_ref(__size_ - 1);} 23050b57cec5SDimitry Andric 2306bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void push_back(const value_type& __x); 230706c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 23080b57cec5SDimitry Andric template <class... _Args> 230906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 2310bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference emplace_back(_Args&&... __args) 23110b57cec5SDimitry Andric#else 2312bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI void emplace_back(_Args&&... __args) 23130b57cec5SDimitry Andric#endif 23140b57cec5SDimitry Andric { 2315bdd1243dSDimitry Andric push_back ( value_type ( std::forward<_Args>(__args)... )); 231606c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 23170b57cec5SDimitry Andric return this->back(); 23180b57cec5SDimitry Andric#endif 23190b57cec5SDimitry Andric } 23200b57cec5SDimitry Andric#endif 23210b57cec5SDimitry Andric 232206c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 232306c3fb27SDimitry Andric template <_ContainerCompatibleRange<bool> _Range> 232406c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 232506c3fb27SDimitry Andric constexpr void append_range(_Range&& __range) { 232606c3fb27SDimitry Andric insert_range(end(), std::forward<_Range>(__range)); 232706c3fb27SDimitry Andric } 232806c3fb27SDimitry Andric#endif 232906c3fb27SDimitry Andric 2330bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void pop_back() {--__size_;} 23310b57cec5SDimitry Andric 233206c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 23330b57cec5SDimitry Andric template <class... _Args> 2334bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator emplace(const_iterator __position, _Args&&... __args) 2335bdd1243dSDimitry Andric { return insert ( __position, value_type ( std::forward<_Args>(__args)... )); } 23360b57cec5SDimitry Andric#endif 23370b57cec5SDimitry Andric 2338bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __position, const value_type& __x); 2339bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __position, size_type __n, const value_type& __x); 2340*5f757f3fSDimitry Andric template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0> 23410b57cec5SDimitry Andric iterator 2342bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 insert(const_iterator __position, _InputIterator __first, _InputIterator __last); 2343*5f757f3fSDimitry Andric template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0> 23440b57cec5SDimitry Andric iterator 2345bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); 23460b57cec5SDimitry Andric 234706c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 234806c3fb27SDimitry Andric template <_ContainerCompatibleRange<bool> _Range> 234906c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 235006c3fb27SDimitry Andric constexpr iterator insert_range(const_iterator __position, _Range&& __range) { 235106c3fb27SDimitry Andric if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) { 235206c3fb27SDimitry Andric auto __n = static_cast<size_type>(ranges::distance(__range)); 235306c3fb27SDimitry Andric return __insert_with_size(__position, ranges::begin(__range), ranges::end(__range), __n); 235406c3fb27SDimitry Andric 235506c3fb27SDimitry Andric } else { 235606c3fb27SDimitry Andric return __insert_with_sentinel(__position, ranges::begin(__range), ranges::end(__range)); 235706c3fb27SDimitry Andric } 235806c3fb27SDimitry Andric } 235906c3fb27SDimitry Andric#endif 236006c3fb27SDimitry Andric 23610b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 2362bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 23630b57cec5SDimitry Andric iterator insert(const_iterator __position, initializer_list<value_type> __il) 23640b57cec5SDimitry Andric {return insert(__position, __il.begin(), __il.end());} 23650b57cec5SDimitry Andric#endif 23660b57cec5SDimitry Andric 2367bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __position); 2368bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __first, const_iterator __last); 23690b57cec5SDimitry Andric 2370bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 23710b57cec5SDimitry Andric void clear() _NOEXCEPT {__size_ = 0;} 23720b57cec5SDimitry Andric 237306c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(vector&) 23740b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 23750b57cec5SDimitry Andric _NOEXCEPT; 23760b57cec5SDimitry Andric#else 23770b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 23780b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value); 23790b57cec5SDimitry Andric#endif 2380bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void swap(reference __x, reference __y) _NOEXCEPT { std::swap(__x, __y); } 23810b57cec5SDimitry Andric 2382bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void resize(size_type __sz, value_type __x = false); 2383bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void flip() _NOEXCEPT; 23840b57cec5SDimitry Andric 2385bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __invariants() const; 23860b57cec5SDimitry Andric 23870b57cec5SDimitry Andricprivate: 2388d56accc7SDimitry Andric _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI 2389d56accc7SDimitry Andric void __throw_length_error() const { 2390bdd1243dSDimitry Andric std::__throw_length_error("vector"); 2391d56accc7SDimitry Andric } 2392d56accc7SDimitry Andric 2393d56accc7SDimitry Andric _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI 2394d56accc7SDimitry Andric void __throw_out_of_range() const { 2395bdd1243dSDimitry Andric std::__throw_out_of_range("vector"); 2396d56accc7SDimitry Andric } 2397d56accc7SDimitry Andric 239806c3fb27SDimitry Andric template <class _InputIterator, class _Sentinel> 239906c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 240006c3fb27SDimitry Andric void __init_with_size(_InputIterator __first, _Sentinel __last, size_type __n) { 240106c3fb27SDimitry Andric auto __guard = std::__make_exception_guard(__destroy_vector(*this)); 240206c3fb27SDimitry Andric 240306c3fb27SDimitry Andric if (__n > 0) { 240406c3fb27SDimitry Andric __vallocate(__n); 240506c3fb27SDimitry Andric __construct_at_end(std::move(__first), std::move(__last), __n); 240606c3fb27SDimitry Andric } 240706c3fb27SDimitry Andric 240806c3fb27SDimitry Andric __guard.__complete(); 240906c3fb27SDimitry Andric } 241006c3fb27SDimitry Andric 241106c3fb27SDimitry Andric template <class _InputIterator, class _Sentinel> 241206c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 241306c3fb27SDimitry Andric void __init_with_sentinel(_InputIterator __first, _Sentinel __last) { 241406c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 241506c3fb27SDimitry Andric try { 241606c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 241706c3fb27SDimitry Andric for (; __first != __last; ++__first) 241806c3fb27SDimitry Andric push_back(*__first); 241906c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 242006c3fb27SDimitry Andric } catch (...) { 242106c3fb27SDimitry Andric if (__begin_ != nullptr) 242206c3fb27SDimitry Andric __storage_traits::deallocate(__alloc(), __begin_, __cap()); 242306c3fb27SDimitry Andric throw; 242406c3fb27SDimitry Andric } 242506c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 242606c3fb27SDimitry Andric } 242706c3fb27SDimitry Andric 242806c3fb27SDimitry Andric template <class _Iterator, class _Sentinel> 242906c3fb27SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 243006c3fb27SDimitry Andric void __assign_with_sentinel(_Iterator __first, _Sentinel __last); 243106c3fb27SDimitry Andric 243206c3fb27SDimitry Andric template <class _ForwardIterator, class _Sentinel> 243306c3fb27SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 243406c3fb27SDimitry Andric void __assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __ns); 243506c3fb27SDimitry Andric 243606c3fb27SDimitry Andric template <class _InputIterator, class _Sentinel> 243706c3fb27SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 243806c3fb27SDimitry Andric iterator __insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last); 243906c3fb27SDimitry Andric 244006c3fb27SDimitry Andric template <class _Iterator, class _Sentinel> 244106c3fb27SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 244206c3fb27SDimitry Andric iterator __insert_with_size(const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n); 244306c3fb27SDimitry Andric 244481ad6265SDimitry Andric // Allocate space for __n objects 244581ad6265SDimitry Andric // throws length_error if __n > max_size() 244681ad6265SDimitry Andric // throws (probably bad_alloc) if memory run out 244781ad6265SDimitry Andric // Precondition: __begin_ == __end_ == __cap() == 0 244881ad6265SDimitry Andric // Precondition: __n > 0 244981ad6265SDimitry Andric // Postcondition: capacity() >= __n 245081ad6265SDimitry Andric // Postcondition: size() == 0 2451bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __vallocate(size_type __n) { 245281ad6265SDimitry Andric if (__n > max_size()) 245381ad6265SDimitry Andric __throw_length_error(); 245481ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __external_cap_to_internal(__n)); 245581ad6265SDimitry Andric __begin_ = __allocation.ptr; 245681ad6265SDimitry Andric __size_ = 0; 245781ad6265SDimitry Andric __cap() = __allocation.count; 245861cfbce3SDimitry Andric if (__libcpp_is_constant_evaluated()) { 245961cfbce3SDimitry Andric for (size_type __i = 0; __i != __cap(); ++__i) 246061cfbce3SDimitry Andric std::__construct_at(std::__to_address(__begin_) + __i); 246161cfbce3SDimitry Andric } 246281ad6265SDimitry Andric } 246381ad6265SDimitry Andric 2464bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __vdeallocate() _NOEXCEPT; 2465bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 24660b57cec5SDimitry Andric static size_type __align_it(size_type __new_size) _NOEXCEPT 246781ad6265SDimitry Andric {return (__new_size + (__bits_per_word-1)) & ~((size_type)__bits_per_word-1);} 2468bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type __recommend(size_type __new_size) const; 2469bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __construct_at_end(size_type __n, bool __x); 247006c3fb27SDimitry Andric template <class _InputIterator, class _Sentinel> 247106c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 247206c3fb27SDimitry Andric void __construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n); 2473bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __append(size_type __n, const_reference __x); 2474bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 24750b57cec5SDimitry Andric reference __make_ref(size_type __pos) _NOEXCEPT 24760b57cec5SDimitry Andric {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} 2477bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 247881ad6265SDimitry Andric const_reference __make_ref(size_type __pos) const _NOEXCEPT { 247981ad6265SDimitry Andric return __bit_const_reference<vector>(__begin_ + __pos / __bits_per_word, 248081ad6265SDimitry Andric __storage_type(1) << __pos % __bits_per_word); 248181ad6265SDimitry Andric } 2482bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 24830b57cec5SDimitry Andric iterator __make_iter(size_type __pos) _NOEXCEPT 24840b57cec5SDimitry Andric {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));} 2485bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 24860b57cec5SDimitry Andric const_iterator __make_iter(size_type __pos) const _NOEXCEPT 24870b57cec5SDimitry Andric {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));} 2488bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 24890b57cec5SDimitry Andric iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT 24900b57cec5SDimitry Andric {return begin() + (__p - cbegin());} 24910b57cec5SDimitry Andric 2492bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 24930b57cec5SDimitry Andric void __copy_assign_alloc(const vector& __v) 24940b57cec5SDimitry Andric {__copy_assign_alloc(__v, integral_constant<bool, 24950b57cec5SDimitry Andric __storage_traits::propagate_on_container_copy_assignment::value>());} 2496bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 24970b57cec5SDimitry Andric void __copy_assign_alloc(const vector& __c, true_type) 24980b57cec5SDimitry Andric { 24990b57cec5SDimitry Andric if (__alloc() != __c.__alloc()) 25000b57cec5SDimitry Andric __vdeallocate(); 25010b57cec5SDimitry Andric __alloc() = __c.__alloc(); 25020b57cec5SDimitry Andric } 25030b57cec5SDimitry Andric 2504bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 25050b57cec5SDimitry Andric void __copy_assign_alloc(const vector&, false_type) 25060b57cec5SDimitry Andric {} 25070b57cec5SDimitry Andric 2508bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign(vector& __c, false_type); 2509bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign(vector& __c, true_type) 25100b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); 2511bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 25120b57cec5SDimitry Andric void __move_assign_alloc(vector& __c) 25130b57cec5SDimitry Andric _NOEXCEPT_( 25140b57cec5SDimitry Andric !__storage_traits::propagate_on_container_move_assignment::value || 25150b57cec5SDimitry Andric is_nothrow_move_assignable<allocator_type>::value) 25160b57cec5SDimitry Andric {__move_assign_alloc(__c, integral_constant<bool, 25170b57cec5SDimitry Andric __storage_traits::propagate_on_container_move_assignment::value>());} 2518bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 25190b57cec5SDimitry Andric void __move_assign_alloc(vector& __c, true_type) 25200b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 25210b57cec5SDimitry Andric { 2522bdd1243dSDimitry Andric __alloc() = std::move(__c.__alloc()); 25230b57cec5SDimitry Andric } 25240b57cec5SDimitry Andric 2525bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 25260b57cec5SDimitry Andric void __move_assign_alloc(vector&, false_type) 25270b57cec5SDimitry Andric _NOEXCEPT 25280b57cec5SDimitry Andric {} 25290b57cec5SDimitry Andric 2530bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t __hash_code() const _NOEXCEPT; 25310b57cec5SDimitry Andric 25320b57cec5SDimitry Andric friend class __bit_reference<vector>; 25330b57cec5SDimitry Andric friend class __bit_const_reference<vector>; 25340b57cec5SDimitry Andric friend class __bit_iterator<vector, false>; 25350b57cec5SDimitry Andric friend class __bit_iterator<vector, true>; 25360b57cec5SDimitry Andric friend struct __bit_array<vector>; 25370b57cec5SDimitry Andric friend struct _LIBCPP_TEMPLATE_VIS hash<vector>; 25380b57cec5SDimitry Andric}; 25390b57cec5SDimitry Andric 25400b57cec5SDimitry Andrictemplate <class _Allocator> 2541bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void 25420b57cec5SDimitry Andricvector<bool, _Allocator>::__vdeallocate() _NOEXCEPT 25430b57cec5SDimitry Andric{ 25440b57cec5SDimitry Andric if (this->__begin_ != nullptr) 25450b57cec5SDimitry Andric { 25460b57cec5SDimitry Andric __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap()); 25470b57cec5SDimitry Andric this->__begin_ = nullptr; 25480b57cec5SDimitry Andric this->__size_ = this->__cap() = 0; 25490b57cec5SDimitry Andric } 25500b57cec5SDimitry Andric} 25510b57cec5SDimitry Andric 25520b57cec5SDimitry Andrictemplate <class _Allocator> 2553bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 25540b57cec5SDimitry Andrictypename vector<bool, _Allocator>::size_type 25550b57cec5SDimitry Andricvector<bool, _Allocator>::max_size() const _NOEXCEPT 25560b57cec5SDimitry Andric{ 25570b57cec5SDimitry Andric size_type __amax = __storage_traits::max_size(__alloc()); 25580b57cec5SDimitry Andric size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always 25590b57cec5SDimitry Andric if (__nmax / __bits_per_word <= __amax) 25600b57cec5SDimitry Andric return __nmax; 25610b57cec5SDimitry Andric return __internal_cap_to_external(__amax); 25620b57cec5SDimitry Andric} 25630b57cec5SDimitry Andric 25640b57cec5SDimitry Andric// Precondition: __new_size > capacity() 25650b57cec5SDimitry Andrictemplate <class _Allocator> 2566bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 25670b57cec5SDimitry Andrictypename vector<bool, _Allocator>::size_type 25680b57cec5SDimitry Andricvector<bool, _Allocator>::__recommend(size_type __new_size) const 25690b57cec5SDimitry Andric{ 25700b57cec5SDimitry Andric const size_type __ms = max_size(); 25710b57cec5SDimitry Andric if (__new_size > __ms) 25720b57cec5SDimitry Andric this->__throw_length_error(); 25730b57cec5SDimitry Andric const size_type __cap = capacity(); 25740b57cec5SDimitry Andric if (__cap >= __ms / 2) 25750b57cec5SDimitry Andric return __ms; 2576bdd1243dSDimitry Andric return std::max(2 * __cap, __align_it(__new_size)); 25770b57cec5SDimitry Andric} 25780b57cec5SDimitry Andric 25790b57cec5SDimitry Andric// Default constructs __n objects starting at __end_ 25800b57cec5SDimitry Andric// Precondition: __n > 0 25810b57cec5SDimitry Andric// Precondition: size() + __n <= capacity() 25820b57cec5SDimitry Andric// Postcondition: size() == size() + __n 25830b57cec5SDimitry Andrictemplate <class _Allocator> 2584bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 25850b57cec5SDimitry Andricvoid 25860b57cec5SDimitry Andricvector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x) 25870b57cec5SDimitry Andric{ 25880b57cec5SDimitry Andric size_type __old_size = this->__size_; 25890b57cec5SDimitry Andric this->__size_ += __n; 25900b57cec5SDimitry Andric if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) 25910b57cec5SDimitry Andric { 25920b57cec5SDimitry Andric if (this->__size_ <= __bits_per_word) 25930b57cec5SDimitry Andric this->__begin_[0] = __storage_type(0); 25940b57cec5SDimitry Andric else 25950b57cec5SDimitry Andric this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0); 25960b57cec5SDimitry Andric } 2597bdd1243dSDimitry Andric std::fill_n(__make_iter(__old_size), __n, __x); 25980b57cec5SDimitry Andric} 25990b57cec5SDimitry Andric 26000b57cec5SDimitry Andrictemplate <class _Allocator> 260106c3fb27SDimitry Andrictemplate <class _InputIterator, class _Sentinel> 2602bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 260306c3fb27SDimitry Andricvoid vector<bool, _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) { 26040b57cec5SDimitry Andric size_type __old_size = this->__size_; 260506c3fb27SDimitry Andric this->__size_ += __n; 26060b57cec5SDimitry Andric if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) 26070b57cec5SDimitry Andric { 26080b57cec5SDimitry Andric if (this->__size_ <= __bits_per_word) 26090b57cec5SDimitry Andric this->__begin_[0] = __storage_type(0); 26100b57cec5SDimitry Andric else 26110b57cec5SDimitry Andric this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0); 26120b57cec5SDimitry Andric } 261306c3fb27SDimitry Andric std::__copy<_ClassicAlgPolicy>(__first, __last, __make_iter(__old_size)); 26140b57cec5SDimitry Andric} 26150b57cec5SDimitry Andric 26160b57cec5SDimitry Andrictemplate <class _Allocator> 2617bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 26180b57cec5SDimitry Andricvector<bool, _Allocator>::vector() 26190b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 26200b57cec5SDimitry Andric : __begin_(nullptr), 26210b57cec5SDimitry Andric __size_(0), 2622480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 26230b57cec5SDimitry Andric{ 26240b57cec5SDimitry Andric} 26250b57cec5SDimitry Andric 26260b57cec5SDimitry Andrictemplate <class _Allocator> 2627bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 26280b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const allocator_type& __a) 26290b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 26300b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) 26310b57cec5SDimitry Andric#else 26320b57cec5SDimitry Andric _NOEXCEPT 26330b57cec5SDimitry Andric#endif 26340b57cec5SDimitry Andric : __begin_(nullptr), 26350b57cec5SDimitry Andric __size_(0), 26360b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 26370b57cec5SDimitry Andric{ 26380b57cec5SDimitry Andric} 26390b57cec5SDimitry Andric 26400b57cec5SDimitry Andrictemplate <class _Allocator> 2641bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 26420b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n) 26430b57cec5SDimitry Andric : __begin_(nullptr), 26440b57cec5SDimitry Andric __size_(0), 2645480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 26460b57cec5SDimitry Andric{ 26470b57cec5SDimitry Andric if (__n > 0) 26480b57cec5SDimitry Andric { 26490b57cec5SDimitry Andric __vallocate(__n); 26500b57cec5SDimitry Andric __construct_at_end(__n, false); 26510b57cec5SDimitry Andric } 26520b57cec5SDimitry Andric} 26530b57cec5SDimitry Andric 265406c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 26550b57cec5SDimitry Andrictemplate <class _Allocator> 2656bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 26570b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a) 26580b57cec5SDimitry Andric : __begin_(nullptr), 26590b57cec5SDimitry Andric __size_(0), 26600b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 26610b57cec5SDimitry Andric{ 26620b57cec5SDimitry Andric if (__n > 0) 26630b57cec5SDimitry Andric { 26640b57cec5SDimitry Andric __vallocate(__n); 26650b57cec5SDimitry Andric __construct_at_end(__n, false); 26660b57cec5SDimitry Andric } 26670b57cec5SDimitry Andric} 26680b57cec5SDimitry Andric#endif 26690b57cec5SDimitry Andric 26700b57cec5SDimitry Andrictemplate <class _Allocator> 2671bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 26720b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const value_type& __x) 26730b57cec5SDimitry Andric : __begin_(nullptr), 26740b57cec5SDimitry Andric __size_(0), 2675480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 26760b57cec5SDimitry Andric{ 26770b57cec5SDimitry Andric if (__n > 0) 26780b57cec5SDimitry Andric { 26790b57cec5SDimitry Andric __vallocate(__n); 26800b57cec5SDimitry Andric __construct_at_end(__n, __x); 26810b57cec5SDimitry Andric } 26820b57cec5SDimitry Andric} 26830b57cec5SDimitry Andric 26840b57cec5SDimitry Andrictemplate <class _Allocator> 2685bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 26860b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a) 26870b57cec5SDimitry Andric : __begin_(nullptr), 26880b57cec5SDimitry Andric __size_(0), 26890b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 26900b57cec5SDimitry Andric{ 26910b57cec5SDimitry Andric if (__n > 0) 26920b57cec5SDimitry Andric { 26930b57cec5SDimitry Andric __vallocate(__n); 26940b57cec5SDimitry Andric __construct_at_end(__n, __x); 26950b57cec5SDimitry Andric } 26960b57cec5SDimitry Andric} 26970b57cec5SDimitry Andric 26980b57cec5SDimitry Andrictemplate <class _Allocator> 2699*5f757f3fSDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> > 2700bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 2701*5f757f3fSDimitry Andricvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last) 27020b57cec5SDimitry Andric : __begin_(nullptr), 27030b57cec5SDimitry Andric __size_(0), 2704480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 27050b57cec5SDimitry Andric{ 270606c3fb27SDimitry Andric __init_with_sentinel(__first, __last); 27070b57cec5SDimitry Andric} 27080b57cec5SDimitry Andric 27090b57cec5SDimitry Andrictemplate <class _Allocator> 2710*5f757f3fSDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> > 2711bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 2712*5f757f3fSDimitry Andricvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a) 27130b57cec5SDimitry Andric : __begin_(nullptr), 27140b57cec5SDimitry Andric __size_(0), 27150b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 27160b57cec5SDimitry Andric{ 271706c3fb27SDimitry Andric __init_with_sentinel(__first, __last); 27180b57cec5SDimitry Andric} 27190b57cec5SDimitry Andric 27200b57cec5SDimitry Andrictemplate <class _Allocator> 2721*5f757f3fSDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> > 2722bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 2723*5f757f3fSDimitry Andricvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last) 27240b57cec5SDimitry Andric : __begin_(nullptr), 27250b57cec5SDimitry Andric __size_(0), 2726480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 27270b57cec5SDimitry Andric{ 272806c3fb27SDimitry Andric auto __n = static_cast<size_type>(std::distance(__first, __last)); 272906c3fb27SDimitry Andric __init_with_size(__first, __last, __n); 27300b57cec5SDimitry Andric} 27310b57cec5SDimitry Andric 27320b57cec5SDimitry Andrictemplate <class _Allocator> 2733*5f757f3fSDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> > 2734bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 2735*5f757f3fSDimitry Andricvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a) 27360b57cec5SDimitry Andric : __begin_(nullptr), 27370b57cec5SDimitry Andric __size_(0), 27380b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 27390b57cec5SDimitry Andric{ 274006c3fb27SDimitry Andric auto __n = static_cast<size_type>(std::distance(__first, __last)); 274106c3fb27SDimitry Andric __init_with_size(__first, __last, __n); 27420b57cec5SDimitry Andric} 27430b57cec5SDimitry Andric 27440b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 27450b57cec5SDimitry Andric 27460b57cec5SDimitry Andrictemplate <class _Allocator> 2747bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 27480b57cec5SDimitry Andricvector<bool, _Allocator>::vector(initializer_list<value_type> __il) 27490b57cec5SDimitry Andric : __begin_(nullptr), 27500b57cec5SDimitry Andric __size_(0), 2751480093f4SDimitry Andric __cap_alloc_(0, __default_init_tag()) 27520b57cec5SDimitry Andric{ 27530b57cec5SDimitry Andric size_type __n = static_cast<size_type>(__il.size()); 27540b57cec5SDimitry Andric if (__n > 0) 27550b57cec5SDimitry Andric { 27560b57cec5SDimitry Andric __vallocate(__n); 275706c3fb27SDimitry Andric __construct_at_end(__il.begin(), __il.end(), __n); 27580b57cec5SDimitry Andric } 27590b57cec5SDimitry Andric} 27600b57cec5SDimitry Andric 27610b57cec5SDimitry Andrictemplate <class _Allocator> 2762bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 27630b57cec5SDimitry Andricvector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) 27640b57cec5SDimitry Andric : __begin_(nullptr), 27650b57cec5SDimitry Andric __size_(0), 27660b57cec5SDimitry Andric __cap_alloc_(0, static_cast<__storage_allocator>(__a)) 27670b57cec5SDimitry Andric{ 27680b57cec5SDimitry Andric size_type __n = static_cast<size_type>(__il.size()); 27690b57cec5SDimitry Andric if (__n > 0) 27700b57cec5SDimitry Andric { 27710b57cec5SDimitry Andric __vallocate(__n); 277206c3fb27SDimitry Andric __construct_at_end(__il.begin(), __il.end(), __n); 27730b57cec5SDimitry Andric } 27740b57cec5SDimitry Andric} 27750b57cec5SDimitry Andric 27760b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 27770b57cec5SDimitry Andric 27780b57cec5SDimitry Andrictemplate <class _Allocator> 2779bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 27800b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const vector& __v) 27810b57cec5SDimitry Andric : __begin_(nullptr), 27820b57cec5SDimitry Andric __size_(0), 27830b57cec5SDimitry Andric __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc())) 27840b57cec5SDimitry Andric{ 27850b57cec5SDimitry Andric if (__v.size() > 0) 27860b57cec5SDimitry Andric { 27870b57cec5SDimitry Andric __vallocate(__v.size()); 278806c3fb27SDimitry Andric __construct_at_end(__v.begin(), __v.end(), __v.size()); 27890b57cec5SDimitry Andric } 27900b57cec5SDimitry Andric} 27910b57cec5SDimitry Andric 27920b57cec5SDimitry Andrictemplate <class _Allocator> 2793bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 27940b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a) 27950b57cec5SDimitry Andric : __begin_(nullptr), 27960b57cec5SDimitry Andric __size_(0), 27970b57cec5SDimitry Andric __cap_alloc_(0, __a) 27980b57cec5SDimitry Andric{ 27990b57cec5SDimitry Andric if (__v.size() > 0) 28000b57cec5SDimitry Andric { 28010b57cec5SDimitry Andric __vallocate(__v.size()); 280206c3fb27SDimitry Andric __construct_at_end(__v.begin(), __v.end(), __v.size()); 28030b57cec5SDimitry Andric } 28040b57cec5SDimitry Andric} 28050b57cec5SDimitry Andric 28060b57cec5SDimitry Andrictemplate <class _Allocator> 2807bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 28080b57cec5SDimitry Andricvector<bool, _Allocator>& 28090b57cec5SDimitry Andricvector<bool, _Allocator>::operator=(const vector& __v) 28100b57cec5SDimitry Andric{ 2811bdd1243dSDimitry Andric if (this != std::addressof(__v)) 28120b57cec5SDimitry Andric { 28130b57cec5SDimitry Andric __copy_assign_alloc(__v); 28140b57cec5SDimitry Andric if (__v.__size_) 28150b57cec5SDimitry Andric { 28160b57cec5SDimitry Andric if (__v.__size_ > capacity()) 28170b57cec5SDimitry Andric { 28180b57cec5SDimitry Andric __vdeallocate(); 28190b57cec5SDimitry Andric __vallocate(__v.__size_); 28200b57cec5SDimitry Andric } 2821bdd1243dSDimitry Andric std::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_); 28220b57cec5SDimitry Andric } 28230b57cec5SDimitry Andric __size_ = __v.__size_; 28240b57cec5SDimitry Andric } 28250b57cec5SDimitry Andric return *this; 28260b57cec5SDimitry Andric} 28270b57cec5SDimitry Andric 28280b57cec5SDimitry Andrictemplate <class _Allocator> 2829bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(vector&& __v) 283006c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 28310b57cec5SDimitry Andric _NOEXCEPT 28320b57cec5SDimitry Andric#else 28330b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 28340b57cec5SDimitry Andric#endif 28350b57cec5SDimitry Andric : __begin_(__v.__begin_), 28360b57cec5SDimitry Andric __size_(__v.__size_), 2837bdd1243dSDimitry Andric __cap_alloc_(std::move(__v.__cap_alloc_)) { 28380b57cec5SDimitry Andric __v.__begin_ = nullptr; 28390b57cec5SDimitry Andric __v.__size_ = 0; 28400b57cec5SDimitry Andric __v.__cap() = 0; 28410b57cec5SDimitry Andric} 28420b57cec5SDimitry Andric 28430b57cec5SDimitry Andrictemplate <class _Allocator> 2844bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 284581ad6265SDimitry Andricvector<bool, _Allocator>::vector(vector&& __v, const __type_identity_t<allocator_type>& __a) 28460b57cec5SDimitry Andric : __begin_(nullptr), 28470b57cec5SDimitry Andric __size_(0), 28480b57cec5SDimitry Andric __cap_alloc_(0, __a) 28490b57cec5SDimitry Andric{ 28500b57cec5SDimitry Andric if (__a == allocator_type(__v.__alloc())) 28510b57cec5SDimitry Andric { 28520b57cec5SDimitry Andric this->__begin_ = __v.__begin_; 28530b57cec5SDimitry Andric this->__size_ = __v.__size_; 28540b57cec5SDimitry Andric this->__cap() = __v.__cap(); 28550b57cec5SDimitry Andric __v.__begin_ = nullptr; 28560b57cec5SDimitry Andric __v.__cap() = __v.__size_ = 0; 28570b57cec5SDimitry Andric } 28580b57cec5SDimitry Andric else if (__v.size() > 0) 28590b57cec5SDimitry Andric { 28600b57cec5SDimitry Andric __vallocate(__v.size()); 286106c3fb27SDimitry Andric __construct_at_end(__v.begin(), __v.end(), __v.size()); 28620b57cec5SDimitry Andric } 28630b57cec5SDimitry Andric} 28640b57cec5SDimitry Andric 28650b57cec5SDimitry Andrictemplate <class _Allocator> 2866bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 28670b57cec5SDimitry Andricvector<bool, _Allocator>& 28680b57cec5SDimitry Andricvector<bool, _Allocator>::operator=(vector&& __v) 28690b57cec5SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) 28700b57cec5SDimitry Andric{ 28710b57cec5SDimitry Andric __move_assign(__v, integral_constant<bool, 28720b57cec5SDimitry Andric __storage_traits::propagate_on_container_move_assignment::value>()); 28730b57cec5SDimitry Andric return *this; 28740b57cec5SDimitry Andric} 28750b57cec5SDimitry Andric 28760b57cec5SDimitry Andrictemplate <class _Allocator> 2877bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void 28780b57cec5SDimitry Andricvector<bool, _Allocator>::__move_assign(vector& __c, false_type) 28790b57cec5SDimitry Andric{ 28800b57cec5SDimitry Andric if (__alloc() != __c.__alloc()) 28810b57cec5SDimitry Andric assign(__c.begin(), __c.end()); 28820b57cec5SDimitry Andric else 28830b57cec5SDimitry Andric __move_assign(__c, true_type()); 28840b57cec5SDimitry Andric} 28850b57cec5SDimitry Andric 28860b57cec5SDimitry Andrictemplate <class _Allocator> 2887bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void 28880b57cec5SDimitry Andricvector<bool, _Allocator>::__move_assign(vector& __c, true_type) 28890b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 28900b57cec5SDimitry Andric{ 28910b57cec5SDimitry Andric __vdeallocate(); 28920b57cec5SDimitry Andric __move_assign_alloc(__c); 28930b57cec5SDimitry Andric this->__begin_ = __c.__begin_; 28940b57cec5SDimitry Andric this->__size_ = __c.__size_; 28950b57cec5SDimitry Andric this->__cap() = __c.__cap(); 28960b57cec5SDimitry Andric __c.__begin_ = nullptr; 28970b57cec5SDimitry Andric __c.__cap() = __c.__size_ = 0; 28980b57cec5SDimitry Andric} 28990b57cec5SDimitry Andric 29000b57cec5SDimitry Andrictemplate <class _Allocator> 2901bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void 29020b57cec5SDimitry Andricvector<bool, _Allocator>::assign(size_type __n, const value_type& __x) 29030b57cec5SDimitry Andric{ 29040b57cec5SDimitry Andric __size_ = 0; 29050b57cec5SDimitry Andric if (__n > 0) 29060b57cec5SDimitry Andric { 29070b57cec5SDimitry Andric size_type __c = capacity(); 29080b57cec5SDimitry Andric if (__n <= __c) 29090b57cec5SDimitry Andric __size_ = __n; 29100b57cec5SDimitry Andric else 29110b57cec5SDimitry Andric { 2912349cc55cSDimitry Andric vector __v(get_allocator()); 29130b57cec5SDimitry Andric __v.reserve(__recommend(__n)); 29140b57cec5SDimitry Andric __v.__size_ = __n; 29150b57cec5SDimitry Andric swap(__v); 29160b57cec5SDimitry Andric } 2917bdd1243dSDimitry Andric std::fill_n(begin(), __n, __x); 29180b57cec5SDimitry Andric } 29190b57cec5SDimitry Andric} 29200b57cec5SDimitry Andric 29210b57cec5SDimitry Andrictemplate <class _Allocator> 2922*5f757f3fSDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> > 2923*5f757f3fSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 29240b57cec5SDimitry Andricvoid 29250b57cec5SDimitry Andricvector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last) 29260b57cec5SDimitry Andric{ 292706c3fb27SDimitry Andric __assign_with_sentinel(__first, __last); 292806c3fb27SDimitry Andric} 292906c3fb27SDimitry Andric 293006c3fb27SDimitry Andrictemplate <class _Allocator> 293106c3fb27SDimitry Andrictemplate <class _Iterator, class _Sentinel> 293206c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 293306c3fb27SDimitry Andricvoid vector<bool, _Allocator>::__assign_with_sentinel(_Iterator __first, _Sentinel __last) { 29340b57cec5SDimitry Andric clear(); 29350b57cec5SDimitry Andric for (; __first != __last; ++__first) 29360b57cec5SDimitry Andric push_back(*__first); 29370b57cec5SDimitry Andric} 29380b57cec5SDimitry Andric 29390b57cec5SDimitry Andrictemplate <class _Allocator> 2940*5f757f3fSDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> > 2941bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 29420b57cec5SDimitry Andricvoid 29430b57cec5SDimitry Andricvector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) 29440b57cec5SDimitry Andric{ 294506c3fb27SDimitry Andric __assign_with_size(__first, __last, std::distance(__first, __last)); 294606c3fb27SDimitry Andric} 294706c3fb27SDimitry Andric 294806c3fb27SDimitry Andrictemplate <class _Allocator> 294906c3fb27SDimitry Andrictemplate <class _ForwardIterator, class _Sentinel> 295006c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 295106c3fb27SDimitry Andricvoid vector<bool, _Allocator>::__assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __ns) { 295206c3fb27SDimitry Andric _LIBCPP_ASSERT_VALID_INPUT_RANGE(__ns >= 0, "invalid range specified"); 295306c3fb27SDimitry Andric 29540b57cec5SDimitry Andric clear(); 295506c3fb27SDimitry Andric 29560b57cec5SDimitry Andric const size_t __n = static_cast<size_type>(__ns); 29570b57cec5SDimitry Andric if (__n) 29580b57cec5SDimitry Andric { 29590b57cec5SDimitry Andric if (__n > capacity()) 29600b57cec5SDimitry Andric { 29610b57cec5SDimitry Andric __vdeallocate(); 29620b57cec5SDimitry Andric __vallocate(__n); 29630b57cec5SDimitry Andric } 296406c3fb27SDimitry Andric __construct_at_end(__first, __last, __n); 29650b57cec5SDimitry Andric } 29660b57cec5SDimitry Andric} 29670b57cec5SDimitry Andric 29680b57cec5SDimitry Andrictemplate <class _Allocator> 2969bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void 29700b57cec5SDimitry Andricvector<bool, _Allocator>::reserve(size_type __n) 29710b57cec5SDimitry Andric{ 29720b57cec5SDimitry Andric if (__n > capacity()) 29730b57cec5SDimitry Andric { 2974349cc55cSDimitry Andric if (__n > max_size()) 2975349cc55cSDimitry Andric this->__throw_length_error(); 2976349cc55cSDimitry Andric vector __v(this->get_allocator()); 29770b57cec5SDimitry Andric __v.__vallocate(__n); 297806c3fb27SDimitry Andric __v.__construct_at_end(this->begin(), this->end(), this->size()); 29790b57cec5SDimitry Andric swap(__v); 29800b57cec5SDimitry Andric } 29810b57cec5SDimitry Andric} 29820b57cec5SDimitry Andric 29830b57cec5SDimitry Andrictemplate <class _Allocator> 2984bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void 29850b57cec5SDimitry Andricvector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT 29860b57cec5SDimitry Andric{ 29870b57cec5SDimitry Andric if (__external_cap_to_internal(size()) > __cap()) 29880b57cec5SDimitry Andric { 298906c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 29900b57cec5SDimitry Andric try 29910b57cec5SDimitry Andric { 299206c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 29930b57cec5SDimitry Andric vector(*this, allocator_type(__alloc())).swap(*this); 299406c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 29950b57cec5SDimitry Andric } 29960b57cec5SDimitry Andric catch (...) 29970b57cec5SDimitry Andric { 29980b57cec5SDimitry Andric } 299906c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 30000b57cec5SDimitry Andric } 30010b57cec5SDimitry Andric} 30020b57cec5SDimitry Andric 30030b57cec5SDimitry Andrictemplate <class _Allocator> 30040b57cec5SDimitry Andrictypename vector<bool, _Allocator>::reference 30050b57cec5SDimitry Andricvector<bool, _Allocator>::at(size_type __n) 30060b57cec5SDimitry Andric{ 30070b57cec5SDimitry Andric if (__n >= size()) 30080b57cec5SDimitry Andric this->__throw_out_of_range(); 30090b57cec5SDimitry Andric return (*this)[__n]; 30100b57cec5SDimitry Andric} 30110b57cec5SDimitry Andric 30120b57cec5SDimitry Andrictemplate <class _Allocator> 30130b57cec5SDimitry Andrictypename vector<bool, _Allocator>::const_reference 30140b57cec5SDimitry Andricvector<bool, _Allocator>::at(size_type __n) const 30150b57cec5SDimitry Andric{ 30160b57cec5SDimitry Andric if (__n >= size()) 30170b57cec5SDimitry Andric this->__throw_out_of_range(); 30180b57cec5SDimitry Andric return (*this)[__n]; 30190b57cec5SDimitry Andric} 30200b57cec5SDimitry Andric 30210b57cec5SDimitry Andrictemplate <class _Allocator> 3022bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void 30230b57cec5SDimitry Andricvector<bool, _Allocator>::push_back(const value_type& __x) 30240b57cec5SDimitry Andric{ 30250b57cec5SDimitry Andric if (this->__size_ == this->capacity()) 30260b57cec5SDimitry Andric reserve(__recommend(this->__size_ + 1)); 30270b57cec5SDimitry Andric ++this->__size_; 30280b57cec5SDimitry Andric back() = __x; 30290b57cec5SDimitry Andric} 30300b57cec5SDimitry Andric 30310b57cec5SDimitry Andrictemplate <class _Allocator> 3032bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator 30330b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x) 30340b57cec5SDimitry Andric{ 30350b57cec5SDimitry Andric iterator __r; 30360b57cec5SDimitry Andric if (size() < capacity()) 30370b57cec5SDimitry Andric { 30380b57cec5SDimitry Andric const_iterator __old_end = end(); 30390b57cec5SDimitry Andric ++__size_; 3040bdd1243dSDimitry Andric std::copy_backward(__position, __old_end, end()); 30410b57cec5SDimitry Andric __r = __const_iterator_cast(__position); 30420b57cec5SDimitry Andric } 30430b57cec5SDimitry Andric else 30440b57cec5SDimitry Andric { 3045349cc55cSDimitry Andric vector __v(get_allocator()); 30460b57cec5SDimitry Andric __v.reserve(__recommend(__size_ + 1)); 30470b57cec5SDimitry Andric __v.__size_ = __size_ + 1; 3048bdd1243dSDimitry Andric __r = std::copy(cbegin(), __position, __v.begin()); 3049bdd1243dSDimitry Andric std::copy_backward(__position, cend(), __v.end()); 30500b57cec5SDimitry Andric swap(__v); 30510b57cec5SDimitry Andric } 30520b57cec5SDimitry Andric *__r = __x; 30530b57cec5SDimitry Andric return __r; 30540b57cec5SDimitry Andric} 30550b57cec5SDimitry Andric 30560b57cec5SDimitry Andrictemplate <class _Allocator> 3057bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator 30580b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x) 30590b57cec5SDimitry Andric{ 30600b57cec5SDimitry Andric iterator __r; 30610b57cec5SDimitry Andric size_type __c = capacity(); 30620b57cec5SDimitry Andric if (__n <= __c && size() <= __c - __n) 30630b57cec5SDimitry Andric { 30640b57cec5SDimitry Andric const_iterator __old_end = end(); 30650b57cec5SDimitry Andric __size_ += __n; 3066bdd1243dSDimitry Andric std::copy_backward(__position, __old_end, end()); 30670b57cec5SDimitry Andric __r = __const_iterator_cast(__position); 30680b57cec5SDimitry Andric } 30690b57cec5SDimitry Andric else 30700b57cec5SDimitry Andric { 3071349cc55cSDimitry Andric vector __v(get_allocator()); 30720b57cec5SDimitry Andric __v.reserve(__recommend(__size_ + __n)); 30730b57cec5SDimitry Andric __v.__size_ = __size_ + __n; 3074bdd1243dSDimitry Andric __r = std::copy(cbegin(), __position, __v.begin()); 3075bdd1243dSDimitry Andric std::copy_backward(__position, cend(), __v.end()); 30760b57cec5SDimitry Andric swap(__v); 30770b57cec5SDimitry Andric } 3078bdd1243dSDimitry Andric std::fill_n(__r, __n, __x); 30790b57cec5SDimitry Andric return __r; 30800b57cec5SDimitry Andric} 30810b57cec5SDimitry Andric 30820b57cec5SDimitry Andrictemplate <class _Allocator> 3083*5f757f3fSDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> > 3084*5f757f3fSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 30850b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator 30860b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) 30870b57cec5SDimitry Andric{ 308806c3fb27SDimitry Andric return __insert_with_sentinel(__position, __first, __last); 308906c3fb27SDimitry Andric} 309006c3fb27SDimitry Andric 309106c3fb27SDimitry Andrictemplate <class _Allocator> 309206c3fb27SDimitry Andrictemplate <class _InputIterator, class _Sentinel> 309306c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 309406c3fb27SDimitry Andrictypename vector<bool, _Allocator>::iterator 309506c3fb27SDimitry Andricvector<bool, _Allocator>::__insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last) { 30960b57cec5SDimitry Andric difference_type __off = __position - begin(); 30970b57cec5SDimitry Andric iterator __p = __const_iterator_cast(__position); 30980b57cec5SDimitry Andric iterator __old_end = end(); 30990b57cec5SDimitry Andric for (; size() != capacity() && __first != __last; ++__first) 31000b57cec5SDimitry Andric { 31010b57cec5SDimitry Andric ++this->__size_; 31020b57cec5SDimitry Andric back() = *__first; 31030b57cec5SDimitry Andric } 3104349cc55cSDimitry Andric vector __v(get_allocator()); 31050b57cec5SDimitry Andric if (__first != __last) 31060b57cec5SDimitry Andric { 310706c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 31080b57cec5SDimitry Andric try 31090b57cec5SDimitry Andric { 311006c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 311106c3fb27SDimitry Andric __v.__assign_with_sentinel(std::move(__first), std::move(__last)); 31120b57cec5SDimitry Andric difference_type __old_size = static_cast<difference_type>(__old_end - begin()); 31130b57cec5SDimitry Andric difference_type __old_p = __p - begin(); 31140b57cec5SDimitry Andric reserve(__recommend(size() + __v.size())); 31150b57cec5SDimitry Andric __p = begin() + __old_p; 31160b57cec5SDimitry Andric __old_end = begin() + __old_size; 311706c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 31180b57cec5SDimitry Andric } 31190b57cec5SDimitry Andric catch (...) 31200b57cec5SDimitry Andric { 31210b57cec5SDimitry Andric erase(__old_end, end()); 31220b57cec5SDimitry Andric throw; 31230b57cec5SDimitry Andric } 312406c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 31250b57cec5SDimitry Andric } 3126bdd1243dSDimitry Andric __p = std::rotate(__p, __old_end, end()); 31270b57cec5SDimitry Andric insert(__p, __v.begin(), __v.end()); 31280b57cec5SDimitry Andric return begin() + __off; 31290b57cec5SDimitry Andric} 31300b57cec5SDimitry Andric 31310b57cec5SDimitry Andrictemplate <class _Allocator> 3132*5f757f3fSDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> > 3133bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 31340b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator 31350b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) 31360b57cec5SDimitry Andric{ 313706c3fb27SDimitry Andric return __insert_with_size(__position, __first, __last, std::distance(__first, __last)); 313806c3fb27SDimitry Andric} 313906c3fb27SDimitry Andric 314006c3fb27SDimitry Andrictemplate <class _Allocator> 314106c3fb27SDimitry Andrictemplate <class _ForwardIterator, class _Sentinel> 314206c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 314306c3fb27SDimitry Andrictypename vector<bool, _Allocator>::iterator 314406c3fb27SDimitry Andricvector<bool, _Allocator>::__insert_with_size(const_iterator __position, _ForwardIterator __first, _Sentinel __last, 314506c3fb27SDimitry Andric difference_type __n_signed) { 314606c3fb27SDimitry Andric _LIBCPP_ASSERT_VALID_INPUT_RANGE(__n_signed >= 0, "invalid range specified"); 31470b57cec5SDimitry Andric const size_type __n = static_cast<size_type>(__n_signed); 31480b57cec5SDimitry Andric iterator __r; 31490b57cec5SDimitry Andric size_type __c = capacity(); 31500b57cec5SDimitry Andric if (__n <= __c && size() <= __c - __n) 31510b57cec5SDimitry Andric { 31520b57cec5SDimitry Andric const_iterator __old_end = end(); 31530b57cec5SDimitry Andric __size_ += __n; 3154bdd1243dSDimitry Andric std::copy_backward(__position, __old_end, end()); 31550b57cec5SDimitry Andric __r = __const_iterator_cast(__position); 31560b57cec5SDimitry Andric } 31570b57cec5SDimitry Andric else 31580b57cec5SDimitry Andric { 3159349cc55cSDimitry Andric vector __v(get_allocator()); 31600b57cec5SDimitry Andric __v.reserve(__recommend(__size_ + __n)); 31610b57cec5SDimitry Andric __v.__size_ = __size_ + __n; 3162bdd1243dSDimitry Andric __r = std::copy(cbegin(), __position, __v.begin()); 3163bdd1243dSDimitry Andric std::copy_backward(__position, cend(), __v.end()); 31640b57cec5SDimitry Andric swap(__v); 31650b57cec5SDimitry Andric } 316606c3fb27SDimitry Andric std::__copy<_ClassicAlgPolicy>(__first, __last, __r); 31670b57cec5SDimitry Andric return __r; 31680b57cec5SDimitry Andric} 31690b57cec5SDimitry Andric 31700b57cec5SDimitry Andrictemplate <class _Allocator> 3171bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 31720b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator 31730b57cec5SDimitry Andricvector<bool, _Allocator>::erase(const_iterator __position) 31740b57cec5SDimitry Andric{ 31750b57cec5SDimitry Andric iterator __r = __const_iterator_cast(__position); 3176bdd1243dSDimitry Andric std::copy(__position + 1, this->cend(), __r); 31770b57cec5SDimitry Andric --__size_; 31780b57cec5SDimitry Andric return __r; 31790b57cec5SDimitry Andric} 31800b57cec5SDimitry Andric 31810b57cec5SDimitry Andrictemplate <class _Allocator> 3182bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 31830b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator 31840b57cec5SDimitry Andricvector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last) 31850b57cec5SDimitry Andric{ 31860b57cec5SDimitry Andric iterator __r = __const_iterator_cast(__first); 31870b57cec5SDimitry Andric difference_type __d = __last - __first; 3188bdd1243dSDimitry Andric std::copy(__last, this->cend(), __r); 31890b57cec5SDimitry Andric __size_ -= __d; 31900b57cec5SDimitry Andric return __r; 31910b57cec5SDimitry Andric} 31920b57cec5SDimitry Andric 31930b57cec5SDimitry Andrictemplate <class _Allocator> 3194bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void 31950b57cec5SDimitry Andricvector<bool, _Allocator>::swap(vector& __x) 31960b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 31970b57cec5SDimitry Andric _NOEXCEPT 31980b57cec5SDimitry Andric#else 31990b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 32000b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value) 32010b57cec5SDimitry Andric#endif 32020b57cec5SDimitry Andric{ 3203bdd1243dSDimitry Andric std::swap(this->__begin_, __x.__begin_); 3204bdd1243dSDimitry Andric std::swap(this->__size_, __x.__size_); 3205bdd1243dSDimitry Andric std::swap(this->__cap(), __x.__cap()); 3206bdd1243dSDimitry Andric std::__swap_allocator(this->__alloc(), __x.__alloc(), 32070b57cec5SDimitry Andric integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>()); 32080b57cec5SDimitry Andric} 32090b57cec5SDimitry Andric 32100b57cec5SDimitry Andrictemplate <class _Allocator> 3211bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void 32120b57cec5SDimitry Andricvector<bool, _Allocator>::resize(size_type __sz, value_type __x) 32130b57cec5SDimitry Andric{ 32140b57cec5SDimitry Andric size_type __cs = size(); 32150b57cec5SDimitry Andric if (__cs < __sz) 32160b57cec5SDimitry Andric { 32170b57cec5SDimitry Andric iterator __r; 32180b57cec5SDimitry Andric size_type __c = capacity(); 32190b57cec5SDimitry Andric size_type __n = __sz - __cs; 32200b57cec5SDimitry Andric if (__n <= __c && __cs <= __c - __n) 32210b57cec5SDimitry Andric { 32220b57cec5SDimitry Andric __r = end(); 32230b57cec5SDimitry Andric __size_ += __n; 32240b57cec5SDimitry Andric } 32250b57cec5SDimitry Andric else 32260b57cec5SDimitry Andric { 3227349cc55cSDimitry Andric vector __v(get_allocator()); 32280b57cec5SDimitry Andric __v.reserve(__recommend(__size_ + __n)); 32290b57cec5SDimitry Andric __v.__size_ = __size_ + __n; 3230bdd1243dSDimitry Andric __r = std::copy(cbegin(), cend(), __v.begin()); 32310b57cec5SDimitry Andric swap(__v); 32320b57cec5SDimitry Andric } 3233bdd1243dSDimitry Andric std::fill_n(__r, __n, __x); 32340b57cec5SDimitry Andric } 32350b57cec5SDimitry Andric else 32360b57cec5SDimitry Andric __size_ = __sz; 32370b57cec5SDimitry Andric} 32380b57cec5SDimitry Andric 32390b57cec5SDimitry Andrictemplate <class _Allocator> 3240bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void 32410b57cec5SDimitry Andricvector<bool, _Allocator>::flip() _NOEXCEPT 32420b57cec5SDimitry Andric{ 32430b57cec5SDimitry Andric // do middle whole words 32440b57cec5SDimitry Andric size_type __n = __size_; 32450b57cec5SDimitry Andric __storage_pointer __p = __begin_; 32460b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 32470b57cec5SDimitry Andric *__p = ~*__p; 32480b57cec5SDimitry Andric // do last partial word 32490b57cec5SDimitry Andric if (__n > 0) 32500b57cec5SDimitry Andric { 32510b57cec5SDimitry Andric __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 32520b57cec5SDimitry Andric __storage_type __b = *__p & __m; 32530b57cec5SDimitry Andric *__p &= ~__m; 32540b57cec5SDimitry Andric *__p |= ~__b & __m; 32550b57cec5SDimitry Andric } 32560b57cec5SDimitry Andric} 32570b57cec5SDimitry Andric 32580b57cec5SDimitry Andrictemplate <class _Allocator> 3259bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 bool 32600b57cec5SDimitry Andricvector<bool, _Allocator>::__invariants() const 32610b57cec5SDimitry Andric{ 32620b57cec5SDimitry Andric if (this->__begin_ == nullptr) 32630b57cec5SDimitry Andric { 32640b57cec5SDimitry Andric if (this->__size_ != 0 || this->__cap() != 0) 32650b57cec5SDimitry Andric return false; 32660b57cec5SDimitry Andric } 32670b57cec5SDimitry Andric else 32680b57cec5SDimitry Andric { 32690b57cec5SDimitry Andric if (this->__cap() == 0) 32700b57cec5SDimitry Andric return false; 32710b57cec5SDimitry Andric if (this->__size_ > this->capacity()) 32720b57cec5SDimitry Andric return false; 32730b57cec5SDimitry Andric } 32740b57cec5SDimitry Andric return true; 32750b57cec5SDimitry Andric} 32760b57cec5SDimitry Andric 32770b57cec5SDimitry Andrictemplate <class _Allocator> 3278bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 size_t 32790b57cec5SDimitry Andricvector<bool, _Allocator>::__hash_code() const _NOEXCEPT 32800b57cec5SDimitry Andric{ 32810b57cec5SDimitry Andric size_t __h = 0; 32820b57cec5SDimitry Andric // do middle whole words 32830b57cec5SDimitry Andric size_type __n = __size_; 32840b57cec5SDimitry Andric __storage_pointer __p = __begin_; 32850b57cec5SDimitry Andric for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) 32860b57cec5SDimitry Andric __h ^= *__p; 32870b57cec5SDimitry Andric // do last partial word 32880b57cec5SDimitry Andric if (__n > 0) 32890b57cec5SDimitry Andric { 32900b57cec5SDimitry Andric const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); 32910b57cec5SDimitry Andric __h ^= *__p & __m; 32920b57cec5SDimitry Andric } 32930b57cec5SDimitry Andric return __h; 32940b57cec5SDimitry Andric} 32950b57cec5SDimitry Andric 32960b57cec5SDimitry Andrictemplate <class _Allocator> 32970b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> > 329881ad6265SDimitry Andric : public __unary_function<vector<bool, _Allocator>, size_t> 32990b57cec5SDimitry Andric{ 3300bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 33010b57cec5SDimitry Andric size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT 33020b57cec5SDimitry Andric {return __vec.__hash_code();} 33030b57cec5SDimitry Andric}; 33040b57cec5SDimitry Andric 33050b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 3306bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 3307bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 33080b57cec5SDimitry Andricbool 33090b57cec5SDimitry Andricoperator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 33100b57cec5SDimitry Andric{ 33110b57cec5SDimitry Andric const typename vector<_Tp, _Allocator>::size_type __sz = __x.size(); 3312bdd1243dSDimitry Andric return __sz == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin()); 33130b57cec5SDimitry Andric} 33140b57cec5SDimitry Andric 331506c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17 331606c3fb27SDimitry Andric 33170b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 3318bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 33190b57cec5SDimitry Andricbool 33200b57cec5SDimitry Andricoperator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 33210b57cec5SDimitry Andric{ 33220b57cec5SDimitry Andric return !(__x == __y); 33230b57cec5SDimitry Andric} 33240b57cec5SDimitry Andric 33250b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 3326bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 33270b57cec5SDimitry Andricbool 33280b57cec5SDimitry Andricoperator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 33290b57cec5SDimitry Andric{ 3330bdd1243dSDimitry Andric return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); 33310b57cec5SDimitry Andric} 33320b57cec5SDimitry Andric 33330b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 3334bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 33350b57cec5SDimitry Andricbool 33360b57cec5SDimitry Andricoperator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 33370b57cec5SDimitry Andric{ 33380b57cec5SDimitry Andric return __y < __x; 33390b57cec5SDimitry Andric} 33400b57cec5SDimitry Andric 33410b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 3342bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 33430b57cec5SDimitry Andricbool 33440b57cec5SDimitry Andricoperator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 33450b57cec5SDimitry Andric{ 33460b57cec5SDimitry Andric return !(__x < __y); 33470b57cec5SDimitry Andric} 33480b57cec5SDimitry Andric 33490b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 3350bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 33510b57cec5SDimitry Andricbool 33520b57cec5SDimitry Andricoperator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) 33530b57cec5SDimitry Andric{ 33540b57cec5SDimitry Andric return !(__y < __x); 33550b57cec5SDimitry Andric} 33560b57cec5SDimitry Andric 335706c3fb27SDimitry Andric#else // _LIBCPP_STD_VER <= 17 335806c3fb27SDimitry Andric 335906c3fb27SDimitry Andrictemplate <class _Tp, class _Allocator> 336006c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr __synth_three_way_result<_Tp> 336106c3fb27SDimitry Andricoperator<=>(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { 336206c3fb27SDimitry Andric return std::lexicographical_compare_three_way( 336306c3fb27SDimitry Andric __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way<_Tp, _Tp>); 336406c3fb27SDimitry Andric} 336506c3fb27SDimitry Andric 336606c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER <= 17 336706c3fb27SDimitry Andric 33680b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator> 3369bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 3370bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 33710b57cec5SDimitry Andricvoid 33720b57cec5SDimitry Andricswap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) 33730b57cec5SDimitry Andric _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 33740b57cec5SDimitry Andric{ 33750b57cec5SDimitry Andric __x.swap(__y); 33760b57cec5SDimitry Andric} 33770b57cec5SDimitry Andric 337806c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 33790b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Up> 3380bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 3381bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type 33825ffd83dbSDimitry Andricerase(vector<_Tp, _Allocator>& __c, const _Up& __v) { 33835ffd83dbSDimitry Andric auto __old_size = __c.size(); 3384bdd1243dSDimitry Andric __c.erase(std::remove(__c.begin(), __c.end(), __v), __c.end()); 33855ffd83dbSDimitry Andric return __old_size - __c.size(); 33865ffd83dbSDimitry Andric} 33870b57cec5SDimitry Andric 33880b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Predicate> 3389bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 3390bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type 33915ffd83dbSDimitry Andricerase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) { 33925ffd83dbSDimitry Andric auto __old_size = __c.size(); 3393bdd1243dSDimitry Andric __c.erase(std::remove_if(__c.begin(), __c.end(), __pred), __c.end()); 33945ffd83dbSDimitry Andric return __old_size - __c.size(); 33955ffd83dbSDimitry Andric} 339681ad6265SDimitry Andric 339781ad6265SDimitry Andrictemplate <> 3398bdd1243dSDimitry Andricinline constexpr bool __format::__enable_insertable<vector<char>> = true; 339981ad6265SDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 340081ad6265SDimitry Andrictemplate <> 3401bdd1243dSDimitry Andricinline constexpr bool __format::__enable_insertable<vector<wchar_t>> = true; 34020b57cec5SDimitry Andric#endif 34030b57cec5SDimitry Andric 340406c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 340581ad6265SDimitry Andric 340606c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 340706c3fb27SDimitry Andrictemplate <class _Tp, class _CharT> 3408bdd1243dSDimitry Andric// Since is-vector-bool-reference is only used once it's inlined here. 3409bdd1243dSDimitry Andric requires same_as<typename _Tp::__container, vector<bool, typename _Tp::__container::allocator_type>> 341006c3fb27SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS formatter<_Tp, _CharT> { 3411bdd1243dSDimitry Andricprivate: 341206c3fb27SDimitry Andric formatter<bool, _CharT> __underlying_; 3413bdd1243dSDimitry Andric 3414bdd1243dSDimitry Andricpublic: 3415bdd1243dSDimitry Andric template <class _ParseContext> 3416bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) { 3417bdd1243dSDimitry Andric return __underlying_.parse(__ctx); 3418bdd1243dSDimitry Andric } 3419bdd1243dSDimitry Andric 3420bdd1243dSDimitry Andric template <class _FormatContext> 3421bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(const _Tp& __ref, _FormatContext& __ctx) const { 3422bdd1243dSDimitry Andric return __underlying_.format(__ref, __ctx); 3423bdd1243dSDimitry Andric } 3424bdd1243dSDimitry Andric}; 342506c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 23 3426bdd1243dSDimitry Andric 34270b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 34280b57cec5SDimitry Andric 342906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 3430bdd1243dSDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 3431bdd1243dSDimitry Andricnamespace pmr { 3432bdd1243dSDimitry Andrictemplate <class _ValueT> 343306c3fb27SDimitry Andricusing vector _LIBCPP_AVAILABILITY_PMR = std::vector<_ValueT, polymorphic_allocator<_ValueT>>; 3434bdd1243dSDimitry Andric} // namespace pmr 3435bdd1243dSDimitry Andric_LIBCPP_END_NAMESPACE_STD 3436bdd1243dSDimitry Andric#endif 3437bdd1243dSDimitry Andric 34380b57cec5SDimitry Andric_LIBCPP_POP_MACROS 34390b57cec5SDimitry Andric 3440bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 3441bdd1243dSDimitry Andric# include <algorithm> 3442bdd1243dSDimitry Andric# include <atomic> 3443bdd1243dSDimitry Andric# include <concepts> 344406c3fb27SDimitry Andric# include <cstdlib> 344506c3fb27SDimitry Andric# include <type_traits> 3446bdd1243dSDimitry Andric# include <typeinfo> 3447bdd1243dSDimitry Andric# include <utility> 3448bdd1243dSDimitry Andric#endif 3449bdd1243dSDimitry Andric 34500b57cec5SDimitry Andric#endif // _LIBCPP_VECTOR 3451