xref: /freebsd/contrib/llvm-project/libcxx/include/vector (revision cb14a3fe5122c879eae1fb480ed7ce82a699ddb6)
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
135f757f3fSDimitry Andric// clang-format off
145f757f3fSDimitry 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
3065f757f3fSDimitry Andric// clang-format on
3075f757f3fSDimitry 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> */>
387*cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector {
3880b57cec5SDimitry Andricprivate:
3890b57cec5SDimitry Andric  typedef allocator<_Tp> __default_allocator_type;
390*cb14a3feSDimitry Andric
3910b57cec5SDimitry Andricpublic:
3920b57cec5SDimitry Andric  typedef vector __self;
3930b57cec5SDimitry Andric  typedef _Tp value_type;
3940b57cec5SDimitry Andric  typedef _Allocator allocator_type;
395349cc55cSDimitry Andric  typedef allocator_traits<allocator_type> __alloc_traits;
396349cc55cSDimitry Andric  typedef value_type& reference;
397349cc55cSDimitry Andric  typedef const value_type& const_reference;
3984824e7fdSDimitry Andric  typedef typename __alloc_traits::size_type size_type;
399349cc55cSDimitry Andric  typedef typename __alloc_traits::difference_type difference_type;
400349cc55cSDimitry Andric  typedef typename __alloc_traits::pointer pointer;
401349cc55cSDimitry Andric  typedef typename __alloc_traits::const_pointer const_pointer;
402bdd1243dSDimitry Andric  // TODO: Implement iterator bounds checking without requiring the global database.
4030b57cec5SDimitry Andric  typedef __wrap_iter<pointer> iterator;
4040b57cec5SDimitry Andric  typedef __wrap_iter<const_pointer> const_iterator;
405bdd1243dSDimitry Andric  typedef std::reverse_iterator<iterator> reverse_iterator;
406bdd1243dSDimitry Andric  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
4070b57cec5SDimitry Andric
4080b57cec5SDimitry Andric  static_assert((is_same<typename allocator_type::value_type, value_type>::value),
4090b57cec5SDimitry Andric                "Allocator::value_type must be same type as value_type");
4100b57cec5SDimitry Andric
411bdd1243dSDimitry Andric  static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value,
412bdd1243dSDimitry Andric                "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
413bdd1243dSDimitry Andric                "original allocator");
414bdd1243dSDimitry Andric
415*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector()
416*cb14a3feSDimitry Andric      _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) {}
417bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(const allocator_type& __a)
4180b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
4190b57cec5SDimitry Andric      _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
4200b57cec5SDimitry Andric#else
4210b57cec5SDimitry Andric      _NOEXCEPT
4220b57cec5SDimitry Andric#endif
423*cb14a3feSDimitry Andric      : __end_cap_(nullptr, __a) {
4240b57cec5SDimitry Andric  }
425bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n);
42606c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
427bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n, const allocator_type& __a);
4280b57cec5SDimitry Andric#endif
429bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(size_type __n, const value_type& __x);
4304824e7fdSDimitry Andric
4314824e7fdSDimitry Andric  template <class = __enable_if_t<__is_allocator<_Allocator>::value> >
432bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
4334824e7fdSDimitry Andric  vector(size_type __n, const value_type& __x, const allocator_type& __a)
434*cb14a3feSDimitry Andric      : __end_cap_(nullptr, __a) {
435*cb14a3feSDimitry Andric    if (__n > 0) {
4364824e7fdSDimitry Andric      __vallocate(__n);
4374824e7fdSDimitry Andric      __construct_at_end(__n, __x);
4384824e7fdSDimitry Andric    }
4394824e7fdSDimitry Andric  }
4404824e7fdSDimitry Andric
441bdd1243dSDimitry Andric  template <class _InputIterator,
44206c3fb27SDimitry Andric            __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
443bdd1243dSDimitry Andric                              is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,
444bdd1243dSDimitry Andric                          int> = 0>
445bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(_InputIterator __first, _InputIterator __last);
446bdd1243dSDimitry Andric  template <class _InputIterator,
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
451bdd1243dSDimitry Andric  vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
452bdd1243dSDimitry Andric
453bdd1243dSDimitry Andric  template <
454bdd1243dSDimitry Andric      class _ForwardIterator,
45506c3fb27SDimitry Andric      __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
456bdd1243dSDimitry Andric                        is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
457bdd1243dSDimitry Andric                    int> = 0>
458bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(_ForwardIterator __first, _ForwardIterator __last);
459bdd1243dSDimitry Andric
460*cb14a3feSDimitry Andric  template <
461*cb14a3feSDimitry Andric      class _ForwardIterator,
46206c3fb27SDimitry Andric      __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
463bdd1243dSDimitry Andric                        is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
464bdd1243dSDimitry Andric                    int> = 0>
465bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
466bdd1243dSDimitry Andric  vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a);
4670b57cec5SDimitry Andric
46806c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
46906c3fb27SDimitry Andric  template <_ContainerCompatibleRange<_Tp> _Range>
470*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr vector(
471*cb14a3feSDimitry Andric      from_range_t, _Range&& __range, const allocator_type& __alloc = allocator_type())
472*cb14a3feSDimitry Andric      : __end_cap_(nullptr, __alloc) {
47306c3fb27SDimitry Andric    if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
47406c3fb27SDimitry Andric      auto __n = static_cast<size_type>(ranges::distance(__range));
47506c3fb27SDimitry Andric      __init_with_size(ranges::begin(__range), ranges::end(__range), __n);
47606c3fb27SDimitry Andric
47706c3fb27SDimitry Andric    } else {
47806c3fb27SDimitry Andric      __init_with_sentinel(ranges::begin(__range), ranges::end(__range));
47906c3fb27SDimitry Andric    }
48006c3fb27SDimitry Andric  }
48106c3fb27SDimitry Andric#endif
48206c3fb27SDimitry Andric
48350d7464cSDimitry Andricprivate:
48450d7464cSDimitry Andric  class __destroy_vector {
48550d7464cSDimitry Andric  public:
48606c3fb27SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI __destroy_vector(vector& __vec) : __vec_(__vec) {}
487349cc55cSDimitry Andric
488bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() {
48950d7464cSDimitry Andric      if (__vec_.__begin_ != nullptr) {
49050d7464cSDimitry Andric        __vec_.__clear();
49106c3fb27SDimitry Andric        __vec_.__annotate_delete();
49250d7464cSDimitry Andric        __alloc_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.capacity());
493349cc55cSDimitry Andric      }
4940b57cec5SDimitry Andric    }
4950b57cec5SDimitry Andric
49650d7464cSDimitry Andric  private:
49750d7464cSDimitry Andric    vector& __vec_;
49850d7464cSDimitry Andric  };
49950d7464cSDimitry Andric
50050d7464cSDimitry Andricpublic:
501bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~vector() { __destroy_vector (*this)(); }
50250d7464cSDimitry Andric
503bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(const vector& __x);
504bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
505*cb14a3feSDimitry Andric  vector(const vector& __x, const __type_identity_t<allocator_type>& __a);
506*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector& operator=(const vector& __x);
5070b57cec5SDimitry Andric
5080b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
509*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(initializer_list<value_type> __il);
5100b57cec5SDimitry Andric
511bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
5120b57cec5SDimitry Andric  vector(initializer_list<value_type> __il, const allocator_type& __a);
5130b57cec5SDimitry Andric
514*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector& operator=(initializer_list<value_type> __il) {
515*cb14a3feSDimitry Andric    assign(__il.begin(), __il.end());
516*cb14a3feSDimitry Andric    return *this;
517*cb14a3feSDimitry Andric  }
51881ad6265SDimitry Andric#endif // !_LIBCPP_CXX03_LANG
51981ad6265SDimitry Andric
520*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(vector&& __x)
52106c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
52281ad6265SDimitry Andric      noexcept;
5230b57cec5SDimitry Andric#else
5240b57cec5SDimitry Andric      _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
5250b57cec5SDimitry Andric#endif
5260b57cec5SDimitry Andric
527bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
52881ad6265SDimitry Andric  vector(vector&& __x, const __type_identity_t<allocator_type>& __a);
529*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector& operator=(vector&& __x)
5300b57cec5SDimitry Andric      _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
5310b57cec5SDimitry Andric
532bdd1243dSDimitry Andric  template <class _InputIterator,
53306c3fb27SDimitry Andric            __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
534bdd1243dSDimitry Andric                              is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,
535bdd1243dSDimitry Andric                          int> = 0>
536bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(_InputIterator __first, _InputIterator __last);
537bdd1243dSDimitry Andric  template <
538bdd1243dSDimitry Andric      class _ForwardIterator,
53906c3fb27SDimitry Andric      __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
540bdd1243dSDimitry Andric                        is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
541bdd1243dSDimitry Andric                    int> = 0>
542bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(_ForwardIterator __first, _ForwardIterator __last);
5430b57cec5SDimitry Andric
54406c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
54506c3fb27SDimitry Andric  template <_ContainerCompatibleRange<_Tp> _Range>
546*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr void assign_range(_Range&& __range) {
54706c3fb27SDimitry Andric    if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
54806c3fb27SDimitry Andric      auto __n = static_cast<size_type>(ranges::distance(__range));
54906c3fb27SDimitry Andric      __assign_with_size(ranges::begin(__range), ranges::end(__range), __n);
55006c3fb27SDimitry Andric
55106c3fb27SDimitry Andric    } else {
55206c3fb27SDimitry Andric      __assign_with_sentinel(ranges::begin(__range), ranges::end(__range));
55306c3fb27SDimitry Andric    }
55406c3fb27SDimitry Andric  }
55506c3fb27SDimitry Andric#endif
55606c3fb27SDimitry Andric
557bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const_reference __u);
5580b57cec5SDimitry Andric
5590b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
560*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(initializer_list<value_type> __il) {
561*cb14a3feSDimitry Andric    assign(__il.begin(), __il.end());
562*cb14a3feSDimitry Andric  }
5630b57cec5SDimitry Andric#endif
5640b57cec5SDimitry Andric
565*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT {
566*cb14a3feSDimitry Andric    return this->__alloc();
567*cb14a3feSDimitry Andric  }
5680b57cec5SDimitry Andric
569bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT;
570bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT;
571bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT;
572bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT;
5730b57cec5SDimitry Andric
574*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT {
575*cb14a3feSDimitry Andric    return reverse_iterator(end());
576*cb14a3feSDimitry Andric  }
577*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT {
578*cb14a3feSDimitry Andric    return const_reverse_iterator(end());
579*cb14a3feSDimitry Andric  }
580*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() _NOEXCEPT {
581*cb14a3feSDimitry Andric    return reverse_iterator(begin());
582*cb14a3feSDimitry Andric  }
583*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT {
584*cb14a3feSDimitry Andric    return const_reverse_iterator(begin());
585*cb14a3feSDimitry Andric  }
5860b57cec5SDimitry Andric
587*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return begin(); }
588*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return end(); }
589*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT {
590*cb14a3feSDimitry Andric    return rbegin();
591*cb14a3feSDimitry Andric  }
592*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
5930b57cec5SDimitry Andric
594*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT {
595*cb14a3feSDimitry Andric    return static_cast<size_type>(this->__end_ - this->__begin_);
596*cb14a3feSDimitry Andric  }
597*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type capacity() const _NOEXCEPT {
598*cb14a3feSDimitry Andric    return static_cast<size_type>(__end_cap() - this->__begin_);
599*cb14a3feSDimitry Andric  }
600*cb14a3feSDimitry Andric  _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT {
601*cb14a3feSDimitry Andric    return this->__begin_ == this->__end_;
602*cb14a3feSDimitry Andric  }
603bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT;
604bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void reserve(size_type __n);
605bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void shrink_to_fit() _NOEXCEPT;
6060b57cec5SDimitry Andric
607bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference operator[](size_type __n) _NOEXCEPT;
608bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference operator[](size_type __n) const _NOEXCEPT;
609bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference at(size_type __n);
610bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __n) const;
6110b57cec5SDimitry Andric
612*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference front() _NOEXCEPT {
61306c3fb27SDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "front() called on an empty vector");
6140b57cec5SDimitry Andric    return *this->__begin_;
6150b57cec5SDimitry Andric  }
616*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference front() const _NOEXCEPT {
61706c3fb27SDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "front() called on an empty vector");
6180b57cec5SDimitry Andric    return *this->__begin_;
6190b57cec5SDimitry Andric  }
620*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference back() _NOEXCEPT {
62106c3fb27SDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "back() called on an empty vector");
6220b57cec5SDimitry Andric    return *(this->__end_ - 1);
6230b57cec5SDimitry Andric  }
624*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference back() const _NOEXCEPT {
62506c3fb27SDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "back() called on an empty vector");
6260b57cec5SDimitry Andric    return *(this->__end_ - 1);
6270b57cec5SDimitry Andric  }
6280b57cec5SDimitry Andric
629*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI value_type* data() _NOEXCEPT {
630*cb14a3feSDimitry Andric    return std::__to_address(this->__begin_);
631*cb14a3feSDimitry Andric  }
63261cfbce3SDimitry Andric
633*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const value_type* data() const _NOEXCEPT {
634*cb14a3feSDimitry Andric    return std::__to_address(this->__begin_);
635*cb14a3feSDimitry Andric  }
6360b57cec5SDimitry Andric
637bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_back(const_reference __x);
6380b57cec5SDimitry Andric
639bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __x);
6400b57cec5SDimitry Andric
6410b57cec5SDimitry Andric  template <class... _Args>
642bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
64306c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
644*cb14a3feSDimitry Andric      reference
645*cb14a3feSDimitry Andric      emplace_back(_Args&&... __args);
6460b57cec5SDimitry Andric#else
647*cb14a3feSDimitry Andric      void
648*cb14a3feSDimitry Andric      emplace_back(_Args&&... __args);
6490b57cec5SDimitry Andric#endif
6500b57cec5SDimitry Andric
65106c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
65206c3fb27SDimitry Andric  template <_ContainerCompatibleRange<_Tp> _Range>
653*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr void append_range(_Range&& __range) {
65406c3fb27SDimitry Andric    insert_range(end(), std::forward<_Range>(__range));
65506c3fb27SDimitry Andric  }
65606c3fb27SDimitry Andric#endif
65706c3fb27SDimitry Andric
658*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void pop_back();
6590b57cec5SDimitry Andric
660bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, const_reference __x);
6610b57cec5SDimitry Andric
662bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, value_type&& __x);
6630b57cec5SDimitry Andric  template <class... _Args>
664bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __position, _Args&&... __args);
6650b57cec5SDimitry Andric
666*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
667*cb14a3feSDimitry Andric  insert(const_iterator __position, size_type __n, const_reference __x);
668bdd1243dSDimitry Andric
669bdd1243dSDimitry Andric  template <class _InputIterator,
67006c3fb27SDimitry Andric            __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
671bdd1243dSDimitry Andric                              is_constructible< value_type, typename iterator_traits<_InputIterator>::reference>::value,
672bdd1243dSDimitry Andric                          int> = 0>
673bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
6740b57cec5SDimitry Andric  insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
675bdd1243dSDimitry Andric
67606c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
67706c3fb27SDimitry Andric  template <_ContainerCompatibleRange<_Tp> _Range>
678*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr iterator insert_range(const_iterator __position, _Range&& __range) {
67906c3fb27SDimitry Andric    if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
68006c3fb27SDimitry Andric      auto __n = static_cast<size_type>(ranges::distance(__range));
68106c3fb27SDimitry Andric      return __insert_with_size(__position, ranges::begin(__range), ranges::end(__range), __n);
68206c3fb27SDimitry Andric
68306c3fb27SDimitry Andric    } else {
68406c3fb27SDimitry Andric      return __insert_with_sentinel(__position, ranges::begin(__range), ranges::end(__range));
68506c3fb27SDimitry Andric    }
68606c3fb27SDimitry Andric  }
68706c3fb27SDimitry Andric#endif
68806c3fb27SDimitry Andric
689bdd1243dSDimitry Andric  template <
690bdd1243dSDimitry Andric      class _ForwardIterator,
69106c3fb27SDimitry Andric      __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
692bdd1243dSDimitry Andric                        is_constructible< value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
693bdd1243dSDimitry Andric                    int> = 0>
694bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
6950b57cec5SDimitry Andric  insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
6960b57cec5SDimitry Andric
6970b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
698*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
699*cb14a3feSDimitry Andric  insert(const_iterator __position, initializer_list<value_type> __il) {
700*cb14a3feSDimitry Andric    return insert(__position, __il.begin(), __il.end());
701*cb14a3feSDimitry Andric  }
7020b57cec5SDimitry Andric#endif
7030b57cec5SDimitry Andric
704bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __position);
705bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last);
7060b57cec5SDimitry Andric
707*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT {
7080b57cec5SDimitry Andric    size_type __old_size = size();
709349cc55cSDimitry Andric    __clear();
7100b57cec5SDimitry Andric    __annotate_shrink(__old_size);
7110b57cec5SDimitry Andric  }
7120b57cec5SDimitry Andric
713bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz);
714bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz, const_reference __x);
7150b57cec5SDimitry Andric
716bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void swap(vector&)
7170b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
7180b57cec5SDimitry Andric      _NOEXCEPT;
7190b57cec5SDimitry Andric#else
720*cb14a3feSDimitry Andric      _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value);
7210b57cec5SDimitry Andric#endif
7220b57cec5SDimitry Andric
723bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool __invariants() const;
7240b57cec5SDimitry Andric
7250b57cec5SDimitry Andricprivate:
726d56accc7SDimitry Andric  pointer __begin_ = nullptr;
727d56accc7SDimitry Andric  pointer __end_   = nullptr;
728d56accc7SDimitry Andric  __compressed_pair<pointer, allocator_type> __end_cap_ =
729d56accc7SDimitry Andric      __compressed_pair<pointer, allocator_type>(nullptr, __default_init_tag());
730d56accc7SDimitry Andric
73181ad6265SDimitry Andric  //  Allocate space for __n objects
73281ad6265SDimitry Andric  //  throws length_error if __n > max_size()
73381ad6265SDimitry Andric  //  throws (probably bad_alloc) if memory run out
73481ad6265SDimitry Andric  //  Precondition:  __begin_ == __end_ == __end_cap() == 0
73581ad6265SDimitry Andric  //  Precondition:  __n > 0
73681ad6265SDimitry Andric  //  Postcondition:  capacity() >= __n
73781ad6265SDimitry Andric  //  Postcondition:  size() == 0
738bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) {
73981ad6265SDimitry Andric    if (__n > max_size())
74081ad6265SDimitry Andric      __throw_length_error();
74181ad6265SDimitry Andric    auto __allocation = std::__allocate_at_least(__alloc(), __n);
74281ad6265SDimitry Andric    __begin_          = __allocation.ptr;
74381ad6265SDimitry Andric    __end_            = __allocation.ptr;
74481ad6265SDimitry Andric    __end_cap()       = __begin_ + __allocation.count;
74581ad6265SDimitry Andric    __annotate_new(0);
74681ad6265SDimitry Andric  }
74781ad6265SDimitry Andric
748bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __vdeallocate() _NOEXCEPT;
749bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type __recommend(size_type __new_size) const;
750bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_at_end(size_type __n);
751*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_at_end(size_type __n, const_reference __x);
752bdd1243dSDimitry Andric
75306c3fb27SDimitry Andric  template <class _InputIterator, class _Sentinel>
754*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
755*cb14a3feSDimitry Andric  __init_with_size(_InputIterator __first, _Sentinel __last, size_type __n) {
75606c3fb27SDimitry Andric    auto __guard = std::__make_exception_guard(__destroy_vector(*this));
75706c3fb27SDimitry Andric
75806c3fb27SDimitry Andric    if (__n > 0) {
75906c3fb27SDimitry Andric      __vallocate(__n);
76006c3fb27SDimitry Andric      __construct_at_end(__first, __last, __n);
76106c3fb27SDimitry Andric    }
76206c3fb27SDimitry Andric
76306c3fb27SDimitry Andric    __guard.__complete();
76406c3fb27SDimitry Andric  }
76506c3fb27SDimitry Andric
76606c3fb27SDimitry Andric  template <class _InputIterator, class _Sentinel>
767*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
768*cb14a3feSDimitry Andric  __init_with_sentinel(_InputIterator __first, _Sentinel __last) {
76906c3fb27SDimitry Andric    auto __guard = std::__make_exception_guard(__destroy_vector(*this));
77006c3fb27SDimitry Andric
77106c3fb27SDimitry Andric    for (; __first != __last; ++__first)
77206c3fb27SDimitry Andric      emplace_back(*__first);
77306c3fb27SDimitry Andric
77406c3fb27SDimitry Andric    __guard.__complete();
77506c3fb27SDimitry Andric  }
77606c3fb27SDimitry Andric
77706c3fb27SDimitry Andric  template <class _Iterator, class _Sentinel>
778*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __assign_with_sentinel(_Iterator __first, _Sentinel __last);
77906c3fb27SDimitry Andric
78006c3fb27SDimitry Andric  template <class _ForwardIterator, class _Sentinel>
781*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
782*cb14a3feSDimitry Andric  __assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __n);
78306c3fb27SDimitry Andric
78406c3fb27SDimitry Andric  template <class _InputIterator, class _Sentinel>
785*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
786*cb14a3feSDimitry Andric  __insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last);
78706c3fb27SDimitry Andric
78806c3fb27SDimitry Andric  template <class _Iterator, class _Sentinel>
789*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
790*cb14a3feSDimitry Andric  __insert_with_size(const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n);
79106c3fb27SDimitry Andric
79206c3fb27SDimitry Andric  template <class _InputIterator, class _Sentinel>
793*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
794*cb14a3feSDimitry Andric  __construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n);
795bdd1243dSDimitry Andric
796bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __append(size_type __n);
797bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __append(size_type __n, const_reference __x);
798*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator __make_iter(pointer __p) _NOEXCEPT {
799*cb14a3feSDimitry Andric    return iterator(__p);
800*cb14a3feSDimitry Andric  }
801*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator __make_iter(const_pointer __p) const _NOEXCEPT {
802*cb14a3feSDimitry Andric    return const_iterator(__p);
803*cb14a3feSDimitry Andric  }
804*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
805*cb14a3feSDimitry Andric  __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
806*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer
807*cb14a3feSDimitry Andric  __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
808*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
809*cb14a3feSDimitry Andric  __move_range(pointer __from_s, pointer __from_e, pointer __to);
810bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, true_type)
8110b57cec5SDimitry Andric      _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
812bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, false_type)
8130b57cec5SDimitry Andric      _NOEXCEPT_(__alloc_traits::is_always_equal::value);
814*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __destruct_at_end(pointer __new_last) _NOEXCEPT {
8150b57cec5SDimitry Andric    size_type __old_size = size();
816349cc55cSDimitry Andric    __base_destruct_at_end(__new_last);
8170b57cec5SDimitry Andric    __annotate_shrink(__old_size);
8180b57cec5SDimitry Andric  }
8190b57cec5SDimitry Andric
8200b57cec5SDimitry Andric  template <class _Up>
821*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI inline pointer __push_back_slow_path(_Up&& __x);
8220b57cec5SDimitry Andric
8230b57cec5SDimitry Andric  template <class... _Args>
824*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI inline pointer __emplace_back_slow_path(_Args&&... __args);
8250b57cec5SDimitry Andric
8260b57cec5SDimitry Andric  // The following functions are no-ops outside of AddressSanitizer mode.
82706c3fb27SDimitry Andric  // We call annotations for every allocator, unless explicitly disabled.
82806c3fb27SDimitry Andric  //
82906c3fb27SDimitry Andric  // To disable annotations for a particular allocator, change value of
83006c3fb27SDimitry Andric  // __asan_annotate_container_with_allocator to false.
83106c3fb27SDimitry Andric  // For more details, see the "Using libc++" documentation page or
83206c3fb27SDimitry Andric  // the documentation for __sanitizer_annotate_contiguous_container.
8335f757f3fSDimitry Andric
834*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_contiguous_container(
835*cb14a3feSDimitry Andric      const void* __beg, const void* __end, const void* __old_mid, const void* __new_mid) const {
8365f757f3fSDimitry Andric    (void)__beg;
8375f757f3fSDimitry Andric    (void)__end;
8385f757f3fSDimitry Andric    (void)__old_mid;
8395f757f3fSDimitry Andric    (void)__new_mid;
8405f757f3fSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
841*cb14a3feSDimitry Andric    if (!__libcpp_is_constant_evaluated() && __beg != nullptr &&
842*cb14a3feSDimitry Andric        __asan_annotate_container_with_allocator<_Allocator>::value)
8430b57cec5SDimitry Andric      __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
8440b57cec5SDimitry Andric#endif
8455f757f3fSDimitry Andric  }
8465f757f3fSDimitry Andric
847*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_new(size_type __current_size) const _NOEXCEPT {
848*cb14a3feSDimitry Andric    (void)__current_size;
849*cb14a3feSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
850*cb14a3feSDimitry Andric    __annotate_contiguous_container(data(), data() + capacity(), data() + capacity(), data() + __current_size);
851*cb14a3feSDimitry Andric#endif
8520b57cec5SDimitry Andric  }
8530b57cec5SDimitry Andric
854*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_delete() const _NOEXCEPT {
855*cb14a3feSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
856*cb14a3feSDimitry Andric    __annotate_contiguous_container(data(), data() + capacity(), data() + size(), data() + capacity());
857*cb14a3feSDimitry Andric#endif
8580b57cec5SDimitry Andric  }
8590b57cec5SDimitry Andric
860*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_increase(size_type __n) const _NOEXCEPT {
861*cb14a3feSDimitry Andric    (void)__n;
862*cb14a3feSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
863*cb14a3feSDimitry Andric    __annotate_contiguous_container(data(), data() + capacity(), data() + size(), data() + size() + __n);
864*cb14a3feSDimitry Andric#endif
8650b57cec5SDimitry Andric  }
8660b57cec5SDimitry Andric
867*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __annotate_shrink(size_type __old_size) const _NOEXCEPT {
868*cb14a3feSDimitry Andric    (void)__old_size;
869*cb14a3feSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
870*cb14a3feSDimitry Andric    __annotate_contiguous_container(data(), data() + capacity(), data() + __old_size, data() + size());
871*cb14a3feSDimitry Andric#endif
8720b57cec5SDimitry Andric  }
8730b57cec5SDimitry Andric
874e40139ffSDimitry Andric  struct _ConstructTransaction {
875*cb14a3feSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit _ConstructTransaction(vector& __v, size_type __n)
876e40139ffSDimitry Andric        : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) {
877e40139ffSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
878e40139ffSDimitry Andric      __v_.__annotate_increase(__n);
879e40139ffSDimitry Andric#endif
880e40139ffSDimitry Andric    }
881bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~_ConstructTransaction() {
882e40139ffSDimitry Andric      __v_.__end_ = __pos_;
883e40139ffSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
884e40139ffSDimitry Andric      if (__pos_ != __new_end_) {
885e40139ffSDimitry Andric        __v_.__annotate_shrink(__new_end_ - __v_.__begin_);
886e40139ffSDimitry Andric      }
887e40139ffSDimitry Andric#endif
888e40139ffSDimitry Andric    }
889e40139ffSDimitry Andric
890e40139ffSDimitry Andric    vector& __v_;
891e40139ffSDimitry Andric    pointer __pos_;
892e40139ffSDimitry Andric    const_pointer const __new_end_;
893e40139ffSDimitry Andric
894e40139ffSDimitry Andric  private:
895e40139ffSDimitry Andric    _ConstructTransaction(_ConstructTransaction const&)            = delete;
896e40139ffSDimitry Andric    _ConstructTransaction& operator=(_ConstructTransaction const&) = delete;
897e40139ffSDimitry Andric  };
898e40139ffSDimitry Andric
899e40139ffSDimitry Andric  template <class... _Args>
900*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_one_at_end(_Args&&... __args) {
901e40139ffSDimitry Andric    _ConstructTransaction __tx(*this, 1);
902*cb14a3feSDimitry Andric    __alloc_traits::construct(this->__alloc(), std::__to_address(__tx.__pos_), std::forward<_Args>(__args)...);
903e40139ffSDimitry Andric    ++__tx.__pos_;
904e40139ffSDimitry Andric  }
905349cc55cSDimitry Andric
906*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI allocator_type& __alloc() _NOEXCEPT {
907*cb14a3feSDimitry Andric    return this->__end_cap_.second();
908*cb14a3feSDimitry Andric  }
909*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const allocator_type& __alloc() const _NOEXCEPT {
910*cb14a3feSDimitry Andric    return this->__end_cap_.second();
911*cb14a3feSDimitry Andric  }
912*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer& __end_cap() _NOEXCEPT {
913*cb14a3feSDimitry Andric    return this->__end_cap_.first();
914*cb14a3feSDimitry Andric  }
915*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const pointer& __end_cap() const _NOEXCEPT {
916*cb14a3feSDimitry Andric    return this->__end_cap_.first();
917*cb14a3feSDimitry Andric  }
918349cc55cSDimitry Andric
919*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __clear() _NOEXCEPT {
920*cb14a3feSDimitry Andric    __base_destruct_at_end(this->__begin_);
921*cb14a3feSDimitry Andric  }
922349cc55cSDimitry Andric
923*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __base_destruct_at_end(pointer __new_last) _NOEXCEPT {
924349cc55cSDimitry Andric    pointer __soon_to_be_end = this->__end_;
925349cc55cSDimitry Andric    while (__new_last != __soon_to_be_end)
926bdd1243dSDimitry Andric      __alloc_traits::destroy(__alloc(), std::__to_address(--__soon_to_be_end));
927349cc55cSDimitry Andric    this->__end_ = __new_last;
928349cc55cSDimitry Andric  }
929349cc55cSDimitry Andric
930*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const vector& __c) {
931*cb14a3feSDimitry Andric    __copy_assign_alloc(__c, integral_constant<bool, __alloc_traits::propagate_on_container_copy_assignment::value>());
932349cc55cSDimitry Andric  }
933349cc55cSDimitry Andric
934*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector& __c)
935*cb14a3feSDimitry Andric      _NOEXCEPT_(!__alloc_traits::propagate_on_container_move_assignment::value ||
936*cb14a3feSDimitry Andric                 is_nothrow_move_assignable<allocator_type>::value) {
937*cb14a3feSDimitry Andric    __move_assign_alloc(__c, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>());
938349cc55cSDimitry Andric  }
939349cc55cSDimitry Andric
940*cb14a3feSDimitry Andric  _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_length_error() const { std::__throw_length_error("vector"); }
941*cb14a3feSDimitry Andric
942*cb14a3feSDimitry Andric  _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range() const { std::__throw_out_of_range("vector"); }
943*cb14a3feSDimitry Andric
944*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const vector& __c, true_type) {
945*cb14a3feSDimitry Andric    if (__alloc() != __c.__alloc()) {
946349cc55cSDimitry Andric      __clear();
94706c3fb27SDimitry Andric      __annotate_delete();
948349cc55cSDimitry Andric      __alloc_traits::deallocate(__alloc(), this->__begin_, capacity());
949349cc55cSDimitry Andric      this->__begin_ = this->__end_ = __end_cap() = nullptr;
950349cc55cSDimitry Andric    }
951349cc55cSDimitry Andric    __alloc() = __c.__alloc();
952349cc55cSDimitry Andric  }
953349cc55cSDimitry Andric
954*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const vector&, false_type) {}
955349cc55cSDimitry Andric
956*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector& __c, true_type)
957*cb14a3feSDimitry Andric      _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) {
958bdd1243dSDimitry Andric    __alloc() = std::move(__c.__alloc());
959349cc55cSDimitry Andric  }
960349cc55cSDimitry Andric
961*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector&, false_type) _NOEXCEPT {}
9620b57cec5SDimitry Andric};
9630b57cec5SDimitry Andric
964349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17
9650b57cec5SDimitry Andrictemplate <class _InputIterator,
966fe6060f1SDimitry Andric          class _Alloc = allocator<__iter_value_type<_InputIterator>>,
96706c3fb27SDimitry Andric          class        = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
968*cb14a3feSDimitry Andric          class        = enable_if_t<__is_allocator<_Alloc>::value> >
969*cb14a3feSDimitry Andricvector(_InputIterator, _InputIterator) -> vector<__iter_value_type<_InputIterator>, _Alloc>;
9700b57cec5SDimitry Andric
9710b57cec5SDimitry Andrictemplate <class _InputIterator,
9720b57cec5SDimitry Andric          class _Alloc,
97306c3fb27SDimitry Andric          class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
974*cb14a3feSDimitry Andric          class = enable_if_t<__is_allocator<_Alloc>::value> >
975*cb14a3feSDimitry Andricvector(_InputIterator, _InputIterator, _Alloc) -> vector<__iter_value_type<_InputIterator>, _Alloc>;
9760b57cec5SDimitry Andric#endif
9770b57cec5SDimitry Andric
97806c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
97906c3fb27SDimitry Andrictemplate <ranges::input_range _Range,
98006c3fb27SDimitry Andric          class _Alloc = allocator<ranges::range_value_t<_Range>>,
981*cb14a3feSDimitry Andric          class        = enable_if_t<__is_allocator<_Alloc>::value> >
982*cb14a3feSDimitry Andricvector(from_range_t, _Range&&, _Alloc = _Alloc()) -> vector<ranges::range_value_t<_Range>, _Alloc>;
98306c3fb27SDimitry Andric#endif
98406c3fb27SDimitry Andric
9850b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
986*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void
987*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v) {
9880b57cec5SDimitry Andric  __annotate_delete();
989972a253aSDimitry Andric  using _RevIter = std::reverse_iterator<pointer>;
990972a253aSDimitry Andric  __v.__begin_   = std::__uninitialized_allocator_move_if_noexcept(
991972a253aSDimitry Andric                     __alloc(), _RevIter(__end_), _RevIter(__begin_), _RevIter(__v.__begin_))
992972a253aSDimitry Andric                     .base();
993bdd1243dSDimitry Andric  std::swap(this->__begin_, __v.__begin_);
994bdd1243dSDimitry Andric  std::swap(this->__end_, __v.__end_);
995bdd1243dSDimitry Andric  std::swap(this->__end_cap(), __v.__end_cap());
9960b57cec5SDimitry Andric  __v.__first_ = __v.__begin_;
9970b57cec5SDimitry Andric  __annotate_new(size());
9980b57cec5SDimitry Andric}
9990b57cec5SDimitry Andric
10000b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1001*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::pointer
1002*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p) {
10030b57cec5SDimitry Andric  __annotate_delete();
10040b57cec5SDimitry Andric  pointer __r    = __v.__begin_;
1005972a253aSDimitry Andric  using _RevIter = std::reverse_iterator<pointer>;
1006972a253aSDimitry Andric  __v.__begin_   = std::__uninitialized_allocator_move_if_noexcept(
1007972a253aSDimitry Andric                     __alloc(), _RevIter(__p), _RevIter(__begin_), _RevIter(__v.__begin_))
1008972a253aSDimitry Andric                     .base();
1009972a253aSDimitry Andric  __v.__end_ = std::__uninitialized_allocator_move_if_noexcept(__alloc(), __p, __end_, __v.__end_);
1010bdd1243dSDimitry Andric  std::swap(this->__begin_, __v.__begin_);
1011bdd1243dSDimitry Andric  std::swap(this->__end_, __v.__end_);
1012bdd1243dSDimitry Andric  std::swap(this->__end_cap(), __v.__end_cap());
10130b57cec5SDimitry Andric  __v.__first_ = __v.__begin_;
10140b57cec5SDimitry Andric  __annotate_new(size());
10150b57cec5SDimitry Andric  return __r;
10160b57cec5SDimitry Andric}
10170b57cec5SDimitry Andric
10180b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1019*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT {
1020*cb14a3feSDimitry Andric  if (this->__begin_ != nullptr) {
10210b57cec5SDimitry Andric    clear();
102206c3fb27SDimitry Andric    __annotate_delete();
10230b57cec5SDimitry Andric    __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
10240b57cec5SDimitry Andric    this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
10250b57cec5SDimitry Andric  }
10260b57cec5SDimitry Andric}
10270b57cec5SDimitry Andric
10280b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1029*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::size_type
1030*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::max_size() const _NOEXCEPT {
1031*cb14a3feSDimitry Andric  return std::min<size_type>(__alloc_traits::max_size(this->__alloc()), numeric_limits<difference_type>::max());
10320b57cec5SDimitry Andric}
10330b57cec5SDimitry Andric
10340b57cec5SDimitry Andric//  Precondition:  __new_size > capacity()
10350b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1036*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
1037*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::__recommend(size_type __new_size) const {
10380b57cec5SDimitry Andric  const size_type __ms = max_size();
10390b57cec5SDimitry Andric  if (__new_size > __ms)
10400b57cec5SDimitry Andric    this->__throw_length_error();
10410b57cec5SDimitry Andric  const size_type __cap = capacity();
10420b57cec5SDimitry Andric  if (__cap >= __ms / 2)
10430b57cec5SDimitry Andric    return __ms;
1044bdd1243dSDimitry Andric  return std::max<size_type>(2 * __cap, __new_size);
10450b57cec5SDimitry Andric}
10460b57cec5SDimitry Andric
10470b57cec5SDimitry Andric//  Default constructs __n objects starting at __end_
10480b57cec5SDimitry Andric//  throws if construction throws
10490b57cec5SDimitry Andric//  Precondition:  __n > 0
10500b57cec5SDimitry Andric//  Precondition:  size() + __n <= capacity()
10510b57cec5SDimitry Andric//  Postcondition:  size() == size() + __n
10520b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1053*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__construct_at_end(size_type __n) {
1054e40139ffSDimitry Andric  _ConstructTransaction __tx(*this, __n);
10555ffd83dbSDimitry Andric  const_pointer __new_end = __tx.__new_end_;
1056349cc55cSDimitry Andric  for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
1057bdd1243dSDimitry Andric    __alloc_traits::construct(this->__alloc(), std::__to_address(__pos));
1058e40139ffSDimitry Andric  }
10590b57cec5SDimitry Andric}
10600b57cec5SDimitry Andric
10610b57cec5SDimitry Andric//  Copy constructs __n objects starting at __end_ from __x
10620b57cec5SDimitry Andric//  throws if construction throws
10630b57cec5SDimitry Andric//  Precondition:  __n > 0
10640b57cec5SDimitry Andric//  Precondition:  size() + __n <= capacity()
10650b57cec5SDimitry Andric//  Postcondition:  size() == old size() + __n
10660b57cec5SDimitry Andric//  Postcondition:  [i] == __x for all i in [size() - __n, __n)
10670b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1068*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline void
1069*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) {
1070e40139ffSDimitry Andric  _ConstructTransaction __tx(*this, __n);
10715ffd83dbSDimitry Andric  const_pointer __new_end = __tx.__new_end_;
1072349cc55cSDimitry Andric  for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
1073bdd1243dSDimitry Andric    __alloc_traits::construct(this->__alloc(), std::__to_address(__pos), __x);
1074e40139ffSDimitry Andric  }
10750b57cec5SDimitry Andric}
10760b57cec5SDimitry Andric
10770b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
107806c3fb27SDimitry Andrictemplate <class _InputIterator, class _Sentinel>
1079bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void
108006c3fb27SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) {
1081e40139ffSDimitry Andric  _ConstructTransaction __tx(*this, __n);
1082972a253aSDimitry Andric  __tx.__pos_ = std::__uninitialized_allocator_copy(__alloc(), __first, __last, __tx.__pos_);
10830b57cec5SDimitry Andric}
10840b57cec5SDimitry Andric
10850b57cec5SDimitry Andric//  Default constructs __n objects starting at __end_
10860b57cec5SDimitry Andric//  throws if construction throws
10870b57cec5SDimitry Andric//  Postcondition:  size() == size() + __n
10880b57cec5SDimitry Andric//  Exception safety: strong.
10890b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1090*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__append(size_type __n) {
10910b57cec5SDimitry Andric  if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
10920b57cec5SDimitry Andric    this->__construct_at_end(__n);
1093*cb14a3feSDimitry Andric  else {
10940b57cec5SDimitry Andric    allocator_type& __a = this->__alloc();
10950b57cec5SDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
10960b57cec5SDimitry Andric    __v.__construct_at_end(__n);
10970b57cec5SDimitry Andric    __swap_out_circular_buffer(__v);
10980b57cec5SDimitry Andric  }
10990b57cec5SDimitry Andric}
11000b57cec5SDimitry Andric
11010b57cec5SDimitry Andric//  Default constructs __n objects starting at __end_
11020b57cec5SDimitry Andric//  throws if construction throws
11030b57cec5SDimitry Andric//  Postcondition:  size() == size() + __n
11040b57cec5SDimitry Andric//  Exception safety: strong.
11050b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1106*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x) {
11070b57cec5SDimitry Andric  if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
11080b57cec5SDimitry Andric    this->__construct_at_end(__n, __x);
1109*cb14a3feSDimitry Andric  else {
11100b57cec5SDimitry Andric    allocator_type& __a = this->__alloc();
11110b57cec5SDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
11120b57cec5SDimitry Andric    __v.__construct_at_end(__n, __x);
11130b57cec5SDimitry Andric    __swap_out_circular_buffer(__v);
11140b57cec5SDimitry Andric  }
11150b57cec5SDimitry Andric}
11160b57cec5SDimitry Andric
11170b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1118*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n) {
1119bdd1243dSDimitry Andric  auto __guard = std::__make_exception_guard(__destroy_vector(*this));
1120*cb14a3feSDimitry Andric  if (__n > 0) {
11210b57cec5SDimitry Andric    __vallocate(__n);
11220b57cec5SDimitry Andric    __construct_at_end(__n);
11230b57cec5SDimitry Andric  }
112450d7464cSDimitry Andric  __guard.__complete();
11250b57cec5SDimitry Andric}
11260b57cec5SDimitry Andric
112706c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
11280b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1129*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
1130*cb14a3feSDimitry Andric    : __end_cap_(nullptr, __a) {
1131bdd1243dSDimitry Andric  auto __guard = std::__make_exception_guard(__destroy_vector(*this));
1132*cb14a3feSDimitry Andric  if (__n > 0) {
11330b57cec5SDimitry Andric    __vallocate(__n);
11340b57cec5SDimitry Andric    __construct_at_end(__n);
11350b57cec5SDimitry Andric  }
113650d7464cSDimitry Andric  __guard.__complete();
11370b57cec5SDimitry Andric}
11380b57cec5SDimitry Andric#endif
11390b57cec5SDimitry Andric
11400b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1141*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x) {
1142bdd1243dSDimitry Andric  auto __guard = std::__make_exception_guard(__destroy_vector(*this));
1143*cb14a3feSDimitry Andric  if (__n > 0) {
11440b57cec5SDimitry Andric    __vallocate(__n);
11450b57cec5SDimitry Andric    __construct_at_end(__n, __x);
11460b57cec5SDimitry Andric  }
114750d7464cSDimitry Andric  __guard.__complete();
11480b57cec5SDimitry Andric}
11490b57cec5SDimitry Andric
11500b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1151*cb14a3feSDimitry Andrictemplate <class _InputIterator,
1152*cb14a3feSDimitry Andric          __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
1153bdd1243dSDimitry Andric                            is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
1154bdd1243dSDimitry Andric                        int> >
1155*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last) {
115606c3fb27SDimitry Andric  __init_with_sentinel(__first, __last);
11570b57cec5SDimitry Andric}
11580b57cec5SDimitry Andric
11590b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1160*cb14a3feSDimitry Andrictemplate <class _InputIterator,
1161*cb14a3feSDimitry Andric          __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
1162bdd1243dSDimitry Andric                            is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
1163bdd1243dSDimitry Andric                        int> >
1164bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
1165bdd1243dSDimitry Andricvector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a)
1166*cb14a3feSDimitry Andric    : __end_cap_(nullptr, __a) {
116706c3fb27SDimitry Andric  __init_with_sentinel(__first, __last);
11680b57cec5SDimitry Andric}
11690b57cec5SDimitry Andric
11700b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1171*cb14a3feSDimitry Andrictemplate <class _ForwardIterator,
1172*cb14a3feSDimitry Andric          __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
1173bdd1243dSDimitry Andric                            is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
1174bdd1243dSDimitry Andric                        int> >
1175*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last) {
117650d7464cSDimitry Andric  size_type __n = static_cast<size_type>(std::distance(__first, __last));
117706c3fb27SDimitry Andric  __init_with_size(__first, __last, __n);
11780b57cec5SDimitry Andric}
11790b57cec5SDimitry Andric
11800b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1181*cb14a3feSDimitry Andrictemplate <class _ForwardIterator,
1182*cb14a3feSDimitry Andric          __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
1183bdd1243dSDimitry Andric                            is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
1184bdd1243dSDimitry Andric                        int> >
1185bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
1186bdd1243dSDimitry Andricvector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a)
1187*cb14a3feSDimitry Andric    : __end_cap_(nullptr, __a) {
118850d7464cSDimitry Andric  size_type __n = static_cast<size_type>(std::distance(__first, __last));
118906c3fb27SDimitry Andric  __init_with_size(__first, __last, __n);
11900b57cec5SDimitry Andric}
11910b57cec5SDimitry Andric
11920b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1193*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<_Tp, _Allocator>::vector(const vector& __x)
1194*cb14a3feSDimitry Andric    : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc())) {
119506c3fb27SDimitry Andric  __init_with_size(__x.__begin_, __x.__end_, __x.size());
11960b57cec5SDimitry Andric}
11970b57cec5SDimitry Andric
11980b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1199bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
120081ad6265SDimitry Andricvector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
1201*cb14a3feSDimitry Andric    : __end_cap_(nullptr, __a) {
120206c3fb27SDimitry Andric  __init_with_size(__x.__begin_, __x.__end_, __x.size());
12030b57cec5SDimitry Andric}
12040b57cec5SDimitry Andric
12050b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1206*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>::vector(vector&& __x)
120706c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
120881ad6265SDimitry Andric    noexcept
12090b57cec5SDimitry Andric#else
12100b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
12110b57cec5SDimitry Andric#endif
1212*cb14a3feSDimitry Andric    : __end_cap_(nullptr, std::move(__x.__alloc())) {
12130b57cec5SDimitry Andric  this->__begin_    = __x.__begin_;
12140b57cec5SDimitry Andric  this->__end_      = __x.__end_;
12150b57cec5SDimitry Andric  this->__end_cap() = __x.__end_cap();
12160b57cec5SDimitry Andric  __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
12170b57cec5SDimitry Andric}
12180b57cec5SDimitry Andric
12190b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1220*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI
122181ad6265SDimitry Andricvector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_type>& __a)
1222*cb14a3feSDimitry Andric    : __end_cap_(nullptr, __a) {
1223*cb14a3feSDimitry Andric  if (__a == __x.__alloc()) {
12240b57cec5SDimitry Andric    this->__begin_    = __x.__begin_;
12250b57cec5SDimitry Andric    this->__end_      = __x.__end_;
12260b57cec5SDimitry Andric    this->__end_cap() = __x.__end_cap();
12270b57cec5SDimitry Andric    __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1228*cb14a3feSDimitry Andric  } else {
12290b57cec5SDimitry Andric    typedef move_iterator<iterator> _Ip;
1230bdd1243dSDimitry Andric    auto __guard = std::__make_exception_guard(__destroy_vector(*this));
12310b57cec5SDimitry Andric    assign(_Ip(__x.begin()), _Ip(__x.end()));
123250d7464cSDimitry Andric    __guard.__complete();
12330b57cec5SDimitry Andric  }
12340b57cec5SDimitry Andric}
12350b57cec5SDimitry Andric
123681ad6265SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
123781ad6265SDimitry Andric
12380b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1239*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI
1240*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il) {
1241bdd1243dSDimitry Andric  auto __guard = std::__make_exception_guard(__destroy_vector(*this));
1242*cb14a3feSDimitry Andric  if (__il.size() > 0) {
12430b57cec5SDimitry Andric    __vallocate(__il.size());
12440b57cec5SDimitry Andric    __construct_at_end(__il.begin(), __il.end(), __il.size());
12450b57cec5SDimitry Andric  }
124650d7464cSDimitry Andric  __guard.__complete();
12470b57cec5SDimitry Andric}
12480b57cec5SDimitry Andric
12490b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1250*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI
12510b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1252*cb14a3feSDimitry Andric    : __end_cap_(nullptr, __a) {
1253bdd1243dSDimitry Andric  auto __guard = std::__make_exception_guard(__destroy_vector(*this));
1254*cb14a3feSDimitry Andric  if (__il.size() > 0) {
12550b57cec5SDimitry Andric    __vallocate(__il.size());
12560b57cec5SDimitry Andric    __construct_at_end(__il.begin(), __il.end(), __il.size());
12570b57cec5SDimitry Andric  }
125850d7464cSDimitry Andric  __guard.__complete();
12590b57cec5SDimitry Andric}
12600b57cec5SDimitry Andric
126181ad6265SDimitry Andric#endif // _LIBCPP_CXX03_LANG
126281ad6265SDimitry Andric
12630b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1264*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>&
12650b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator=(vector&& __x)
1266*cb14a3feSDimitry Andric    _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) {
1267*cb14a3feSDimitry Andric  __move_assign(__x, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>());
12680b57cec5SDimitry Andric  return *this;
12690b57cec5SDimitry Andric}
12700b57cec5SDimitry Andric
12710b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1272*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
1273*cb14a3feSDimitry Andric    _NOEXCEPT_(__alloc_traits::is_always_equal::value) {
1274*cb14a3feSDimitry Andric  if (__alloc() != __c.__alloc()) {
12750b57cec5SDimitry Andric    typedef move_iterator<iterator> _Ip;
12760b57cec5SDimitry Andric    assign(_Ip(__c.begin()), _Ip(__c.end()));
1277*cb14a3feSDimitry Andric  } else
12780b57cec5SDimitry Andric    __move_assign(__c, true_type());
12790b57cec5SDimitry Andric}
12800b57cec5SDimitry Andric
12810b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1282*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
1283*cb14a3feSDimitry Andric    _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) {
12840b57cec5SDimitry Andric  __vdeallocate();
1285349cc55cSDimitry Andric  __move_assign_alloc(__c); // this can throw
12860b57cec5SDimitry Andric  this->__begin_    = __c.__begin_;
12870b57cec5SDimitry Andric  this->__end_      = __c.__end_;
12880b57cec5SDimitry Andric  this->__end_cap() = __c.__end_cap();
12890b57cec5SDimitry Andric  __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
12900b57cec5SDimitry Andric}
12910b57cec5SDimitry Andric
12920b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1293*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>&
1294*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::operator=(const vector& __x) {
1295*cb14a3feSDimitry Andric  if (this != std::addressof(__x)) {
1296349cc55cSDimitry Andric    __copy_assign_alloc(__x);
12970b57cec5SDimitry Andric    assign(__x.__begin_, __x.__end_);
12980b57cec5SDimitry Andric  }
12990b57cec5SDimitry Andric  return *this;
13000b57cec5SDimitry Andric}
13010b57cec5SDimitry Andric
13020b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1303*cb14a3feSDimitry Andrictemplate <class _InputIterator,
1304*cb14a3feSDimitry Andric          __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
1305bdd1243dSDimitry Andric                            is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
1306bdd1243dSDimitry Andric                        int> >
1307*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last) {
130806c3fb27SDimitry Andric  __assign_with_sentinel(__first, __last);
130906c3fb27SDimitry Andric}
131006c3fb27SDimitry Andric
131106c3fb27SDimitry Andrictemplate <class _Tp, class _Allocator>
131206c3fb27SDimitry Andrictemplate <class _Iterator, class _Sentinel>
1313*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
1314*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::__assign_with_sentinel(_Iterator __first, _Sentinel __last) {
13150b57cec5SDimitry Andric  clear();
13160b57cec5SDimitry Andric  for (; __first != __last; ++__first)
131781ad6265SDimitry Andric    emplace_back(*__first);
13180b57cec5SDimitry Andric}
13190b57cec5SDimitry Andric
13200b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1321*cb14a3feSDimitry Andrictemplate <class _ForwardIterator,
1322*cb14a3feSDimitry Andric          __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
1323bdd1243dSDimitry Andric                            is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
1324bdd1243dSDimitry Andric                        int> >
1325*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) {
132606c3fb27SDimitry Andric  __assign_with_size(__first, __last, std::distance(__first, __last));
132706c3fb27SDimitry Andric}
132806c3fb27SDimitry Andric
132906c3fb27SDimitry Andrictemplate <class _Tp, class _Allocator>
133006c3fb27SDimitry Andrictemplate <class _ForwardIterator, class _Sentinel>
1331*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
1332*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::__assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __n) {
133306c3fb27SDimitry Andric  size_type __new_size = static_cast<size_type>(__n);
1334*cb14a3feSDimitry Andric  if (__new_size <= capacity()) {
1335*cb14a3feSDimitry Andric    if (__new_size > size()) {
133606c3fb27SDimitry Andric      _ForwardIterator __mid = std::next(__first, size());
133706c3fb27SDimitry Andric      std::copy(__first, __mid, this->__begin_);
13380b57cec5SDimitry Andric      __construct_at_end(__mid, __last, __new_size - size());
1339*cb14a3feSDimitry Andric    } else {
134006c3fb27SDimitry Andric      pointer __m = std::__copy<_ClassicAlgPolicy>(__first, __last, this->__begin_).second;
13410b57cec5SDimitry Andric      this->__destruct_at_end(__m);
13420b57cec5SDimitry Andric    }
1343*cb14a3feSDimitry Andric  } else {
13440b57cec5SDimitry Andric    __vdeallocate();
13450b57cec5SDimitry Andric    __vallocate(__recommend(__new_size));
13460b57cec5SDimitry Andric    __construct_at_end(__first, __last, __new_size);
13470b57cec5SDimitry Andric  }
13480b57cec5SDimitry Andric}
13490b57cec5SDimitry Andric
13500b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1351*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u) {
1352*cb14a3feSDimitry Andric  if (__n <= capacity()) {
13530b57cec5SDimitry Andric    size_type __s = size();
1354bdd1243dSDimitry Andric    std::fill_n(this->__begin_, std::min(__n, __s), __u);
13550b57cec5SDimitry Andric    if (__n > __s)
13560b57cec5SDimitry Andric      __construct_at_end(__n - __s, __u);
13570b57cec5SDimitry Andric    else
13580b57cec5SDimitry Andric      this->__destruct_at_end(this->__begin_ + __n);
1359*cb14a3feSDimitry Andric  } else {
13600b57cec5SDimitry Andric    __vdeallocate();
13610b57cec5SDimitry Andric    __vallocate(__recommend(static_cast<size_type>(__n)));
13620b57cec5SDimitry Andric    __construct_at_end(__n, __u);
13630b57cec5SDimitry Andric  }
13640b57cec5SDimitry Andric}
13650b57cec5SDimitry Andric
13660b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1367*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator
1368*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::begin() _NOEXCEPT {
1369bdd1243dSDimitry Andric  return __make_iter(this->__begin_);
13700b57cec5SDimitry Andric}
13710b57cec5SDimitry Andric
13720b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1373*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::const_iterator
1374*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::begin() const _NOEXCEPT {
1375bdd1243dSDimitry Andric  return __make_iter(this->__begin_);
13760b57cec5SDimitry Andric}
13770b57cec5SDimitry Andric
13780b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1379*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator
1380*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::end() _NOEXCEPT {
1381bdd1243dSDimitry Andric  return __make_iter(this->__end_);
13820b57cec5SDimitry Andric}
13830b57cec5SDimitry Andric
13840b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1385*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::const_iterator
1386*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::end() const _NOEXCEPT {
1387bdd1243dSDimitry Andric  return __make_iter(this->__end_);
13880b57cec5SDimitry Andric}
13890b57cec5SDimitry Andric
13900b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1391*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::reference
1392*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT {
139306c3fb27SDimitry Andric  _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < size(), "vector[] index out of bounds");
13940b57cec5SDimitry Andric  return this->__begin_[__n];
13950b57cec5SDimitry Andric}
13960b57cec5SDimitry Andric
13970b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1398*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::const_reference
1399*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT {
140006c3fb27SDimitry Andric  _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < size(), "vector[] index out of bounds");
14010b57cec5SDimitry Andric  return this->__begin_[__n];
14020b57cec5SDimitry Andric}
14030b57cec5SDimitry Andric
14040b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1405*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::reference vector<_Tp, _Allocator>::at(size_type __n) {
14060b57cec5SDimitry Andric  if (__n >= size())
14070b57cec5SDimitry Andric    this->__throw_out_of_range();
14080b57cec5SDimitry Andric  return this->__begin_[__n];
14090b57cec5SDimitry Andric}
14100b57cec5SDimitry Andric
14110b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1412*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::const_reference
1413*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::at(size_type __n) const {
14140b57cec5SDimitry Andric  if (__n >= size())
14150b57cec5SDimitry Andric    this->__throw_out_of_range();
14160b57cec5SDimitry Andric  return this->__begin_[__n];
14170b57cec5SDimitry Andric}
14180b57cec5SDimitry Andric
14190b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1420*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::reserve(size_type __n) {
1421*cb14a3feSDimitry Andric  if (__n > capacity()) {
1422349cc55cSDimitry Andric    if (__n > max_size())
1423349cc55cSDimitry Andric      this->__throw_length_error();
14240b57cec5SDimitry Andric    allocator_type& __a = this->__alloc();
14250b57cec5SDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
14260b57cec5SDimitry Andric    __swap_out_circular_buffer(__v);
14270b57cec5SDimitry Andric  }
14280b57cec5SDimitry Andric}
14290b57cec5SDimitry Andric
14300b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1431*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT {
1432*cb14a3feSDimitry Andric  if (capacity() > size()) {
143306c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1434*cb14a3feSDimitry Andric    try {
143506c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
14360b57cec5SDimitry Andric      allocator_type& __a = this->__alloc();
14370b57cec5SDimitry Andric      __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
14380b57cec5SDimitry Andric      __swap_out_circular_buffer(__v);
143906c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1440*cb14a3feSDimitry Andric    } catch (...) {
14410b57cec5SDimitry Andric    }
144206c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
14430b57cec5SDimitry Andric  }
14440b57cec5SDimitry Andric}
14450b57cec5SDimitry Andric
14460b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
14470b57cec5SDimitry Andrictemplate <class _Up>
1448*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::pointer
1449*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x) {
14500b57cec5SDimitry Andric  allocator_type& __a = this->__alloc();
14510b57cec5SDimitry Andric  __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1452bdd1243dSDimitry Andric  // __v.push_back(std::forward<_Up>(__x));
1453bdd1243dSDimitry Andric  __alloc_traits::construct(__a, std::__to_address(__v.__end_), std::forward<_Up>(__x));
14540b57cec5SDimitry Andric  __v.__end_++;
14550b57cec5SDimitry Andric  __swap_out_circular_buffer(__v);
14565f757f3fSDimitry Andric  return this->__end_;
14570b57cec5SDimitry Andric}
14580b57cec5SDimitry Andric
14590b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1460*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI void
1461*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::push_back(const_reference __x) {
14625f757f3fSDimitry Andric  pointer __end = this->__end_;
14635f757f3fSDimitry Andric  if (__end < this->__end_cap()) {
1464e40139ffSDimitry Andric    __construct_one_at_end(__x);
14655f757f3fSDimitry Andric    ++__end;
14665f757f3fSDimitry Andric  } else {
14675f757f3fSDimitry Andric    __end = __push_back_slow_path(__x);
14680b57cec5SDimitry Andric  }
14695f757f3fSDimitry Andric  this->__end_ = __end;
14700b57cec5SDimitry Andric}
14710b57cec5SDimitry Andric
14720b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1473*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI void vector<_Tp, _Allocator>::push_back(value_type&& __x) {
14745f757f3fSDimitry Andric  pointer __end = this->__end_;
14755f757f3fSDimitry Andric  if (__end < this->__end_cap()) {
1476bdd1243dSDimitry Andric    __construct_one_at_end(std::move(__x));
14775f757f3fSDimitry Andric    ++__end;
14785f757f3fSDimitry Andric  } else {
14795f757f3fSDimitry Andric    __end = __push_back_slow_path(std::move(__x));
14800b57cec5SDimitry Andric  }
14815f757f3fSDimitry Andric  this->__end_ = __end;
14820b57cec5SDimitry Andric}
14830b57cec5SDimitry Andric
14840b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
14850b57cec5SDimitry Andrictemplate <class... _Args>
1486*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::pointer
1487*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args) {
14880b57cec5SDimitry Andric  allocator_type& __a = this->__alloc();
14890b57cec5SDimitry Andric  __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1490bdd1243dSDimitry Andric  //    __v.emplace_back(std::forward<_Args>(__args)...);
1491bdd1243dSDimitry Andric  __alloc_traits::construct(__a, std::__to_address(__v.__end_), std::forward<_Args>(__args)...);
14920b57cec5SDimitry Andric  __v.__end_++;
14930b57cec5SDimitry Andric  __swap_out_circular_buffer(__v);
14945f757f3fSDimitry Andric  return this->__end_;
14950b57cec5SDimitry Andric}
14960b57cec5SDimitry Andric
14970b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
14980b57cec5SDimitry Andrictemplate <class... _Args>
1499*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline
150006c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
15010b57cec5SDimitry Andric    typename vector<_Tp, _Allocator>::reference
15020b57cec5SDimitry Andric#else
15030b57cec5SDimitry Andric    void
15040b57cec5SDimitry Andric#endif
1505*cb14a3feSDimitry Andric    vector<_Tp, _Allocator>::emplace_back(_Args&&... __args) {
15065f757f3fSDimitry Andric  pointer __end = this->__end_;
15075f757f3fSDimitry Andric  if (__end < this->__end_cap()) {
1508bdd1243dSDimitry Andric    __construct_one_at_end(std::forward<_Args>(__args)...);
15095f757f3fSDimitry Andric    ++__end;
15105f757f3fSDimitry Andric  } else {
15115f757f3fSDimitry Andric    __end = __emplace_back_slow_path(std::forward<_Args>(__args)...);
15120b57cec5SDimitry Andric  }
15135f757f3fSDimitry Andric  this->__end_ = __end;
151406c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
15155f757f3fSDimitry Andric  return *(__end - 1);
15160b57cec5SDimitry Andric#endif
15170b57cec5SDimitry Andric}
15180b57cec5SDimitry Andric
15190b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1520*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline void vector<_Tp, _Allocator>::pop_back() {
152106c3fb27SDimitry Andric  _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "vector::pop_back called on an empty vector");
15220b57cec5SDimitry Andric  this->__destruct_at_end(this->__end_ - 1);
15230b57cec5SDimitry Andric}
15240b57cec5SDimitry Andric
15250b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1526*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator
1527*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::erase(const_iterator __position) {
1528*cb14a3feSDimitry Andric  _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
1529*cb14a3feSDimitry Andric      __position != end(), "vector::erase(iterator) called with a non-dereferenceable iterator");
15300b57cec5SDimitry Andric  difference_type __ps = __position - cbegin();
15310b57cec5SDimitry Andric  pointer __p          = this->__begin_ + __ps;
1532bdd1243dSDimitry Andric  this->__destruct_at_end(std::move(__p + 1, this->__end_, __p));
1533bdd1243dSDimitry Andric  return __make_iter(__p);
15340b57cec5SDimitry Andric}
15350b57cec5SDimitry Andric
15360b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1537*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
1538*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) {
153906c3fb27SDimitry Andric  _LIBCPP_ASSERT_VALID_INPUT_RANGE(__first <= __last, "vector::erase(first, last) called with invalid range");
15400b57cec5SDimitry Andric  pointer __p = this->__begin_ + (__first - begin());
15410b57cec5SDimitry Andric  if (__first != __last) {
1542bdd1243dSDimitry Andric    this->__destruct_at_end(std::move(__p + (__last - __first), this->__end_, __p));
15430b57cec5SDimitry Andric  }
1544bdd1243dSDimitry Andric  return __make_iter(__p);
15450b57cec5SDimitry Andric}
15460b57cec5SDimitry Andric
15470b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1548*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void
1549*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to) {
15500b57cec5SDimitry Andric  pointer __old_last  = this->__end_;
15510b57cec5SDimitry Andric  difference_type __n = __old_last - __to;
1552e40139ffSDimitry Andric  {
1553e40139ffSDimitry Andric    pointer __i = __from_s + __n;
1554e40139ffSDimitry Andric    _ConstructTransaction __tx(*this, __from_e - __i);
1555*cb14a3feSDimitry Andric    for (pointer __pos = __tx.__pos_; __i < __from_e; ++__i, (void)++__pos, __tx.__pos_ = __pos) {
1556*cb14a3feSDimitry Andric      __alloc_traits::construct(this->__alloc(), std::__to_address(__pos), std::move(*__i));
1557e40139ffSDimitry Andric    }
1558e40139ffSDimitry Andric  }
1559bdd1243dSDimitry Andric  std::move_backward(__from_s, __from_s + __n, __old_last);
15600b57cec5SDimitry Andric}
15610b57cec5SDimitry Andric
15620b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1563*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
1564*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) {
15650b57cec5SDimitry Andric  pointer __p = this->__begin_ + (__position - begin());
156661cfbce3SDimitry Andric  // We can't compare unrelated pointers inside constant expressions
1567*cb14a3feSDimitry Andric  if (!__libcpp_is_constant_evaluated() && this->__end_ < this->__end_cap()) {
1568*cb14a3feSDimitry Andric    if (__p == this->__end_) {
1569e40139ffSDimitry Andric      __construct_one_at_end(__x);
1570*cb14a3feSDimitry Andric    } else {
15710b57cec5SDimitry Andric      __move_range(__p, this->__end_, __p + 1);
15720b57cec5SDimitry Andric      const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
15730b57cec5SDimitry Andric      if (__p <= __xr && __xr < this->__end_)
15740b57cec5SDimitry Andric        ++__xr;
15750b57cec5SDimitry Andric      *__p = *__xr;
15760b57cec5SDimitry Andric    }
1577*cb14a3feSDimitry Andric  } else {
15780b57cec5SDimitry Andric    allocator_type& __a = this->__alloc();
15790b57cec5SDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
15800b57cec5SDimitry Andric    __v.push_back(__x);
15810b57cec5SDimitry Andric    __p = __swap_out_circular_buffer(__v, __p);
15820b57cec5SDimitry Andric  }
1583bdd1243dSDimitry Andric  return __make_iter(__p);
15840b57cec5SDimitry Andric}
15850b57cec5SDimitry Andric
15860b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1587*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
1588*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) {
15890b57cec5SDimitry Andric  pointer __p = this->__begin_ + (__position - begin());
1590*cb14a3feSDimitry Andric  if (this->__end_ < this->__end_cap()) {
1591*cb14a3feSDimitry Andric    if (__p == this->__end_) {
1592bdd1243dSDimitry Andric      __construct_one_at_end(std::move(__x));
1593*cb14a3feSDimitry Andric    } else {
15940b57cec5SDimitry Andric      __move_range(__p, this->__end_, __p + 1);
1595bdd1243dSDimitry Andric      *__p = std::move(__x);
15960b57cec5SDimitry Andric    }
1597*cb14a3feSDimitry Andric  } else {
15980b57cec5SDimitry Andric    allocator_type& __a = this->__alloc();
15990b57cec5SDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1600bdd1243dSDimitry Andric    __v.push_back(std::move(__x));
16010b57cec5SDimitry Andric    __p = __swap_out_circular_buffer(__v, __p);
16020b57cec5SDimitry Andric  }
1603bdd1243dSDimitry Andric  return __make_iter(__p);
16040b57cec5SDimitry Andric}
16050b57cec5SDimitry Andric
16060b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
16070b57cec5SDimitry Andrictemplate <class... _Args>
1608*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
1609*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) {
16100b57cec5SDimitry Andric  pointer __p = this->__begin_ + (__position - begin());
1611*cb14a3feSDimitry Andric  if (this->__end_ < this->__end_cap()) {
1612*cb14a3feSDimitry Andric    if (__p == this->__end_) {
1613bdd1243dSDimitry Andric      __construct_one_at_end(std::forward<_Args>(__args)...);
1614*cb14a3feSDimitry Andric    } else {
1615bdd1243dSDimitry Andric      __temp_value<value_type, _Allocator> __tmp(this->__alloc(), std::forward<_Args>(__args)...);
16160b57cec5SDimitry Andric      __move_range(__p, this->__end_, __p + 1);
1617bdd1243dSDimitry Andric      *__p = std::move(__tmp.get());
16180b57cec5SDimitry Andric    }
1619*cb14a3feSDimitry Andric  } else {
16200b57cec5SDimitry Andric    allocator_type& __a = this->__alloc();
16210b57cec5SDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1622bdd1243dSDimitry Andric    __v.emplace_back(std::forward<_Args>(__args)...);
16230b57cec5SDimitry Andric    __p = __swap_out_circular_buffer(__v, __p);
16240b57cec5SDimitry Andric  }
1625bdd1243dSDimitry Andric  return __make_iter(__p);
16260b57cec5SDimitry Andric}
16270b57cec5SDimitry Andric
16280b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1629*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
1630*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x) {
16310b57cec5SDimitry Andric  pointer __p = this->__begin_ + (__position - begin());
1632*cb14a3feSDimitry Andric  if (__n > 0) {
163361cfbce3SDimitry Andric    // We can't compare unrelated pointers inside constant expressions
1634*cb14a3feSDimitry Andric    if (!__libcpp_is_constant_evaluated() && __n <= static_cast<size_type>(this->__end_cap() - this->__end_)) {
16350b57cec5SDimitry Andric      size_type __old_n  = __n;
16360b57cec5SDimitry Andric      pointer __old_last = this->__end_;
1637*cb14a3feSDimitry Andric      if (__n > static_cast<size_type>(this->__end_ - __p)) {
16380b57cec5SDimitry Andric        size_type __cx = __n - (this->__end_ - __p);
16390b57cec5SDimitry Andric        __construct_at_end(__cx, __x);
16400b57cec5SDimitry Andric        __n -= __cx;
16410b57cec5SDimitry Andric      }
1642*cb14a3feSDimitry Andric      if (__n > 0) {
16430b57cec5SDimitry Andric        __move_range(__p, __old_last, __p + __old_n);
16440b57cec5SDimitry Andric        const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
16450b57cec5SDimitry Andric        if (__p <= __xr && __xr < this->__end_)
16460b57cec5SDimitry Andric          __xr += __old_n;
1647bdd1243dSDimitry Andric        std::fill_n(__p, __n, *__xr);
16480b57cec5SDimitry Andric      }
1649*cb14a3feSDimitry Andric    } else {
16500b57cec5SDimitry Andric      allocator_type& __a = this->__alloc();
16510b57cec5SDimitry Andric      __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
16520b57cec5SDimitry Andric      __v.__construct_at_end(__n, __x);
16530b57cec5SDimitry Andric      __p = __swap_out_circular_buffer(__v, __p);
16540b57cec5SDimitry Andric    }
16550b57cec5SDimitry Andric  }
1656bdd1243dSDimitry Andric  return __make_iter(__p);
16570b57cec5SDimitry Andric}
16580b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1659*cb14a3feSDimitry Andrictemplate <class _InputIterator,
1660*cb14a3feSDimitry Andric          __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
1661bdd1243dSDimitry Andric                            is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
1662bdd1243dSDimitry Andric                        int> >
1663bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
1664*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) {
166506c3fb27SDimitry Andric  return __insert_with_sentinel(__position, __first, __last);
166606c3fb27SDimitry Andric}
166706c3fb27SDimitry Andric
166806c3fb27SDimitry Andrictemplate <class _Tp, class _Allocator>
166906c3fb27SDimitry Andrictemplate <class _InputIterator, class _Sentinel>
1670*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator
167106c3fb27SDimitry Andricvector<_Tp, _Allocator>::__insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last) {
16720b57cec5SDimitry Andric  difference_type __off = __position - begin();
16730b57cec5SDimitry Andric  pointer __p           = this->__begin_ + __off;
16740b57cec5SDimitry Andric  allocator_type& __a   = this->__alloc();
16750b57cec5SDimitry Andric  pointer __old_last    = this->__end_;
1676*cb14a3feSDimitry Andric  for (; this->__end_ != this->__end_cap() && __first != __last; ++__first) {
1677e40139ffSDimitry Andric    __construct_one_at_end(*__first);
16780b57cec5SDimitry Andric  }
16790b57cec5SDimitry Andric  __split_buffer<value_type, allocator_type&> __v(__a);
1680*cb14a3feSDimitry Andric  if (__first != __last) {
168106c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1682*cb14a3feSDimitry Andric    try {
168306c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
168406c3fb27SDimitry Andric      __v.__construct_at_end_with_sentinel(std::move(__first), std::move(__last));
16850b57cec5SDimitry Andric      difference_type __old_size = __old_last - this->__begin_;
16860b57cec5SDimitry Andric      difference_type __old_p    = __p - this->__begin_;
16870b57cec5SDimitry Andric      reserve(__recommend(size() + __v.size()));
16880b57cec5SDimitry Andric      __p        = this->__begin_ + __old_p;
16890b57cec5SDimitry Andric      __old_last = this->__begin_ + __old_size;
169006c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1691*cb14a3feSDimitry Andric    } catch (...) {
1692bdd1243dSDimitry Andric      erase(__make_iter(__old_last), end());
16930b57cec5SDimitry Andric      throw;
16940b57cec5SDimitry Andric    }
169506c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
16960b57cec5SDimitry Andric  }
1697bdd1243dSDimitry Andric  __p = std::rotate(__p, __old_last, this->__end_);
1698*cb14a3feSDimitry Andric  insert(__make_iter(__p), std::make_move_iterator(__v.begin()), std::make_move_iterator(__v.end()));
16990b57cec5SDimitry Andric  return begin() + __off;
17000b57cec5SDimitry Andric}
17010b57cec5SDimitry Andric
17020b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1703*cb14a3feSDimitry Andrictemplate <class _ForwardIterator,
1704*cb14a3feSDimitry Andric          __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
1705bdd1243dSDimitry Andric                            is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
1706bdd1243dSDimitry Andric                        int> >
1707bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
1708*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) {
170906c3fb27SDimitry Andric  return __insert_with_size(__position, __first, __last, std::distance(__first, __last));
171006c3fb27SDimitry Andric}
171106c3fb27SDimitry Andric
171206c3fb27SDimitry Andrictemplate <class _Tp, class _Allocator>
171306c3fb27SDimitry Andrictemplate <class _Iterator, class _Sentinel>
1714*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator
1715*cb14a3feSDimitry Andricvector<_Tp, _Allocator>::__insert_with_size(
1716*cb14a3feSDimitry Andric    const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n) {
171706c3fb27SDimitry Andric  auto __insertion_size = __n;
17180b57cec5SDimitry Andric  pointer __p           = this->__begin_ + (__position - begin());
1719*cb14a3feSDimitry Andric  if (__n > 0) {
1720*cb14a3feSDimitry Andric    if (__n <= this->__end_cap() - this->__end_) {
17210b57cec5SDimitry Andric      size_type __old_n    = __n;
17220b57cec5SDimitry Andric      pointer __old_last   = this->__end_;
172306c3fb27SDimitry Andric      _Iterator __m        = std::next(__first, __n);
17240b57cec5SDimitry Andric      difference_type __dx = this->__end_ - __p;
1725*cb14a3feSDimitry Andric      if (__n > __dx) {
17260b57cec5SDimitry Andric        __m                    = __first;
17270b57cec5SDimitry Andric        difference_type __diff = this->__end_ - __p;
1728bdd1243dSDimitry Andric        std::advance(__m, __diff);
17290b57cec5SDimitry Andric        __construct_at_end(__m, __last, __n - __diff);
17300b57cec5SDimitry Andric        __n = __dx;
17310b57cec5SDimitry Andric      }
1732*cb14a3feSDimitry Andric      if (__n > 0) {
17330b57cec5SDimitry Andric        __move_range(__p, __old_last, __p + __old_n);
1734bdd1243dSDimitry Andric        std::copy(__first, __m, __p);
17350b57cec5SDimitry Andric      }
1736*cb14a3feSDimitry Andric    } else {
17370b57cec5SDimitry Andric      allocator_type& __a = this->__alloc();
17380b57cec5SDimitry Andric      __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
173906c3fb27SDimitry Andric      __v.__construct_at_end_with_size(__first, __insertion_size);
17400b57cec5SDimitry Andric      __p = __swap_out_circular_buffer(__v, __p);
17410b57cec5SDimitry Andric    }
17420b57cec5SDimitry Andric  }
1743bdd1243dSDimitry Andric  return __make_iter(__p);
17440b57cec5SDimitry Andric}
17450b57cec5SDimitry Andric
17460b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1747*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::resize(size_type __sz) {
17480b57cec5SDimitry Andric  size_type __cs = size();
17490b57cec5SDimitry Andric  if (__cs < __sz)
17500b57cec5SDimitry Andric    this->__append(__sz - __cs);
17510b57cec5SDimitry Andric  else if (__cs > __sz)
17520b57cec5SDimitry Andric    this->__destruct_at_end(this->__begin_ + __sz);
17530b57cec5SDimitry Andric}
17540b57cec5SDimitry Andric
17550b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1756*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x) {
17570b57cec5SDimitry Andric  size_type __cs = size();
17580b57cec5SDimitry Andric  if (__cs < __sz)
17590b57cec5SDimitry Andric    this->__append(__sz - __cs, __x);
17600b57cec5SDimitry Andric  else if (__cs > __sz)
17610b57cec5SDimitry Andric    this->__destruct_at_end(this->__begin_ + __sz);
17620b57cec5SDimitry Andric}
17630b57cec5SDimitry Andric
17640b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1765*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<_Tp, _Allocator>::swap(vector& __x)
17660b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
17670b57cec5SDimitry Andric    _NOEXCEPT
17680b57cec5SDimitry Andric#else
1769*cb14a3feSDimitry Andric    _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value)
17700b57cec5SDimitry Andric#endif
17710b57cec5SDimitry Andric{
1772*cb14a3feSDimitry Andric  _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1773*cb14a3feSDimitry Andric      __alloc_traits::propagate_on_container_swap::value || this->__alloc() == __x.__alloc(),
17740b57cec5SDimitry Andric      "vector::swap: Either propagate_on_container_swap must be true"
17750b57cec5SDimitry Andric      " or the allocators must compare equal");
1776bdd1243dSDimitry Andric  std::swap(this->__begin_, __x.__begin_);
1777bdd1243dSDimitry Andric  std::swap(this->__end_, __x.__end_);
1778bdd1243dSDimitry Andric  std::swap(this->__end_cap(), __x.__end_cap());
1779*cb14a3feSDimitry Andric  std::__swap_allocator(
1780*cb14a3feSDimitry Andric      this->__alloc(), __x.__alloc(), integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
17810b57cec5SDimitry Andric}
17820b57cec5SDimitry Andric
17830b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1784*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 bool vector<_Tp, _Allocator>::__invariants() const {
1785*cb14a3feSDimitry Andric  if (this->__begin_ == nullptr) {
17860b57cec5SDimitry Andric    if (this->__end_ != nullptr || this->__end_cap() != nullptr)
17870b57cec5SDimitry Andric      return false;
1788*cb14a3feSDimitry Andric  } else {
17890b57cec5SDimitry Andric    if (this->__begin_ > this->__end_)
17900b57cec5SDimitry Andric      return false;
17910b57cec5SDimitry Andric    if (this->__begin_ == this->__end_cap())
17920b57cec5SDimitry Andric      return false;
17930b57cec5SDimitry Andric    if (this->__end_ > this->__end_cap())
17940b57cec5SDimitry Andric      return false;
17950b57cec5SDimitry Andric  }
17960b57cec5SDimitry Andric  return true;
17970b57cec5SDimitry Andric}
17980b57cec5SDimitry Andric
17990b57cec5SDimitry Andric// vector<bool>
18000b57cec5SDimitry Andric
1801*cb14a3feSDimitry Andrictemplate <class _Allocator>
1802*cb14a3feSDimitry Andricclass vector<bool, _Allocator>;
18030b57cec5SDimitry Andric
18040b57cec5SDimitry Andrictemplate <class _Allocator>
1805*cb14a3feSDimitry Andricstruct hash<vector<bool, _Allocator> >;
1806*cb14a3feSDimitry Andric
1807*cb14a3feSDimitry Andrictemplate <class _Allocator>
1808*cb14a3feSDimitry Andricstruct __has_storage_type<vector<bool, _Allocator> > {
18090b57cec5SDimitry Andric  static const bool value = true;
18100b57cec5SDimitry Andric};
18110b57cec5SDimitry Andric
18120b57cec5SDimitry Andrictemplate <class _Allocator>
1813*cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> {
18140b57cec5SDimitry Andricpublic:
18150b57cec5SDimitry Andric  typedef vector __self;
18160b57cec5SDimitry Andric  typedef bool value_type;
18170b57cec5SDimitry Andric  typedef _Allocator allocator_type;
18180b57cec5SDimitry Andric  typedef allocator_traits<allocator_type> __alloc_traits;
18190b57cec5SDimitry Andric  typedef typename __alloc_traits::size_type size_type;
18200b57cec5SDimitry Andric  typedef typename __alloc_traits::difference_type difference_type;
18210b57cec5SDimitry Andric  typedef size_type __storage_type;
18220b57cec5SDimitry Andric  typedef __bit_iterator<vector, false> pointer;
18230b57cec5SDimitry Andric  typedef __bit_iterator<vector, true> const_pointer;
18240b57cec5SDimitry Andric  typedef pointer iterator;
18250b57cec5SDimitry Andric  typedef const_pointer const_iterator;
1826bdd1243dSDimitry Andric  typedef std::reverse_iterator<iterator> reverse_iterator;
1827bdd1243dSDimitry Andric  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
18280b57cec5SDimitry Andric
18290b57cec5SDimitry Andricprivate:
1830bdd1243dSDimitry Andric  typedef __rebind_alloc<__alloc_traits, __storage_type> __storage_allocator;
18310b57cec5SDimitry Andric  typedef allocator_traits<__storage_allocator> __storage_traits;
18320b57cec5SDimitry Andric  typedef typename __storage_traits::pointer __storage_pointer;
18330b57cec5SDimitry Andric  typedef typename __storage_traits::const_pointer __const_storage_pointer;
18340b57cec5SDimitry Andric
18350b57cec5SDimitry Andric  __storage_pointer __begin_;
18360b57cec5SDimitry Andric  size_type __size_;
18370b57cec5SDimitry Andric  __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
1838*cb14a3feSDimitry Andric
18390b57cec5SDimitry Andricpublic:
18400b57cec5SDimitry Andric  typedef __bit_reference<vector> reference;
184181ad6265SDimitry Andric#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
184281ad6265SDimitry Andric  using const_reference = bool;
184381ad6265SDimitry Andric#else
18440b57cec5SDimitry Andric  typedef __bit_const_reference<vector> const_reference;
184581ad6265SDimitry Andric#endif
1846*cb14a3feSDimitry Andric
18470b57cec5SDimitry Andricprivate:
1848*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type& __cap() _NOEXCEPT { return __cap_alloc_.first(); }
1849*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const size_type& __cap() const _NOEXCEPT {
1850*cb14a3feSDimitry Andric    return __cap_alloc_.first();
1851*cb14a3feSDimitry Andric  }
1852*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __storage_allocator& __alloc() _NOEXCEPT {
1853*cb14a3feSDimitry Andric    return __cap_alloc_.second();
1854*cb14a3feSDimitry Andric  }
1855*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const __storage_allocator& __alloc() const _NOEXCEPT {
1856*cb14a3feSDimitry Andric    return __cap_alloc_.second();
1857*cb14a3feSDimitry Andric  }
18580b57cec5SDimitry Andric
18590b57cec5SDimitry Andric  static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
18600b57cec5SDimitry Andric
1861*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type
1862*cb14a3feSDimitry Andric  __internal_cap_to_external(size_type __n) _NOEXCEPT {
1863*cb14a3feSDimitry Andric    return __n * __bits_per_word;
1864*cb14a3feSDimitry Andric  }
1865*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type
1866*cb14a3feSDimitry Andric  __external_cap_to_internal(size_type __n) _NOEXCEPT {
1867*cb14a3feSDimitry Andric    return (__n - 1) / __bits_per_word + 1;
1868*cb14a3feSDimitry Andric  }
18690b57cec5SDimitry Andric
18700b57cec5SDimitry Andricpublic:
1871*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector()
1872*cb14a3feSDimitry Andric      _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
18730b57cec5SDimitry Andric
1874bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(const allocator_type& __a)
18750b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
18760b57cec5SDimitry Andric      _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
18770b57cec5SDimitry Andric#else
18780b57cec5SDimitry Andric      _NOEXCEPT;
18790b57cec5SDimitry Andric#endif
188050d7464cSDimitry Andric
188150d7464cSDimitry Andricprivate:
188250d7464cSDimitry Andric  class __destroy_vector {
188350d7464cSDimitry Andric  public:
188406c3fb27SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI __destroy_vector(vector& __vec) : __vec_(__vec) {}
188550d7464cSDimitry Andric
1886bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() {
188750d7464cSDimitry Andric      if (__vec_.__begin_ != nullptr)
188850d7464cSDimitry Andric        __storage_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.__cap());
188950d7464cSDimitry Andric    }
189050d7464cSDimitry Andric
189150d7464cSDimitry Andric  private:
189250d7464cSDimitry Andric    vector& __vec_;
189350d7464cSDimitry Andric  };
189450d7464cSDimitry Andric
189550d7464cSDimitry Andricpublic:
1896bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~vector() { __destroy_vector (*this)(); }
189750d7464cSDimitry Andric
1898bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n);
189906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
1900bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n, const allocator_type& __a);
19010b57cec5SDimitry Andric#endif
1902bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(size_type __n, const value_type& __v);
1903*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
1904*cb14a3feSDimitry Andric  vector(size_type __n, const value_type& __v, const allocator_type& __a);
19055f757f3fSDimitry Andric  template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
19065f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_InputIterator __first, _InputIterator __last);
19075f757f3fSDimitry Andric  template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
1908*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
1909*cb14a3feSDimitry Andric  vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
19105f757f3fSDimitry Andric  template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
19115f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_ForwardIterator __first, _ForwardIterator __last);
19125f757f3fSDimitry Andric  template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
1913*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
1914*cb14a3feSDimitry Andric  vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a);
191506c3fb27SDimitry Andric
191606c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
191706c3fb27SDimitry Andric  template <_ContainerCompatibleRange<bool> _Range>
1918*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr vector(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type())
1919*cb14a3feSDimitry Andric      : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) {
192006c3fb27SDimitry Andric    if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
192106c3fb27SDimitry Andric      auto __n = static_cast<size_type>(ranges::distance(__range));
192206c3fb27SDimitry Andric      __init_with_size(ranges::begin(__range), ranges::end(__range), __n);
192306c3fb27SDimitry Andric
192406c3fb27SDimitry Andric    } else {
192506c3fb27SDimitry Andric      __init_with_sentinel(ranges::begin(__range), ranges::end(__range));
192606c3fb27SDimitry Andric    }
192706c3fb27SDimitry Andric  }
192806c3fb27SDimitry Andric#endif
19290b57cec5SDimitry Andric
1930bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(const vector& __v);
1931bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(const vector& __v, const allocator_type& __a);
1932bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector& operator=(const vector& __v);
19330b57cec5SDimitry Andric
19340b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
1935bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(initializer_list<value_type> __il);
1936bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
1937*cb14a3feSDimitry Andric  vector(initializer_list<value_type> __il, const allocator_type& __a);
1938*cb14a3feSDimitry Andric
1939*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector& operator=(initializer_list<value_type> __il) {
1940*cb14a3feSDimitry Andric    assign(__il.begin(), __il.end());
1941*cb14a3feSDimitry Andric    return *this;
1942*cb14a3feSDimitry Andric  }
19430b57cec5SDimitry Andric
19440b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG
19450b57cec5SDimitry Andric
1946*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(vector&& __v)
194706c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
194881ad6265SDimitry Andric      noexcept;
194981ad6265SDimitry Andric#else
195081ad6265SDimitry Andric      _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
195181ad6265SDimitry Andric#endif
1952bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
1953*cb14a3feSDimitry Andric  vector(vector&& __v, const __type_identity_t<allocator_type>& __a);
1954*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector& operator=(vector&& __v)
195581ad6265SDimitry Andric      _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
195681ad6265SDimitry Andric
19575f757f3fSDimitry Andric  template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
1958*cb14a3feSDimitry Andric  void _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 assign(_InputIterator __first, _InputIterator __last);
19595f757f3fSDimitry Andric  template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
1960*cb14a3feSDimitry Andric  void _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 assign(_ForwardIterator __first, _ForwardIterator __last);
19610b57cec5SDimitry Andric
196206c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
196306c3fb27SDimitry Andric  template <_ContainerCompatibleRange<bool> _Range>
1964*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr void assign_range(_Range&& __range) {
196506c3fb27SDimitry Andric    if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
196606c3fb27SDimitry Andric      auto __n = static_cast<size_type>(ranges::distance(__range));
196706c3fb27SDimitry Andric      __assign_with_size(ranges::begin(__range), ranges::end(__range), __n);
196806c3fb27SDimitry Andric
196906c3fb27SDimitry Andric    } else {
197006c3fb27SDimitry Andric      __assign_with_sentinel(ranges::begin(__range), ranges::end(__range));
197106c3fb27SDimitry Andric    }
197206c3fb27SDimitry Andric  }
197306c3fb27SDimitry Andric#endif
197406c3fb27SDimitry Andric
1975bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void assign(size_type __n, const value_type& __x);
19760b57cec5SDimitry Andric
19770b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
1978*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void assign(initializer_list<value_type> __il) {
1979*cb14a3feSDimitry Andric    assign(__il.begin(), __il.end());
1980*cb14a3feSDimitry Andric  }
19810b57cec5SDimitry Andric#endif
19820b57cec5SDimitry Andric
1983*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator_type get_allocator() const _NOEXCEPT {
1984*cb14a3feSDimitry Andric    return allocator_type(this->__alloc());
1985*cb14a3feSDimitry Andric  }
19860b57cec5SDimitry Andric
1987bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type max_size() const _NOEXCEPT;
1988*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type capacity() const _NOEXCEPT {
1989*cb14a3feSDimitry Andric    return __internal_cap_to_external(__cap());
1990*cb14a3feSDimitry Andric  }
1991*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type size() const _NOEXCEPT { return __size_; }
1992*cb14a3feSDimitry Andric  _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool empty() const _NOEXCEPT {
1993*cb14a3feSDimitry Andric    return __size_ == 0;
1994*cb14a3feSDimitry Andric  }
1995bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void reserve(size_type __n);
1996bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void shrink_to_fit() _NOEXCEPT;
19970b57cec5SDimitry Andric
1998*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator begin() _NOEXCEPT { return __make_iter(0); }
1999*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator begin() const _NOEXCEPT { return __make_iter(0); }
2000*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator end() _NOEXCEPT { return __make_iter(__size_); }
2001*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator end() const _NOEXCEPT {
2002*cb14a3feSDimitry Andric    return __make_iter(__size_);
2003*cb14a3feSDimitry Andric  }
20040b57cec5SDimitry Andric
2005*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reverse_iterator rbegin() _NOEXCEPT {
2006*cb14a3feSDimitry Andric    return reverse_iterator(end());
2007*cb14a3feSDimitry Andric  }
2008*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator rbegin() const _NOEXCEPT {
2009*cb14a3feSDimitry Andric    return const_reverse_iterator(end());
2010*cb14a3feSDimitry Andric  }
2011*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reverse_iterator rend() _NOEXCEPT {
2012*cb14a3feSDimitry Andric    return reverse_iterator(begin());
2013*cb14a3feSDimitry Andric  }
2014*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator rend() const _NOEXCEPT {
2015*cb14a3feSDimitry Andric    return const_reverse_iterator(begin());
2016*cb14a3feSDimitry Andric  }
20170b57cec5SDimitry Andric
2018*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator cbegin() const _NOEXCEPT { return __make_iter(0); }
2019*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator cend() const _NOEXCEPT {
2020*cb14a3feSDimitry Andric    return __make_iter(__size_);
2021*cb14a3feSDimitry Andric  }
2022*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator crbegin() const _NOEXCEPT {
2023*cb14a3feSDimitry Andric    return rbegin();
2024*cb14a3feSDimitry Andric  }
2025*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
20260b57cec5SDimitry Andric
2027bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator[](size_type __n) { return __make_ref(__n); }
2028*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference operator[](size_type __n) const {
2029*cb14a3feSDimitry Andric    return __make_ref(__n);
2030*cb14a3feSDimitry Andric  }
2031bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reference at(size_type __n);
2032bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __n) const;
20330b57cec5SDimitry Andric
2034bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference front() { return __make_ref(0); }
2035bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference front() const { return __make_ref(0); }
2036bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference back() { return __make_ref(__size_ - 1); }
2037bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference back() const { return __make_ref(__size_ - 1); }
20380b57cec5SDimitry Andric
2039bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void push_back(const value_type& __x);
204006c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
20410b57cec5SDimitry Andric  template <class... _Args>
204206c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 17
2043bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference emplace_back(_Args&&... __args)
20440b57cec5SDimitry Andric#  else
2045bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void emplace_back(_Args&&... __args)
20460b57cec5SDimitry Andric#  endif
20470b57cec5SDimitry Andric  {
2048bdd1243dSDimitry Andric    push_back(value_type(std::forward<_Args>(__args)...));
204906c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 17
20500b57cec5SDimitry Andric    return this->back();
20510b57cec5SDimitry Andric#  endif
20520b57cec5SDimitry Andric  }
20530b57cec5SDimitry Andric#endif
20540b57cec5SDimitry Andric
205506c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
205606c3fb27SDimitry Andric  template <_ContainerCompatibleRange<bool> _Range>
2057*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr void append_range(_Range&& __range) {
205806c3fb27SDimitry Andric    insert_range(end(), std::forward<_Range>(__range));
205906c3fb27SDimitry Andric  }
206006c3fb27SDimitry Andric#endif
206106c3fb27SDimitry Andric
2062bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void pop_back() { --__size_; }
20630b57cec5SDimitry Andric
206406c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
20650b57cec5SDimitry Andric  template <class... _Args>
2066*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator emplace(const_iterator __position, _Args&&... __args) {
2067*cb14a3feSDimitry Andric    return insert(__position, value_type(std::forward<_Args>(__args)...));
2068*cb14a3feSDimitry Andric  }
20690b57cec5SDimitry Andric#endif
20700b57cec5SDimitry Andric
2071bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __position, const value_type& __x);
2072*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
2073*cb14a3feSDimitry Andric  insert(const_iterator __position, size_type __n, const value_type& __x);
20745f757f3fSDimitry Andric  template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
2075*cb14a3feSDimitry Andric  iterator _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
2076*cb14a3feSDimitry Andric  insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
20775f757f3fSDimitry Andric  template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
2078*cb14a3feSDimitry Andric  iterator _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
2079*cb14a3feSDimitry Andric  insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
20800b57cec5SDimitry Andric
208106c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
208206c3fb27SDimitry Andric  template <_ContainerCompatibleRange<bool> _Range>
2083*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr iterator insert_range(const_iterator __position, _Range&& __range) {
208406c3fb27SDimitry Andric    if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
208506c3fb27SDimitry Andric      auto __n = static_cast<size_type>(ranges::distance(__range));
208606c3fb27SDimitry Andric      return __insert_with_size(__position, ranges::begin(__range), ranges::end(__range), __n);
208706c3fb27SDimitry Andric
208806c3fb27SDimitry Andric    } else {
208906c3fb27SDimitry Andric      return __insert_with_sentinel(__position, ranges::begin(__range), ranges::end(__range));
209006c3fb27SDimitry Andric    }
209106c3fb27SDimitry Andric  }
209206c3fb27SDimitry Andric#endif
209306c3fb27SDimitry Andric
20940b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
2095*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator
2096*cb14a3feSDimitry Andric  insert(const_iterator __position, initializer_list<value_type> __il) {
2097*cb14a3feSDimitry Andric    return insert(__position, __il.begin(), __il.end());
2098*cb14a3feSDimitry Andric  }
20990b57cec5SDimitry Andric#endif
21000b57cec5SDimitry Andric
2101bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __position);
2102bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __first, const_iterator __last);
21030b57cec5SDimitry Andric
2104*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void clear() _NOEXCEPT { __size_ = 0; }
21050b57cec5SDimitry Andric
210606c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(vector&)
21070b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
21080b57cec5SDimitry Andric      _NOEXCEPT;
21090b57cec5SDimitry Andric#else
2110*cb14a3feSDimitry Andric      _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value);
21110b57cec5SDimitry Andric#endif
2112*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void swap(reference __x, reference __y) _NOEXCEPT {
2113*cb14a3feSDimitry Andric    std::swap(__x, __y);
2114*cb14a3feSDimitry Andric  }
21150b57cec5SDimitry Andric
2116bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void resize(size_type __sz, value_type __x = false);
2117bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void flip() _NOEXCEPT;
21180b57cec5SDimitry Andric
2119bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __invariants() const;
21200b57cec5SDimitry Andric
21210b57cec5SDimitry Andricprivate:
2122*cb14a3feSDimitry Andric  _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_length_error() const { std::__throw_length_error("vector"); }
2123d56accc7SDimitry Andric
2124*cb14a3feSDimitry Andric  _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range() const { std::__throw_out_of_range("vector"); }
2125d56accc7SDimitry Andric
212606c3fb27SDimitry Andric  template <class _InputIterator, class _Sentinel>
2127*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
2128*cb14a3feSDimitry Andric  __init_with_size(_InputIterator __first, _Sentinel __last, size_type __n) {
212906c3fb27SDimitry Andric    auto __guard = std::__make_exception_guard(__destroy_vector(*this));
213006c3fb27SDimitry Andric
213106c3fb27SDimitry Andric    if (__n > 0) {
213206c3fb27SDimitry Andric      __vallocate(__n);
213306c3fb27SDimitry Andric      __construct_at_end(std::move(__first), std::move(__last), __n);
213406c3fb27SDimitry Andric    }
213506c3fb27SDimitry Andric
213606c3fb27SDimitry Andric    __guard.__complete();
213706c3fb27SDimitry Andric  }
213806c3fb27SDimitry Andric
213906c3fb27SDimitry Andric  template <class _InputIterator, class _Sentinel>
2140*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
2141*cb14a3feSDimitry Andric  __init_with_sentinel(_InputIterator __first, _Sentinel __last) {
214206c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
214306c3fb27SDimitry Andric    try {
214406c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
214506c3fb27SDimitry Andric      for (; __first != __last; ++__first)
214606c3fb27SDimitry Andric        push_back(*__first);
214706c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
214806c3fb27SDimitry Andric    } catch (...) {
214906c3fb27SDimitry Andric      if (__begin_ != nullptr)
215006c3fb27SDimitry Andric        __storage_traits::deallocate(__alloc(), __begin_, __cap());
215106c3fb27SDimitry Andric      throw;
215206c3fb27SDimitry Andric    }
215306c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
215406c3fb27SDimitry Andric  }
215506c3fb27SDimitry Andric
215606c3fb27SDimitry Andric  template <class _Iterator, class _Sentinel>
2157*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __assign_with_sentinel(_Iterator __first, _Sentinel __last);
215806c3fb27SDimitry Andric
215906c3fb27SDimitry Andric  template <class _ForwardIterator, class _Sentinel>
2160*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
2161*cb14a3feSDimitry Andric  __assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __ns);
216206c3fb27SDimitry Andric
216306c3fb27SDimitry Andric  template <class _InputIterator, class _Sentinel>
2164*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
2165*cb14a3feSDimitry Andric  __insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last);
216606c3fb27SDimitry Andric
216706c3fb27SDimitry Andric  template <class _Iterator, class _Sentinel>
2168*cb14a3feSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
2169*cb14a3feSDimitry Andric  __insert_with_size(const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n);
217006c3fb27SDimitry Andric
217181ad6265SDimitry Andric  //  Allocate space for __n objects
217281ad6265SDimitry Andric  //  throws length_error if __n > max_size()
217381ad6265SDimitry Andric  //  throws (probably bad_alloc) if memory run out
217481ad6265SDimitry Andric  //  Precondition:  __begin_ == __end_ == __cap() == 0
217581ad6265SDimitry Andric  //  Precondition:  __n > 0
217681ad6265SDimitry Andric  //  Postcondition:  capacity() >= __n
217781ad6265SDimitry Andric  //  Postcondition:  size() == 0
2178bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __vallocate(size_type __n) {
217981ad6265SDimitry Andric    if (__n > max_size())
218081ad6265SDimitry Andric      __throw_length_error();
218181ad6265SDimitry Andric    auto __allocation = std::__allocate_at_least(__alloc(), __external_cap_to_internal(__n));
218281ad6265SDimitry Andric    __begin_          = __allocation.ptr;
218381ad6265SDimitry Andric    __size_           = 0;
218481ad6265SDimitry Andric    __cap()           = __allocation.count;
218561cfbce3SDimitry Andric    if (__libcpp_is_constant_evaluated()) {
218661cfbce3SDimitry Andric      for (size_type __i = 0; __i != __cap(); ++__i)
218761cfbce3SDimitry Andric        std::__construct_at(std::__to_address(__begin_) + __i);
218861cfbce3SDimitry Andric    }
218981ad6265SDimitry Andric  }
219081ad6265SDimitry Andric
2191bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __vdeallocate() _NOEXCEPT;
2192*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static size_type __align_it(size_type __new_size) _NOEXCEPT {
2193*cb14a3feSDimitry Andric    return (__new_size + (__bits_per_word - 1)) & ~((size_type)__bits_per_word - 1);
2194*cb14a3feSDimitry Andric  }
2195bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type __recommend(size_type __new_size) const;
2196bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __construct_at_end(size_type __n, bool __x);
219706c3fb27SDimitry Andric  template <class _InputIterator, class _Sentinel>
2198*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
2199*cb14a3feSDimitry Andric  __construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n);
2200bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __append(size_type __n, const_reference __x);
2201*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference __make_ref(size_type __pos) _NOEXCEPT {
2202*cb14a3feSDimitry Andric    return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
220381ad6265SDimitry Andric  }
2204*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference __make_ref(size_type __pos) const _NOEXCEPT {
2205*cb14a3feSDimitry Andric    return __bit_const_reference<vector>(
2206*cb14a3feSDimitry Andric        __begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
2207*cb14a3feSDimitry Andric  }
2208*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator __make_iter(size_type __pos) _NOEXCEPT {
2209*cb14a3feSDimitry Andric    return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));
2210*cb14a3feSDimitry Andric  }
2211*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator __make_iter(size_type __pos) const _NOEXCEPT {
2212*cb14a3feSDimitry Andric    return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));
2213*cb14a3feSDimitry Andric  }
2214*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT {
2215*cb14a3feSDimitry Andric    return begin() + (__p - cbegin());
2216*cb14a3feSDimitry Andric  }
22170b57cec5SDimitry Andric
2218*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __copy_assign_alloc(const vector& __v) {
2219*cb14a3feSDimitry Andric    __copy_assign_alloc(
2220*cb14a3feSDimitry Andric        __v, integral_constant<bool, __storage_traits::propagate_on_container_copy_assignment::value>());
2221*cb14a3feSDimitry Andric  }
2222*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __copy_assign_alloc(const vector& __c, true_type) {
22230b57cec5SDimitry Andric    if (__alloc() != __c.__alloc())
22240b57cec5SDimitry Andric      __vdeallocate();
22250b57cec5SDimitry Andric    __alloc() = __c.__alloc();
22260b57cec5SDimitry Andric  }
22270b57cec5SDimitry Andric
2228*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __copy_assign_alloc(const vector&, false_type) {}
22290b57cec5SDimitry Andric
2230bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign(vector& __c, false_type);
2231bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign(vector& __c, true_type)
22320b57cec5SDimitry Andric      _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
2233*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign_alloc(vector& __c)
2234*cb14a3feSDimitry Andric      _NOEXCEPT_(!__storage_traits::propagate_on_container_move_assignment::value ||
2235*cb14a3feSDimitry Andric                 is_nothrow_move_assignable<allocator_type>::value) {
2236*cb14a3feSDimitry Andric    __move_assign_alloc(
2237*cb14a3feSDimitry Andric        __c, integral_constant<bool, __storage_traits::propagate_on_container_move_assignment::value>());
2238*cb14a3feSDimitry Andric  }
2239*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign_alloc(vector& __c, true_type)
2240*cb14a3feSDimitry Andric      _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) {
2241bdd1243dSDimitry Andric    __alloc() = std::move(__c.__alloc());
22420b57cec5SDimitry Andric  }
22430b57cec5SDimitry Andric
2244*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign_alloc(vector&, false_type) _NOEXCEPT {}
22450b57cec5SDimitry Andric
2246bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t __hash_code() const _NOEXCEPT;
22470b57cec5SDimitry Andric
22480b57cec5SDimitry Andric  friend class __bit_reference<vector>;
22490b57cec5SDimitry Andric  friend class __bit_const_reference<vector>;
22500b57cec5SDimitry Andric  friend class __bit_iterator<vector, false>;
22510b57cec5SDimitry Andric  friend class __bit_iterator<vector, true>;
22520b57cec5SDimitry Andric  friend struct __bit_array<vector>;
22530b57cec5SDimitry Andric  friend struct _LIBCPP_TEMPLATE_VIS hash<vector>;
22540b57cec5SDimitry Andric};
22550b57cec5SDimitry Andric
22560b57cec5SDimitry Andrictemplate <class _Allocator>
2257*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::__vdeallocate() _NOEXCEPT {
2258*cb14a3feSDimitry Andric  if (this->__begin_ != nullptr) {
22590b57cec5SDimitry Andric    __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
22600b57cec5SDimitry Andric    this->__begin_ = nullptr;
22610b57cec5SDimitry Andric    this->__size_ = this->__cap() = 0;
22620b57cec5SDimitry Andric  }
22630b57cec5SDimitry Andric}
22640b57cec5SDimitry Andric
22650b57cec5SDimitry Andrictemplate <class _Allocator>
2266*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::size_type
2267*cb14a3feSDimitry Andricvector<bool, _Allocator>::max_size() const _NOEXCEPT {
22680b57cec5SDimitry Andric  size_type __amax = __storage_traits::max_size(__alloc());
22690b57cec5SDimitry Andric  size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
22700b57cec5SDimitry Andric  if (__nmax / __bits_per_word <= __amax)
22710b57cec5SDimitry Andric    return __nmax;
22720b57cec5SDimitry Andric  return __internal_cap_to_external(__amax);
22730b57cec5SDimitry Andric}
22740b57cec5SDimitry Andric
22750b57cec5SDimitry Andric//  Precondition:  __new_size > capacity()
22760b57cec5SDimitry Andrictemplate <class _Allocator>
2277*cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::size_type
2278*cb14a3feSDimitry Andricvector<bool, _Allocator>::__recommend(size_type __new_size) const {
22790b57cec5SDimitry Andric  const size_type __ms = max_size();
22800b57cec5SDimitry Andric  if (__new_size > __ms)
22810b57cec5SDimitry Andric    this->__throw_length_error();
22820b57cec5SDimitry Andric  const size_type __cap = capacity();
22830b57cec5SDimitry Andric  if (__cap >= __ms / 2)
22840b57cec5SDimitry Andric    return __ms;
2285bdd1243dSDimitry Andric  return std::max(2 * __cap, __align_it(__new_size));
22860b57cec5SDimitry Andric}
22870b57cec5SDimitry Andric
22880b57cec5SDimitry Andric//  Default constructs __n objects starting at __end_
22890b57cec5SDimitry Andric//  Precondition:  __n > 0
22900b57cec5SDimitry Andric//  Precondition:  size() + __n <= capacity()
22910b57cec5SDimitry Andric//  Postcondition:  size() == size() + __n
22920b57cec5SDimitry Andrictemplate <class _Allocator>
2293*cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
2294*cb14a3feSDimitry Andricvector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x) {
22950b57cec5SDimitry Andric  size_type __old_size = this->__size_;
22960b57cec5SDimitry Andric  this->__size_ += __n;
2297*cb14a3feSDimitry Andric  if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) {
22980b57cec5SDimitry Andric    if (this->__size_ <= __bits_per_word)
22990b57cec5SDimitry Andric      this->__begin_[0] = __storage_type(0);
23000b57cec5SDimitry Andric    else
23010b57cec5SDimitry Andric      this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
23020b57cec5SDimitry Andric  }
2303bdd1243dSDimitry Andric  std::fill_n(__make_iter(__old_size), __n, __x);
23040b57cec5SDimitry Andric}
23050b57cec5SDimitry Andric
23060b57cec5SDimitry Andrictemplate <class _Allocator>
230706c3fb27SDimitry Andrictemplate <class _InputIterator, class _Sentinel>
2308*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void
2309*cb14a3feSDimitry Andricvector<bool, _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) {
23100b57cec5SDimitry Andric  size_type __old_size = this->__size_;
231106c3fb27SDimitry Andric  this->__size_ += __n;
2312*cb14a3feSDimitry Andric  if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) {
23130b57cec5SDimitry Andric    if (this->__size_ <= __bits_per_word)
23140b57cec5SDimitry Andric      this->__begin_[0] = __storage_type(0);
23150b57cec5SDimitry Andric    else
23160b57cec5SDimitry Andric      this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
23170b57cec5SDimitry Andric  }
231806c3fb27SDimitry Andric  std::__copy<_ClassicAlgPolicy>(__first, __last, __make_iter(__old_size));
23190b57cec5SDimitry Andric}
23200b57cec5SDimitry Andric
23210b57cec5SDimitry Andrictemplate <class _Allocator>
2322*cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector()
23230b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
2324*cb14a3feSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) {}
23250b57cec5SDimitry Andric
23260b57cec5SDimitry Andrictemplate <class _Allocator>
2327*cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(const allocator_type& __a)
23280b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
23290b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
23300b57cec5SDimitry Andric#else
23310b57cec5SDimitry Andric        _NOEXCEPT
23320b57cec5SDimitry Andric#endif
2333*cb14a3feSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) {
23340b57cec5SDimitry Andric}
23350b57cec5SDimitry Andric
23360b57cec5SDimitry Andrictemplate <class _Allocator>
2337*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(size_type __n)
2338*cb14a3feSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) {
2339*cb14a3feSDimitry Andric  if (__n > 0) {
23400b57cec5SDimitry Andric    __vallocate(__n);
23410b57cec5SDimitry Andric    __construct_at_end(__n, false);
23420b57cec5SDimitry Andric  }
23430b57cec5SDimitry Andric}
23440b57cec5SDimitry Andric
234506c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
23460b57cec5SDimitry Andrictemplate <class _Allocator>
2347*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
2348*cb14a3feSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) {
2349*cb14a3feSDimitry Andric  if (__n > 0) {
23500b57cec5SDimitry Andric    __vallocate(__n);
23510b57cec5SDimitry Andric    __construct_at_end(__n, false);
23520b57cec5SDimitry Andric  }
23530b57cec5SDimitry Andric}
23540b57cec5SDimitry Andric#endif
23550b57cec5SDimitry Andric
23560b57cec5SDimitry Andrictemplate <class _Allocator>
2357*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
2358*cb14a3feSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) {
2359*cb14a3feSDimitry Andric  if (__n > 0) {
23600b57cec5SDimitry Andric    __vallocate(__n);
23610b57cec5SDimitry Andric    __construct_at_end(__n, __x);
23620b57cec5SDimitry Andric  }
23630b57cec5SDimitry Andric}
23640b57cec5SDimitry Andric
23650b57cec5SDimitry Andrictemplate <class _Allocator>
2366bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
23670b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
2368*cb14a3feSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) {
2369*cb14a3feSDimitry Andric  if (__n > 0) {
23700b57cec5SDimitry Andric    __vallocate(__n);
23710b57cec5SDimitry Andric    __construct_at_end(__n, __x);
23720b57cec5SDimitry Andric  }
23730b57cec5SDimitry Andric}
23740b57cec5SDimitry Andric
23750b57cec5SDimitry Andrictemplate <class _Allocator>
23765f757f3fSDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
2377*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last)
2378*cb14a3feSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) {
237906c3fb27SDimitry Andric  __init_with_sentinel(__first, __last);
23800b57cec5SDimitry Andric}
23810b57cec5SDimitry Andric
23820b57cec5SDimitry Andrictemplate <class _Allocator>
23835f757f3fSDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
2384bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
23855f757f3fSDimitry Andricvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a)
2386*cb14a3feSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) {
238706c3fb27SDimitry Andric  __init_with_sentinel(__first, __last);
23880b57cec5SDimitry Andric}
23890b57cec5SDimitry Andric
23900b57cec5SDimitry Andrictemplate <class _Allocator>
23915f757f3fSDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
2392*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last)
2393*cb14a3feSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) {
239406c3fb27SDimitry Andric  auto __n = static_cast<size_type>(std::distance(__first, __last));
239506c3fb27SDimitry Andric  __init_with_size(__first, __last, __n);
23960b57cec5SDimitry Andric}
23970b57cec5SDimitry Andric
23980b57cec5SDimitry Andrictemplate <class _Allocator>
23995f757f3fSDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
2400bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
24015f757f3fSDimitry Andricvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a)
2402*cb14a3feSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) {
240306c3fb27SDimitry Andric  auto __n = static_cast<size_type>(std::distance(__first, __last));
240406c3fb27SDimitry Andric  __init_with_size(__first, __last, __n);
24050b57cec5SDimitry Andric}
24060b57cec5SDimitry Andric
24070b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
24080b57cec5SDimitry Andric
24090b57cec5SDimitry Andrictemplate <class _Allocator>
2410*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
2411*cb14a3feSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) {
24120b57cec5SDimitry Andric  size_type __n = static_cast<size_type>(__il.size());
2413*cb14a3feSDimitry Andric  if (__n > 0) {
24140b57cec5SDimitry Andric    __vallocate(__n);
241506c3fb27SDimitry Andric    __construct_at_end(__il.begin(), __il.end(), __n);
24160b57cec5SDimitry Andric  }
24170b57cec5SDimitry Andric}
24180b57cec5SDimitry Andric
24190b57cec5SDimitry Andrictemplate <class _Allocator>
2420bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
24210b57cec5SDimitry Andricvector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
2422*cb14a3feSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) {
24230b57cec5SDimitry Andric  size_type __n = static_cast<size_type>(__il.size());
2424*cb14a3feSDimitry Andric  if (__n > 0) {
24250b57cec5SDimitry Andric    __vallocate(__n);
242606c3fb27SDimitry Andric    __construct_at_end(__il.begin(), __il.end(), __n);
24270b57cec5SDimitry Andric  }
24280b57cec5SDimitry Andric}
24290b57cec5SDimitry Andric
24300b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
24310b57cec5SDimitry Andric
24320b57cec5SDimitry Andrictemplate <class _Allocator>
2433*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(const vector& __v)
24340b57cec5SDimitry Andric    : __begin_(nullptr),
24350b57cec5SDimitry Andric      __size_(0),
2436*cb14a3feSDimitry Andric      __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc())) {
2437*cb14a3feSDimitry Andric  if (__v.size() > 0) {
24380b57cec5SDimitry Andric    __vallocate(__v.size());
243906c3fb27SDimitry Andric    __construct_at_end(__v.begin(), __v.end(), __v.size());
24400b57cec5SDimitry Andric  }
24410b57cec5SDimitry Andric}
24420b57cec5SDimitry Andric
24430b57cec5SDimitry Andrictemplate <class _Allocator>
2444*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
2445*cb14a3feSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, __a) {
2446*cb14a3feSDimitry Andric  if (__v.size() > 0) {
24470b57cec5SDimitry Andric    __vallocate(__v.size());
244806c3fb27SDimitry Andric    __construct_at_end(__v.begin(), __v.end(), __v.size());
24490b57cec5SDimitry Andric  }
24500b57cec5SDimitry Andric}
24510b57cec5SDimitry Andric
24520b57cec5SDimitry Andrictemplate <class _Allocator>
2453*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>& vector<bool, _Allocator>::operator=(const vector& __v) {
2454*cb14a3feSDimitry Andric  if (this != std::addressof(__v)) {
24550b57cec5SDimitry Andric    __copy_assign_alloc(__v);
2456*cb14a3feSDimitry Andric    if (__v.__size_) {
2457*cb14a3feSDimitry Andric      if (__v.__size_ > capacity()) {
24580b57cec5SDimitry Andric        __vdeallocate();
24590b57cec5SDimitry Andric        __vallocate(__v.__size_);
24600b57cec5SDimitry Andric      }
2461bdd1243dSDimitry Andric      std::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
24620b57cec5SDimitry Andric    }
24630b57cec5SDimitry Andric    __size_ = __v.__size_;
24640b57cec5SDimitry Andric  }
24650b57cec5SDimitry Andric  return *this;
24660b57cec5SDimitry Andric}
24670b57cec5SDimitry Andric
24680b57cec5SDimitry Andrictemplate <class _Allocator>
2469bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(vector&& __v)
247006c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
24710b57cec5SDimitry Andric    _NOEXCEPT
24720b57cec5SDimitry Andric#else
24730b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
24740b57cec5SDimitry Andric#endif
24750b57cec5SDimitry Andric    : __begin_(__v.__begin_),
24760b57cec5SDimitry Andric      __size_(__v.__size_),
2477bdd1243dSDimitry Andric      __cap_alloc_(std::move(__v.__cap_alloc_)) {
24780b57cec5SDimitry Andric  __v.__begin_ = nullptr;
24790b57cec5SDimitry Andric  __v.__size_  = 0;
24800b57cec5SDimitry Andric  __v.__cap()  = 0;
24810b57cec5SDimitry Andric}
24820b57cec5SDimitry Andric
24830b57cec5SDimitry Andrictemplate <class _Allocator>
2484bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
248581ad6265SDimitry Andricvector<bool, _Allocator>::vector(vector&& __v, const __type_identity_t<allocator_type>& __a)
2486*cb14a3feSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, __a) {
2487*cb14a3feSDimitry Andric  if (__a == allocator_type(__v.__alloc())) {
24880b57cec5SDimitry Andric    this->__begin_ = __v.__begin_;
24890b57cec5SDimitry Andric    this->__size_  = __v.__size_;
24900b57cec5SDimitry Andric    this->__cap()  = __v.__cap();
24910b57cec5SDimitry Andric    __v.__begin_   = nullptr;
24920b57cec5SDimitry Andric    __v.__cap() = __v.__size_ = 0;
2493*cb14a3feSDimitry Andric  } else if (__v.size() > 0) {
24940b57cec5SDimitry Andric    __vallocate(__v.size());
249506c3fb27SDimitry Andric    __construct_at_end(__v.begin(), __v.end(), __v.size());
24960b57cec5SDimitry Andric  }
24970b57cec5SDimitry Andric}
24980b57cec5SDimitry Andric
24990b57cec5SDimitry Andrictemplate <class _Allocator>
2500*cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>&
25010b57cec5SDimitry Andricvector<bool, _Allocator>::operator=(vector&& __v)
2502*cb14a3feSDimitry Andric    _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) {
2503*cb14a3feSDimitry Andric  __move_assign(__v, integral_constant<bool, __storage_traits::propagate_on_container_move_assignment::value>());
25040b57cec5SDimitry Andric  return *this;
25050b57cec5SDimitry Andric}
25060b57cec5SDimitry Andric
25070b57cec5SDimitry Andrictemplate <class _Allocator>
2508*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::__move_assign(vector& __c, false_type) {
25090b57cec5SDimitry Andric  if (__alloc() != __c.__alloc())
25100b57cec5SDimitry Andric    assign(__c.begin(), __c.end());
25110b57cec5SDimitry Andric  else
25120b57cec5SDimitry Andric    __move_assign(__c, true_type());
25130b57cec5SDimitry Andric}
25140b57cec5SDimitry Andric
25150b57cec5SDimitry Andrictemplate <class _Allocator>
2516*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
2517*cb14a3feSDimitry Andric    _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) {
25180b57cec5SDimitry Andric  __vdeallocate();
25190b57cec5SDimitry Andric  __move_assign_alloc(__c);
25200b57cec5SDimitry Andric  this->__begin_ = __c.__begin_;
25210b57cec5SDimitry Andric  this->__size_  = __c.__size_;
25220b57cec5SDimitry Andric  this->__cap()  = __c.__cap();
25230b57cec5SDimitry Andric  __c.__begin_   = nullptr;
25240b57cec5SDimitry Andric  __c.__cap() = __c.__size_ = 0;
25250b57cec5SDimitry Andric}
25260b57cec5SDimitry Andric
25270b57cec5SDimitry Andrictemplate <class _Allocator>
2528*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::assign(size_type __n, const value_type& __x) {
25290b57cec5SDimitry Andric  __size_ = 0;
2530*cb14a3feSDimitry Andric  if (__n > 0) {
25310b57cec5SDimitry Andric    size_type __c = capacity();
25320b57cec5SDimitry Andric    if (__n <= __c)
25330b57cec5SDimitry Andric      __size_ = __n;
2534*cb14a3feSDimitry Andric    else {
2535349cc55cSDimitry Andric      vector __v(get_allocator());
25360b57cec5SDimitry Andric      __v.reserve(__recommend(__n));
25370b57cec5SDimitry Andric      __v.__size_ = __n;
25380b57cec5SDimitry Andric      swap(__v);
25390b57cec5SDimitry Andric    }
2540bdd1243dSDimitry Andric    std::fill_n(begin(), __n, __x);
25410b57cec5SDimitry Andric  }
25420b57cec5SDimitry Andric}
25430b57cec5SDimitry Andric
25440b57cec5SDimitry Andrictemplate <class _Allocator>
25455f757f3fSDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
2546*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last) {
254706c3fb27SDimitry Andric  __assign_with_sentinel(__first, __last);
254806c3fb27SDimitry Andric}
254906c3fb27SDimitry Andric
255006c3fb27SDimitry Andrictemplate <class _Allocator>
255106c3fb27SDimitry Andrictemplate <class _Iterator, class _Sentinel>
2552*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
2553*cb14a3feSDimitry Andricvector<bool, _Allocator>::__assign_with_sentinel(_Iterator __first, _Sentinel __last) {
25540b57cec5SDimitry Andric  clear();
25550b57cec5SDimitry Andric  for (; __first != __last; ++__first)
25560b57cec5SDimitry Andric    push_back(*__first);
25570b57cec5SDimitry Andric}
25580b57cec5SDimitry Andric
25590b57cec5SDimitry Andrictemplate <class _Allocator>
25605f757f3fSDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
2561*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) {
256206c3fb27SDimitry Andric  __assign_with_size(__first, __last, std::distance(__first, __last));
256306c3fb27SDimitry Andric}
256406c3fb27SDimitry Andric
256506c3fb27SDimitry Andrictemplate <class _Allocator>
256606c3fb27SDimitry Andrictemplate <class _ForwardIterator, class _Sentinel>
2567*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
2568*cb14a3feSDimitry Andricvector<bool, _Allocator>::__assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __ns) {
256906c3fb27SDimitry Andric  _LIBCPP_ASSERT_VALID_INPUT_RANGE(__ns >= 0, "invalid range specified");
257006c3fb27SDimitry Andric
25710b57cec5SDimitry Andric  clear();
257206c3fb27SDimitry Andric
25730b57cec5SDimitry Andric  const size_t __n = static_cast<size_type>(__ns);
2574*cb14a3feSDimitry Andric  if (__n) {
2575*cb14a3feSDimitry Andric    if (__n > capacity()) {
25760b57cec5SDimitry Andric      __vdeallocate();
25770b57cec5SDimitry Andric      __vallocate(__n);
25780b57cec5SDimitry Andric    }
257906c3fb27SDimitry Andric    __construct_at_end(__first, __last, __n);
25800b57cec5SDimitry Andric  }
25810b57cec5SDimitry Andric}
25820b57cec5SDimitry Andric
25830b57cec5SDimitry Andrictemplate <class _Allocator>
2584*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::reserve(size_type __n) {
2585*cb14a3feSDimitry Andric  if (__n > capacity()) {
2586349cc55cSDimitry Andric    if (__n > max_size())
2587349cc55cSDimitry Andric      this->__throw_length_error();
2588349cc55cSDimitry Andric    vector __v(this->get_allocator());
25890b57cec5SDimitry Andric    __v.__vallocate(__n);
259006c3fb27SDimitry Andric    __v.__construct_at_end(this->begin(), this->end(), this->size());
25910b57cec5SDimitry Andric    swap(__v);
25920b57cec5SDimitry Andric  }
25930b57cec5SDimitry Andric}
25940b57cec5SDimitry Andric
25950b57cec5SDimitry Andrictemplate <class _Allocator>
2596*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT {
2597*cb14a3feSDimitry Andric  if (__external_cap_to_internal(size()) > __cap()) {
259806c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2599*cb14a3feSDimitry Andric    try {
260006c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
26010b57cec5SDimitry Andric      vector(*this, allocator_type(__alloc())).swap(*this);
260206c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2603*cb14a3feSDimitry Andric    } catch (...) {
26040b57cec5SDimitry Andric    }
260506c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
26060b57cec5SDimitry Andric  }
26070b57cec5SDimitry Andric}
26080b57cec5SDimitry Andric
26090b57cec5SDimitry Andrictemplate <class _Allocator>
2610*cb14a3feSDimitry Andrictypename vector<bool, _Allocator>::reference vector<bool, _Allocator>::at(size_type __n) {
26110b57cec5SDimitry Andric  if (__n >= size())
26120b57cec5SDimitry Andric    this->__throw_out_of_range();
26130b57cec5SDimitry Andric  return (*this)[__n];
26140b57cec5SDimitry Andric}
26150b57cec5SDimitry Andric
26160b57cec5SDimitry Andrictemplate <class _Allocator>
2617*cb14a3feSDimitry Andrictypename vector<bool, _Allocator>::const_reference vector<bool, _Allocator>::at(size_type __n) const {
26180b57cec5SDimitry Andric  if (__n >= size())
26190b57cec5SDimitry Andric    this->__throw_out_of_range();
26200b57cec5SDimitry Andric  return (*this)[__n];
26210b57cec5SDimitry Andric}
26220b57cec5SDimitry Andric
26230b57cec5SDimitry Andrictemplate <class _Allocator>
2624*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::push_back(const value_type& __x) {
26250b57cec5SDimitry Andric  if (this->__size_ == this->capacity())
26260b57cec5SDimitry Andric    reserve(__recommend(this->__size_ + 1));
26270b57cec5SDimitry Andric  ++this->__size_;
26280b57cec5SDimitry Andric  back() = __x;
26290b57cec5SDimitry Andric}
26300b57cec5SDimitry Andric
26310b57cec5SDimitry Andrictemplate <class _Allocator>
2632bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
2633*cb14a3feSDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x) {
26340b57cec5SDimitry Andric  iterator __r;
2635*cb14a3feSDimitry Andric  if (size() < capacity()) {
26360b57cec5SDimitry Andric    const_iterator __old_end = end();
26370b57cec5SDimitry Andric    ++__size_;
2638bdd1243dSDimitry Andric    std::copy_backward(__position, __old_end, end());
26390b57cec5SDimitry Andric    __r = __const_iterator_cast(__position);
2640*cb14a3feSDimitry Andric  } else {
2641349cc55cSDimitry Andric    vector __v(get_allocator());
26420b57cec5SDimitry Andric    __v.reserve(__recommend(__size_ + 1));
26430b57cec5SDimitry Andric    __v.__size_ = __size_ + 1;
2644bdd1243dSDimitry Andric    __r         = std::copy(cbegin(), __position, __v.begin());
2645bdd1243dSDimitry Andric    std::copy_backward(__position, cend(), __v.end());
26460b57cec5SDimitry Andric    swap(__v);
26470b57cec5SDimitry Andric  }
26480b57cec5SDimitry Andric  *__r = __x;
26490b57cec5SDimitry Andric  return __r;
26500b57cec5SDimitry Andric}
26510b57cec5SDimitry Andric
26520b57cec5SDimitry Andrictemplate <class _Allocator>
2653bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
2654*cb14a3feSDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x) {
26550b57cec5SDimitry Andric  iterator __r;
26560b57cec5SDimitry Andric  size_type __c = capacity();
2657*cb14a3feSDimitry Andric  if (__n <= __c && size() <= __c - __n) {
26580b57cec5SDimitry Andric    const_iterator __old_end = end();
26590b57cec5SDimitry Andric    __size_ += __n;
2660bdd1243dSDimitry Andric    std::copy_backward(__position, __old_end, end());
26610b57cec5SDimitry Andric    __r = __const_iterator_cast(__position);
2662*cb14a3feSDimitry Andric  } else {
2663349cc55cSDimitry Andric    vector __v(get_allocator());
26640b57cec5SDimitry Andric    __v.reserve(__recommend(__size_ + __n));
26650b57cec5SDimitry Andric    __v.__size_ = __size_ + __n;
2666bdd1243dSDimitry Andric    __r         = std::copy(cbegin(), __position, __v.begin());
2667bdd1243dSDimitry Andric    std::copy_backward(__position, cend(), __v.end());
26680b57cec5SDimitry Andric    swap(__v);
26690b57cec5SDimitry Andric  }
2670bdd1243dSDimitry Andric  std::fill_n(__r, __n, __x);
26710b57cec5SDimitry Andric  return __r;
26720b57cec5SDimitry Andric}
26730b57cec5SDimitry Andric
26740b57cec5SDimitry Andrictemplate <class _Allocator>
26755f757f3fSDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
2676*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
2677*cb14a3feSDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) {
267806c3fb27SDimitry Andric  return __insert_with_sentinel(__position, __first, __last);
267906c3fb27SDimitry Andric}
268006c3fb27SDimitry Andric
268106c3fb27SDimitry Andrictemplate <class _Allocator>
268206c3fb27SDimitry Andrictemplate <class _InputIterator, class _Sentinel>
2683*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector<bool, _Allocator>::iterator
268406c3fb27SDimitry Andricvector<bool, _Allocator>::__insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last) {
26850b57cec5SDimitry Andric  difference_type __off = __position - begin();
26860b57cec5SDimitry Andric  iterator __p          = __const_iterator_cast(__position);
26870b57cec5SDimitry Andric  iterator __old_end    = end();
2688*cb14a3feSDimitry Andric  for (; size() != capacity() && __first != __last; ++__first) {
26890b57cec5SDimitry Andric    ++this->__size_;
26900b57cec5SDimitry Andric    back() = *__first;
26910b57cec5SDimitry Andric  }
2692349cc55cSDimitry Andric  vector __v(get_allocator());
2693*cb14a3feSDimitry Andric  if (__first != __last) {
269406c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2695*cb14a3feSDimitry Andric    try {
269606c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
269706c3fb27SDimitry Andric      __v.__assign_with_sentinel(std::move(__first), std::move(__last));
26980b57cec5SDimitry Andric      difference_type __old_size = static_cast<difference_type>(__old_end - begin());
26990b57cec5SDimitry Andric      difference_type __old_p    = __p - begin();
27000b57cec5SDimitry Andric      reserve(__recommend(size() + __v.size()));
27010b57cec5SDimitry Andric      __p       = begin() + __old_p;
27020b57cec5SDimitry Andric      __old_end = begin() + __old_size;
270306c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2704*cb14a3feSDimitry Andric    } catch (...) {
27050b57cec5SDimitry Andric      erase(__old_end, end());
27060b57cec5SDimitry Andric      throw;
27070b57cec5SDimitry Andric    }
270806c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
27090b57cec5SDimitry Andric  }
2710bdd1243dSDimitry Andric  __p = std::rotate(__p, __old_end, end());
27110b57cec5SDimitry Andric  insert(__p, __v.begin(), __v.end());
27120b57cec5SDimitry Andric  return begin() + __off;
27130b57cec5SDimitry Andric}
27140b57cec5SDimitry Andric
27150b57cec5SDimitry Andrictemplate <class _Allocator>
27165f757f3fSDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
2717*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
2718*cb14a3feSDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) {
271906c3fb27SDimitry Andric  return __insert_with_size(__position, __first, __last, std::distance(__first, __last));
272006c3fb27SDimitry Andric}
272106c3fb27SDimitry Andric
272206c3fb27SDimitry Andrictemplate <class _Allocator>
272306c3fb27SDimitry Andrictemplate <class _ForwardIterator, class _Sentinel>
2724*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector<bool, _Allocator>::iterator
2725*cb14a3feSDimitry Andricvector<bool, _Allocator>::__insert_with_size(
2726*cb14a3feSDimitry Andric    const_iterator __position, _ForwardIterator __first, _Sentinel __last, difference_type __n_signed) {
272706c3fb27SDimitry Andric  _LIBCPP_ASSERT_VALID_INPUT_RANGE(__n_signed >= 0, "invalid range specified");
27280b57cec5SDimitry Andric  const size_type __n = static_cast<size_type>(__n_signed);
27290b57cec5SDimitry Andric  iterator __r;
27300b57cec5SDimitry Andric  size_type __c = capacity();
2731*cb14a3feSDimitry Andric  if (__n <= __c && size() <= __c - __n) {
27320b57cec5SDimitry Andric    const_iterator __old_end = end();
27330b57cec5SDimitry Andric    __size_ += __n;
2734bdd1243dSDimitry Andric    std::copy_backward(__position, __old_end, end());
27350b57cec5SDimitry Andric    __r = __const_iterator_cast(__position);
2736*cb14a3feSDimitry Andric  } else {
2737349cc55cSDimitry Andric    vector __v(get_allocator());
27380b57cec5SDimitry Andric    __v.reserve(__recommend(__size_ + __n));
27390b57cec5SDimitry Andric    __v.__size_ = __size_ + __n;
2740bdd1243dSDimitry Andric    __r         = std::copy(cbegin(), __position, __v.begin());
2741bdd1243dSDimitry Andric    std::copy_backward(__position, cend(), __v.end());
27420b57cec5SDimitry Andric    swap(__v);
27430b57cec5SDimitry Andric  }
274406c3fb27SDimitry Andric  std::__copy<_ClassicAlgPolicy>(__first, __last, __r);
27450b57cec5SDimitry Andric  return __r;
27460b57cec5SDimitry Andric}
27470b57cec5SDimitry Andric
27480b57cec5SDimitry Andrictemplate <class _Allocator>
2749*cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
2750*cb14a3feSDimitry Andricvector<bool, _Allocator>::erase(const_iterator __position) {
27510b57cec5SDimitry Andric  iterator __r = __const_iterator_cast(__position);
2752bdd1243dSDimitry Andric  std::copy(__position + 1, this->cend(), __r);
27530b57cec5SDimitry Andric  --__size_;
27540b57cec5SDimitry Andric  return __r;
27550b57cec5SDimitry Andric}
27560b57cec5SDimitry Andric
27570b57cec5SDimitry Andrictemplate <class _Allocator>
2758*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
2759*cb14a3feSDimitry Andricvector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last) {
27600b57cec5SDimitry Andric  iterator __r        = __const_iterator_cast(__first);
27610b57cec5SDimitry Andric  difference_type __d = __last - __first;
2762bdd1243dSDimitry Andric  std::copy(__last, this->cend(), __r);
27630b57cec5SDimitry Andric  __size_ -= __d;
27640b57cec5SDimitry Andric  return __r;
27650b57cec5SDimitry Andric}
27660b57cec5SDimitry Andric
27670b57cec5SDimitry Andrictemplate <class _Allocator>
2768*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::swap(vector& __x)
27690b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
27700b57cec5SDimitry Andric    _NOEXCEPT
27710b57cec5SDimitry Andric#else
2772*cb14a3feSDimitry Andric    _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value)
27730b57cec5SDimitry Andric#endif
27740b57cec5SDimitry Andric{
2775bdd1243dSDimitry Andric  std::swap(this->__begin_, __x.__begin_);
2776bdd1243dSDimitry Andric  std::swap(this->__size_, __x.__size_);
2777bdd1243dSDimitry Andric  std::swap(this->__cap(), __x.__cap());
2778*cb14a3feSDimitry Andric  std::__swap_allocator(
2779*cb14a3feSDimitry Andric      this->__alloc(), __x.__alloc(), integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
27800b57cec5SDimitry Andric}
27810b57cec5SDimitry Andric
27820b57cec5SDimitry Andrictemplate <class _Allocator>
2783*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::resize(size_type __sz, value_type __x) {
27840b57cec5SDimitry Andric  size_type __cs = size();
2785*cb14a3feSDimitry Andric  if (__cs < __sz) {
27860b57cec5SDimitry Andric    iterator __r;
27870b57cec5SDimitry Andric    size_type __c = capacity();
27880b57cec5SDimitry Andric    size_type __n = __sz - __cs;
2789*cb14a3feSDimitry Andric    if (__n <= __c && __cs <= __c - __n) {
27900b57cec5SDimitry Andric      __r = end();
27910b57cec5SDimitry Andric      __size_ += __n;
2792*cb14a3feSDimitry Andric    } else {
2793349cc55cSDimitry Andric      vector __v(get_allocator());
27940b57cec5SDimitry Andric      __v.reserve(__recommend(__size_ + __n));
27950b57cec5SDimitry Andric      __v.__size_ = __size_ + __n;
2796bdd1243dSDimitry Andric      __r         = std::copy(cbegin(), cend(), __v.begin());
27970b57cec5SDimitry Andric      swap(__v);
27980b57cec5SDimitry Andric    }
2799bdd1243dSDimitry Andric    std::fill_n(__r, __n, __x);
2800*cb14a3feSDimitry Andric  } else
28010b57cec5SDimitry Andric    __size_ = __sz;
28020b57cec5SDimitry Andric}
28030b57cec5SDimitry Andric
28040b57cec5SDimitry Andrictemplate <class _Allocator>
2805*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::flip() _NOEXCEPT {
28060b57cec5SDimitry Andric  // do middle whole words
28070b57cec5SDimitry Andric  size_type __n         = __size_;
28080b57cec5SDimitry Andric  __storage_pointer __p = __begin_;
28090b57cec5SDimitry Andric  for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
28100b57cec5SDimitry Andric    *__p = ~*__p;
28110b57cec5SDimitry Andric  // do last partial word
2812*cb14a3feSDimitry Andric  if (__n > 0) {
28130b57cec5SDimitry Andric    __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
28140b57cec5SDimitry Andric    __storage_type __b = *__p & __m;
28150b57cec5SDimitry Andric    *__p &= ~__m;
28160b57cec5SDimitry Andric    *__p |= ~__b & __m;
28170b57cec5SDimitry Andric  }
28180b57cec5SDimitry Andric}
28190b57cec5SDimitry Andric
28200b57cec5SDimitry Andrictemplate <class _Allocator>
2821*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 bool vector<bool, _Allocator>::__invariants() const {
2822*cb14a3feSDimitry Andric  if (this->__begin_ == nullptr) {
28230b57cec5SDimitry Andric    if (this->__size_ != 0 || this->__cap() != 0)
28240b57cec5SDimitry Andric      return false;
2825*cb14a3feSDimitry Andric  } else {
28260b57cec5SDimitry Andric    if (this->__cap() == 0)
28270b57cec5SDimitry Andric      return false;
28280b57cec5SDimitry Andric    if (this->__size_ > this->capacity())
28290b57cec5SDimitry Andric      return false;
28300b57cec5SDimitry Andric  }
28310b57cec5SDimitry Andric  return true;
28320b57cec5SDimitry Andric}
28330b57cec5SDimitry Andric
28340b57cec5SDimitry Andrictemplate <class _Allocator>
2835*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 size_t vector<bool, _Allocator>::__hash_code() const _NOEXCEPT {
28360b57cec5SDimitry Andric  size_t __h = 0;
28370b57cec5SDimitry Andric  // do middle whole words
28380b57cec5SDimitry Andric  size_type __n         = __size_;
28390b57cec5SDimitry Andric  __storage_pointer __p = __begin_;
28400b57cec5SDimitry Andric  for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
28410b57cec5SDimitry Andric    __h ^= *__p;
28420b57cec5SDimitry Andric  // do last partial word
2843*cb14a3feSDimitry Andric  if (__n > 0) {
28440b57cec5SDimitry Andric    const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
28450b57cec5SDimitry Andric    __h ^= *__p & __m;
28460b57cec5SDimitry Andric  }
28470b57cec5SDimitry Andric  return __h;
28480b57cec5SDimitry Andric}
28490b57cec5SDimitry Andric
28500b57cec5SDimitry Andrictemplate <class _Allocator>
28510b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
2852*cb14a3feSDimitry Andric    : public __unary_function<vector<bool, _Allocator>, size_t> {
2853*cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t
2854*cb14a3feSDimitry Andric  operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT {
2855*cb14a3feSDimitry Andric    return __vec.__hash_code();
2856*cb14a3feSDimitry Andric  }
28570b57cec5SDimitry Andric};
28580b57cec5SDimitry Andric
28590b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
2860*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI bool
2861*cb14a3feSDimitry Andricoperator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
28620b57cec5SDimitry Andric  const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
2863bdd1243dSDimitry Andric  return __sz == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
28640b57cec5SDimitry Andric}
28650b57cec5SDimitry Andric
286606c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17
286706c3fb27SDimitry Andric
28680b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
2869*cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
28700b57cec5SDimitry Andric  return !(__x == __y);
28710b57cec5SDimitry Andric}
28720b57cec5SDimitry Andric
28730b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
2874*cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator<(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
2875bdd1243dSDimitry Andric  return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
28760b57cec5SDimitry Andric}
28770b57cec5SDimitry Andric
28780b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
2879*cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator>(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
28800b57cec5SDimitry Andric  return __y < __x;
28810b57cec5SDimitry Andric}
28820b57cec5SDimitry Andric
28830b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
2884*cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
28850b57cec5SDimitry Andric  return !(__x < __y);
28860b57cec5SDimitry Andric}
28870b57cec5SDimitry Andric
28880b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
2889*cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
28900b57cec5SDimitry Andric  return !(__y < __x);
28910b57cec5SDimitry Andric}
28920b57cec5SDimitry Andric
289306c3fb27SDimitry Andric#else // _LIBCPP_STD_VER <= 17
289406c3fb27SDimitry Andric
289506c3fb27SDimitry Andrictemplate <class _Tp, class _Allocator>
289606c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr __synth_three_way_result<_Tp>
289706c3fb27SDimitry Andricoperator<=>(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
289806c3fb27SDimitry Andric  return std::lexicographical_compare_three_way(
289906c3fb27SDimitry Andric      __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way<_Tp, _Tp>);
290006c3fb27SDimitry Andric}
290106c3fb27SDimitry Andric
290206c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER <= 17
290306c3fb27SDimitry Andric
29040b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
2905*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI void
2906*cb14a3feSDimitry Andricswap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
29070b57cec5SDimitry Andric  __x.swap(__y);
29080b57cec5SDimitry Andric}
29090b57cec5SDimitry Andric
291006c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
29110b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Up>
2912*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
29135ffd83dbSDimitry Andricerase(vector<_Tp, _Allocator>& __c, const _Up& __v) {
29145ffd83dbSDimitry Andric  auto __old_size = __c.size();
2915bdd1243dSDimitry Andric  __c.erase(std::remove(__c.begin(), __c.end(), __v), __c.end());
29165ffd83dbSDimitry Andric  return __old_size - __c.size();
29175ffd83dbSDimitry Andric}
29180b57cec5SDimitry Andric
29190b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Predicate>
2920*cb14a3feSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
29215ffd83dbSDimitry Andricerase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) {
29225ffd83dbSDimitry Andric  auto __old_size = __c.size();
2923bdd1243dSDimitry Andric  __c.erase(std::remove_if(__c.begin(), __c.end(), __pred), __c.end());
29245ffd83dbSDimitry Andric  return __old_size - __c.size();
29255ffd83dbSDimitry Andric}
292681ad6265SDimitry Andric
292781ad6265SDimitry Andrictemplate <>
2928bdd1243dSDimitry Andricinline constexpr bool __format::__enable_insertable<vector<char>> = true;
292981ad6265SDimitry Andric#  ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
293081ad6265SDimitry Andrictemplate <>
2931bdd1243dSDimitry Andricinline constexpr bool __format::__enable_insertable<vector<wchar_t>> = true;
29320b57cec5SDimitry Andric#  endif
29330b57cec5SDimitry Andric
293406c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20
293581ad6265SDimitry Andric
293606c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
293706c3fb27SDimitry Andrictemplate <class _Tp, class _CharT>
2938bdd1243dSDimitry Andric// Since is-vector-bool-reference is only used once it's inlined here.
2939bdd1243dSDimitry Andric  requires same_as<typename _Tp::__container, vector<bool, typename _Tp::__container::allocator_type>>
294006c3fb27SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS formatter<_Tp, _CharT> {
2941bdd1243dSDimitry Andricprivate:
294206c3fb27SDimitry Andric  formatter<bool, _CharT> __underlying_;
2943bdd1243dSDimitry Andric
2944bdd1243dSDimitry Andricpublic:
2945bdd1243dSDimitry Andric  template <class _ParseContext>
2946bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
2947bdd1243dSDimitry Andric    return __underlying_.parse(__ctx);
2948bdd1243dSDimitry Andric  }
2949bdd1243dSDimitry Andric
2950bdd1243dSDimitry Andric  template <class _FormatContext>
2951bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(const _Tp& __ref, _FormatContext& __ctx) const {
2952bdd1243dSDimitry Andric    return __underlying_.format(__ref, __ctx);
2953bdd1243dSDimitry Andric  }
2954bdd1243dSDimitry Andric};
295506c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 23
2956bdd1243dSDimitry Andric
29570b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
29580b57cec5SDimitry Andric
295906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
2960bdd1243dSDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
2961bdd1243dSDimitry Andricnamespace pmr {
2962bdd1243dSDimitry Andrictemplate <class _ValueT>
296306c3fb27SDimitry Andricusing vector _LIBCPP_AVAILABILITY_PMR = std::vector<_ValueT, polymorphic_allocator<_ValueT>>;
2964bdd1243dSDimitry Andric} // namespace pmr
2965bdd1243dSDimitry Andric_LIBCPP_END_NAMESPACE_STD
2966bdd1243dSDimitry Andric#endif
2967bdd1243dSDimitry Andric
29680b57cec5SDimitry Andric_LIBCPP_POP_MACROS
29690b57cec5SDimitry Andric
2970bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
2971bdd1243dSDimitry Andric#  include <algorithm>
2972bdd1243dSDimitry Andric#  include <atomic>
2973bdd1243dSDimitry Andric#  include <concepts>
297406c3fb27SDimitry Andric#  include <cstdlib>
297506c3fb27SDimitry Andric#  include <type_traits>
2976bdd1243dSDimitry Andric#  include <typeinfo>
2977bdd1243dSDimitry Andric#  include <utility>
2978bdd1243dSDimitry Andric#endif
2979bdd1243dSDimitry Andric
29800b57cec5SDimitry Andric#endif // _LIBCPP_VECTOR
2981