xref: /freebsd/contrib/llvm-project/libcxx/include/vector (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
10b57cec5SDimitry Andric// -*- C++ -*-
2349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
100b57cec5SDimitry Andric#ifndef _LIBCPP_VECTOR
110b57cec5SDimitry Andric#define _LIBCPP_VECTOR
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric/*
140b57cec5SDimitry Andric    vector synopsis
150b57cec5SDimitry Andric
160b57cec5SDimitry Andricnamespace std
170b57cec5SDimitry Andric{
180b57cec5SDimitry Andric
190b57cec5SDimitry Andrictemplate <class T, class Allocator = allocator<T> >
200b57cec5SDimitry Andricclass vector
210b57cec5SDimitry Andric{
220b57cec5SDimitry Andricpublic:
230b57cec5SDimitry Andric    typedef T                                        value_type;
240b57cec5SDimitry Andric    typedef Allocator                                allocator_type;
250b57cec5SDimitry Andric    typedef typename allocator_type::reference       reference;
260b57cec5SDimitry Andric    typedef typename allocator_type::const_reference const_reference;
270b57cec5SDimitry Andric    typedef implementation-defined                   iterator;
280b57cec5SDimitry Andric    typedef implementation-defined                   const_iterator;
290b57cec5SDimitry Andric    typedef typename allocator_type::size_type       size_type;
300b57cec5SDimitry Andric    typedef typename allocator_type::difference_type difference_type;
310b57cec5SDimitry Andric    typedef typename allocator_type::pointer         pointer;
320b57cec5SDimitry Andric    typedef typename allocator_type::const_pointer   const_pointer;
330b57cec5SDimitry Andric    typedef std::reverse_iterator<iterator>          reverse_iterator;
340b57cec5SDimitry Andric    typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
350b57cec5SDimitry Andric
360b57cec5SDimitry Andric    vector()
370b57cec5SDimitry Andric        noexcept(is_nothrow_default_constructible<allocator_type>::value);
380b57cec5SDimitry Andric    explicit vector(const allocator_type&);
390b57cec5SDimitry Andric    explicit vector(size_type n);
400b57cec5SDimitry Andric    explicit vector(size_type n, const allocator_type&); // C++14
410b57cec5SDimitry Andric    vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
420b57cec5SDimitry Andric    template <class InputIterator>
430b57cec5SDimitry Andric        vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
44*06c3fb27SDimitry Andric    template<container-compatible-range<T> R>
45*06c3fb27SDimitry Andric      constexpr vector(from_range_t, R&& rg, const Allocator& = Allocator()); // C++23
460b57cec5SDimitry Andric    vector(const vector& x);
470b57cec5SDimitry Andric    vector(vector&& x)
480b57cec5SDimitry Andric        noexcept(is_nothrow_move_constructible<allocator_type>::value);
490b57cec5SDimitry Andric    vector(initializer_list<value_type> il);
500b57cec5SDimitry Andric    vector(initializer_list<value_type> il, const allocator_type& a);
510b57cec5SDimitry Andric    ~vector();
520b57cec5SDimitry Andric    vector& operator=(const vector& x);
530b57cec5SDimitry Andric    vector& operator=(vector&& x)
540b57cec5SDimitry Andric        noexcept(
550b57cec5SDimitry Andric             allocator_type::propagate_on_container_move_assignment::value ||
560b57cec5SDimitry Andric             allocator_type::is_always_equal::value); // C++17
570b57cec5SDimitry Andric    vector& operator=(initializer_list<value_type> il);
580b57cec5SDimitry Andric    template <class InputIterator>
590b57cec5SDimitry Andric        void assign(InputIterator first, InputIterator last);
60*06c3fb27SDimitry Andric    template<container-compatible-range<T> R>
61*06c3fb27SDimitry Andric      constexpr void assign_range(R&& rg); // C++23
620b57cec5SDimitry Andric    void assign(size_type n, const value_type& u);
630b57cec5SDimitry Andric    void assign(initializer_list<value_type> il);
640b57cec5SDimitry Andric
650b57cec5SDimitry Andric    allocator_type get_allocator() const noexcept;
660b57cec5SDimitry Andric
670b57cec5SDimitry Andric    iterator               begin() noexcept;
680b57cec5SDimitry Andric    const_iterator         begin()   const noexcept;
690b57cec5SDimitry Andric    iterator               end() noexcept;
700b57cec5SDimitry Andric    const_iterator         end()     const noexcept;
710b57cec5SDimitry Andric
720b57cec5SDimitry Andric    reverse_iterator       rbegin() noexcept;
730b57cec5SDimitry Andric    const_reverse_iterator rbegin()  const noexcept;
740b57cec5SDimitry Andric    reverse_iterator       rend() noexcept;
750b57cec5SDimitry Andric    const_reverse_iterator rend()    const noexcept;
760b57cec5SDimitry Andric
770b57cec5SDimitry Andric    const_iterator         cbegin()  const noexcept;
780b57cec5SDimitry Andric    const_iterator         cend()    const noexcept;
790b57cec5SDimitry Andric    const_reverse_iterator crbegin() const noexcept;
800b57cec5SDimitry Andric    const_reverse_iterator crend()   const noexcept;
810b57cec5SDimitry Andric
820b57cec5SDimitry Andric    size_type size() const noexcept;
830b57cec5SDimitry Andric    size_type max_size() const noexcept;
840b57cec5SDimitry Andric    size_type capacity() const noexcept;
850b57cec5SDimitry Andric    bool empty() const noexcept;
860b57cec5SDimitry Andric    void reserve(size_type n);
870b57cec5SDimitry Andric    void shrink_to_fit() noexcept;
880b57cec5SDimitry Andric
890b57cec5SDimitry Andric    reference       operator[](size_type n);
900b57cec5SDimitry Andric    const_reference operator[](size_type n) const;
910b57cec5SDimitry Andric    reference       at(size_type n);
920b57cec5SDimitry Andric    const_reference at(size_type n) const;
930b57cec5SDimitry Andric
940b57cec5SDimitry Andric    reference       front();
950b57cec5SDimitry Andric    const_reference front() const;
960b57cec5SDimitry Andric    reference       back();
970b57cec5SDimitry Andric    const_reference back() const;
980b57cec5SDimitry Andric
990b57cec5SDimitry Andric    value_type*       data() noexcept;
1000b57cec5SDimitry Andric    const value_type* data() const noexcept;
1010b57cec5SDimitry Andric
1020b57cec5SDimitry Andric    void push_back(const value_type& x);
1030b57cec5SDimitry Andric    void push_back(value_type&& x);
1040b57cec5SDimitry Andric    template <class... Args>
1050b57cec5SDimitry Andric        reference emplace_back(Args&&... args); // reference in C++17
106*06c3fb27SDimitry Andric    template<container-compatible-range<T> R>
107*06c3fb27SDimitry Andric      constexpr void append_range(R&& rg); // C++23
1080b57cec5SDimitry Andric    void pop_back();
1090b57cec5SDimitry Andric
1100b57cec5SDimitry Andric    template <class... Args> iterator emplace(const_iterator position, Args&&... args);
1110b57cec5SDimitry Andric    iterator insert(const_iterator position, const value_type& x);
1120b57cec5SDimitry Andric    iterator insert(const_iterator position, value_type&& x);
1130b57cec5SDimitry Andric    iterator insert(const_iterator position, size_type n, const value_type& x);
1140b57cec5SDimitry Andric    template <class InputIterator>
1150b57cec5SDimitry Andric        iterator insert(const_iterator position, InputIterator first, InputIterator last);
116*06c3fb27SDimitry Andric    template<container-compatible-range<T> R>
117*06c3fb27SDimitry Andric      constexpr iterator insert_range(const_iterator position, R&& rg); // C++23
1180b57cec5SDimitry Andric    iterator insert(const_iterator position, initializer_list<value_type> il);
1190b57cec5SDimitry Andric
1200b57cec5SDimitry Andric    iterator erase(const_iterator position);
1210b57cec5SDimitry Andric    iterator erase(const_iterator first, const_iterator last);
1220b57cec5SDimitry Andric
1230b57cec5SDimitry Andric    void clear() noexcept;
1240b57cec5SDimitry Andric
1250b57cec5SDimitry Andric    void resize(size_type sz);
1260b57cec5SDimitry Andric    void resize(size_type sz, const value_type& c);
1270b57cec5SDimitry Andric
1280b57cec5SDimitry Andric    void swap(vector&)
1290b57cec5SDimitry Andric        noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
1300b57cec5SDimitry Andric                 allocator_traits<allocator_type>::is_always_equal::value);  // C++17
1310b57cec5SDimitry Andric
1320b57cec5SDimitry Andric    bool __invariants() const;
1330b57cec5SDimitry Andric};
1340b57cec5SDimitry Andric
1350b57cec5SDimitry Andrictemplate <class Allocator = allocator<T> >
1360b57cec5SDimitry Andricclass vector<bool, Allocator>
1370b57cec5SDimitry Andric{
1380b57cec5SDimitry Andricpublic:
1390b57cec5SDimitry Andric    typedef bool                                     value_type;
1400b57cec5SDimitry Andric    typedef Allocator                                allocator_type;
1410b57cec5SDimitry Andric    typedef implementation-defined                   iterator;
1420b57cec5SDimitry Andric    typedef implementation-defined                   const_iterator;
1430b57cec5SDimitry Andric    typedef typename allocator_type::size_type       size_type;
1440b57cec5SDimitry Andric    typedef typename allocator_type::difference_type difference_type;
1450b57cec5SDimitry Andric    typedef iterator                                 pointer;
1460b57cec5SDimitry Andric    typedef const_iterator                           const_pointer;
1470b57cec5SDimitry Andric    typedef std::reverse_iterator<iterator>          reverse_iterator;
1480b57cec5SDimitry Andric    typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
1490b57cec5SDimitry Andric
1500b57cec5SDimitry Andric    class reference
1510b57cec5SDimitry Andric    {
1520b57cec5SDimitry Andric    public:
1530b57cec5SDimitry Andric        reference(const reference&) noexcept;
1540b57cec5SDimitry Andric        operator bool() const noexcept;
155fe6060f1SDimitry Andric        reference& operator=(bool x) noexcept;
1560b57cec5SDimitry Andric        reference& operator=(const reference& x) noexcept;
1570b57cec5SDimitry Andric        iterator operator&() const noexcept;
1580b57cec5SDimitry Andric        void flip() noexcept;
1590b57cec5SDimitry Andric    };
1600b57cec5SDimitry Andric
1610b57cec5SDimitry Andric    class const_reference
1620b57cec5SDimitry Andric    {
1630b57cec5SDimitry Andric    public:
1640b57cec5SDimitry Andric        const_reference(const reference&) noexcept;
1650b57cec5SDimitry Andric        operator bool() const noexcept;
1660b57cec5SDimitry Andric        const_iterator operator&() const noexcept;
1670b57cec5SDimitry Andric    };
1680b57cec5SDimitry Andric
1690b57cec5SDimitry Andric    vector()
1700b57cec5SDimitry Andric        noexcept(is_nothrow_default_constructible<allocator_type>::value);
1710b57cec5SDimitry Andric    explicit vector(const allocator_type&);
1720b57cec5SDimitry Andric    explicit vector(size_type n, const allocator_type& a = allocator_type()); // C++14
1730b57cec5SDimitry Andric    vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
1740b57cec5SDimitry Andric    template <class InputIterator>
1750b57cec5SDimitry Andric        vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
176*06c3fb27SDimitry Andric    template<container-compatible-range<bool> R>
177*06c3fb27SDimitry Andric      constexpr vector(from_range_t, R&& rg, const Allocator& = Allocator());
1780b57cec5SDimitry Andric    vector(const vector& x);
1790b57cec5SDimitry Andric    vector(vector&& x)
1800b57cec5SDimitry Andric        noexcept(is_nothrow_move_constructible<allocator_type>::value);
1810b57cec5SDimitry Andric    vector(initializer_list<value_type> il);
1820b57cec5SDimitry Andric    vector(initializer_list<value_type> il, const allocator_type& a);
1830b57cec5SDimitry Andric    ~vector();
1840b57cec5SDimitry Andric    vector& operator=(const vector& x);
1850b57cec5SDimitry Andric    vector& operator=(vector&& x)
1860b57cec5SDimitry Andric        noexcept(
1870b57cec5SDimitry Andric             allocator_type::propagate_on_container_move_assignment::value ||
1880b57cec5SDimitry Andric             allocator_type::is_always_equal::value); // C++17
1890b57cec5SDimitry Andric    vector& operator=(initializer_list<value_type> il);
1900b57cec5SDimitry Andric    template <class InputIterator>
1910b57cec5SDimitry Andric        void assign(InputIterator first, InputIterator last);
192*06c3fb27SDimitry Andric    template<container-compatible-range<T> R>
193*06c3fb27SDimitry Andric      constexpr void assign_range(R&& rg); // C++23
1940b57cec5SDimitry Andric    void assign(size_type n, const value_type& u);
1950b57cec5SDimitry Andric    void assign(initializer_list<value_type> il);
1960b57cec5SDimitry Andric
1970b57cec5SDimitry Andric    allocator_type get_allocator() const noexcept;
1980b57cec5SDimitry Andric
1990b57cec5SDimitry Andric    iterator               begin() noexcept;
2000b57cec5SDimitry Andric    const_iterator         begin()   const noexcept;
2010b57cec5SDimitry Andric    iterator               end() noexcept;
2020b57cec5SDimitry Andric    const_iterator         end()     const noexcept;
2030b57cec5SDimitry Andric
2040b57cec5SDimitry Andric    reverse_iterator       rbegin() noexcept;
2050b57cec5SDimitry Andric    const_reverse_iterator rbegin()  const noexcept;
2060b57cec5SDimitry Andric    reverse_iterator       rend() noexcept;
2070b57cec5SDimitry Andric    const_reverse_iterator rend()    const noexcept;
2080b57cec5SDimitry Andric
2090b57cec5SDimitry Andric    const_iterator         cbegin()  const noexcept;
2100b57cec5SDimitry Andric    const_iterator         cend()    const noexcept;
2110b57cec5SDimitry Andric    const_reverse_iterator crbegin() const noexcept;
2120b57cec5SDimitry Andric    const_reverse_iterator crend()   const noexcept;
2130b57cec5SDimitry Andric
2140b57cec5SDimitry Andric    size_type size() const noexcept;
2150b57cec5SDimitry Andric    size_type max_size() const noexcept;
2160b57cec5SDimitry Andric    size_type capacity() const noexcept;
2170b57cec5SDimitry Andric    bool empty() const noexcept;
2180b57cec5SDimitry Andric    void reserve(size_type n);
2190b57cec5SDimitry Andric    void shrink_to_fit() noexcept;
2200b57cec5SDimitry Andric
2210b57cec5SDimitry Andric    reference       operator[](size_type n);
2220b57cec5SDimitry Andric    const_reference operator[](size_type n) const;
2230b57cec5SDimitry Andric    reference       at(size_type n);
2240b57cec5SDimitry Andric    const_reference at(size_type n) const;
2250b57cec5SDimitry Andric
2260b57cec5SDimitry Andric    reference       front();
2270b57cec5SDimitry Andric    const_reference front() const;
2280b57cec5SDimitry Andric    reference       back();
2290b57cec5SDimitry Andric    const_reference back() const;
2300b57cec5SDimitry Andric
2310b57cec5SDimitry Andric    void push_back(const value_type& x);
2320b57cec5SDimitry Andric    template <class... Args> reference emplace_back(Args&&... args);  // C++14; reference in C++17
233*06c3fb27SDimitry Andric    template<container-compatible-range<T> R>
234*06c3fb27SDimitry Andric      constexpr void append_range(R&& rg); // C++23
2350b57cec5SDimitry Andric    void pop_back();
2360b57cec5SDimitry Andric
2370b57cec5SDimitry Andric    template <class... Args> iterator emplace(const_iterator position, Args&&... args);  // C++14
2380b57cec5SDimitry Andric    iterator insert(const_iterator position, const value_type& x);
2390b57cec5SDimitry Andric    iterator insert(const_iterator position, size_type n, const value_type& x);
2400b57cec5SDimitry Andric    template <class InputIterator>
2410b57cec5SDimitry Andric        iterator insert(const_iterator position, InputIterator first, InputIterator last);
242*06c3fb27SDimitry Andric    template<container-compatible-range<T> R>
243*06c3fb27SDimitry Andric      constexpr iterator insert_range(const_iterator position, R&& rg); // C++23
2440b57cec5SDimitry Andric    iterator insert(const_iterator position, initializer_list<value_type> il);
2450b57cec5SDimitry Andric
2460b57cec5SDimitry Andric    iterator erase(const_iterator position);
2470b57cec5SDimitry Andric    iterator erase(const_iterator first, const_iterator last);
2480b57cec5SDimitry Andric
2490b57cec5SDimitry Andric    void clear() noexcept;
2500b57cec5SDimitry Andric
2510b57cec5SDimitry Andric    void resize(size_type sz);
2520b57cec5SDimitry Andric    void resize(size_type sz, value_type x);
2530b57cec5SDimitry Andric
2540b57cec5SDimitry Andric    void swap(vector&)
2550b57cec5SDimitry Andric        noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
2560b57cec5SDimitry Andric                 allocator_traits<allocator_type>::is_always_equal::value);  // C++17
2570b57cec5SDimitry Andric    void flip() noexcept;
2580b57cec5SDimitry Andric
2590b57cec5SDimitry Andric    bool __invariants() const;
2600b57cec5SDimitry Andric};
2610b57cec5SDimitry Andric
2620b57cec5SDimitry Andrictemplate <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
2630b57cec5SDimitry Andric   vector(InputIterator, InputIterator, Allocator = Allocator())
264349cc55cSDimitry Andric   -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17
2650b57cec5SDimitry Andric
266*06c3fb27SDimitry Andrictemplate<ranges::input_range R, class Allocator = allocator<ranges::range_value_t<R>>>
267*06c3fb27SDimitry Andric  vector(from_range_t, R&&, Allocator = Allocator())
268*06c3fb27SDimitry Andric    -> vector<ranges::range_value_t<R>, Allocator>; // C++23
269*06c3fb27SDimitry Andric
2700b57cec5SDimitry Andrictemplate <class Allocator> struct hash<std::vector<bool, Allocator>>;
2710b57cec5SDimitry Andric
272*06c3fb27SDimitry Andrictemplate <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y);   // constexpr since C++20
273*06c3fb27SDimitry Andrictemplate <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);   // removed in C++20
274*06c3fb27SDimitry Andrictemplate <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y);   // removed in C++20
275*06c3fb27SDimitry Andrictemplate <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y);   // removed in C++20
276*06c3fb27SDimitry Andrictemplate <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);   // removed in C++20
277*06c3fb27SDimitry Andrictemplate <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);   // removed in C++20
278*06c3fb27SDimitry Andrictemplate <class T, class Allocator> constexpr
279*06c3fb27SDimitry Andric  constexpr synth-three-way-result<T> operator<=>(const vector<T, Allocator>& x,
280*06c3fb27SDimitry Andric                                                  const vector<T, Allocator>& y);                                  // since C++20
2810b57cec5SDimitry Andric
2820b57cec5SDimitry Andrictemplate <class T, class Allocator>
2830b57cec5SDimitry Andricvoid swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
2840b57cec5SDimitry Andric    noexcept(noexcept(x.swap(y)));
2850b57cec5SDimitry Andric
2860b57cec5SDimitry Andrictemplate <class T, class Allocator, class U>
2875ffd83dbSDimitry Andrictypename vector<T, Allocator>::size_type
288*06c3fb27SDimitry Andricerase(vector<T, Allocator>& c, const U& value);       // since C++20
2890b57cec5SDimitry Andrictemplate <class T, class Allocator, class Predicate>
2905ffd83dbSDimitry Andrictypename vector<T, Allocator>::size_type
291*06c3fb27SDimitry Andricerase_if(vector<T, Allocator>& c, Predicate pred);    // since C++20
2920b57cec5SDimitry Andric
293bdd1243dSDimitry Andric
294bdd1243dSDimitry Andrictemplate<class T>
295bdd1243dSDimitry Andric inline constexpr bool is-vector-bool-reference = see below;        // exposition only, since C++23
296bdd1243dSDimitry Andric
297bdd1243dSDimitry Andrictemplate<class T, class charT> requires is-vector-bool-reference<T> // Since C++23
298bdd1243dSDimitry Andric struct formatter<T, charT>;
299bdd1243dSDimitry Andric
3000b57cec5SDimitry Andric}  // std
3010b57cec5SDimitry Andric
3020b57cec5SDimitry Andric*/
3030b57cec5SDimitry Andric
30481ad6265SDimitry Andric#include <__algorithm/copy.h>
30581ad6265SDimitry Andric#include <__algorithm/equal.h>
30681ad6265SDimitry Andric#include <__algorithm/fill_n.h>
307*06c3fb27SDimitry Andric#include <__algorithm/iterator_operations.h>
30881ad6265SDimitry Andric#include <__algorithm/lexicographical_compare.h>
309*06c3fb27SDimitry Andric#include <__algorithm/lexicographical_compare_three_way.h>
31081ad6265SDimitry Andric#include <__algorithm/remove.h>
31181ad6265SDimitry Andric#include <__algorithm/remove_if.h>
31281ad6265SDimitry Andric#include <__algorithm/rotate.h>
31381ad6265SDimitry Andric#include <__algorithm/unwrap_iter.h>
31481ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler
315*06c3fb27SDimitry Andric#include <__availability>
3160b57cec5SDimitry Andric#include <__bit_reference>
317bdd1243dSDimitry Andric#include <__concepts/same_as.h>
31804eeddc0SDimitry Andric#include <__config>
31981ad6265SDimitry Andric#include <__format/enable_insertable.h>
320bdd1243dSDimitry Andric#include <__format/formatter.h>
321*06c3fb27SDimitry Andric#include <__format/formatter_bool.h>
32281ad6265SDimitry Andric#include <__functional/hash.h>
32381ad6265SDimitry Andric#include <__functional/unary_function.h>
32481ad6265SDimitry Andric#include <__iterator/advance.h>
325*06c3fb27SDimitry Andric#include <__iterator/distance.h>
326349cc55cSDimitry Andric#include <__iterator/iterator_traits.h>
32781ad6265SDimitry Andric#include <__iterator/reverse_iterator.h>
328fe6060f1SDimitry Andric#include <__iterator/wrap_iter.h>
329*06c3fb27SDimitry Andric#include <__memory/addressof.h>
33081ad6265SDimitry Andric#include <__memory/allocate_at_least.h>
331*06c3fb27SDimitry Andric#include <__memory/allocator_traits.h>
332972a253aSDimitry Andric#include <__memory/pointer_traits.h>
333972a253aSDimitry Andric#include <__memory/swap_allocator.h>
334bdd1243dSDimitry Andric#include <__memory/temp_value.h>
335bdd1243dSDimitry Andric#include <__memory/uninitialized_algorithms.h>
336bdd1243dSDimitry Andric#include <__memory_resource/polymorphic_allocator.h>
337*06c3fb27SDimitry Andric#include <__ranges/access.h>
338*06c3fb27SDimitry Andric#include <__ranges/concepts.h>
339*06c3fb27SDimitry Andric#include <__ranges/container_compatible_range.h>
340*06c3fb27SDimitry Andric#include <__ranges/from_range.h>
341*06c3fb27SDimitry Andric#include <__ranges/size.h>
342fe6060f1SDimitry Andric#include <__split_buffer>
343bdd1243dSDimitry Andric#include <__type_traits/is_allocator.h>
344*06c3fb27SDimitry Andric#include <__type_traits/is_constructible.h>
345*06c3fb27SDimitry Andric#include <__type_traits/is_nothrow_move_assignable.h>
346bdd1243dSDimitry Andric#include <__type_traits/noexcept_move_assign_container.h>
347*06c3fb27SDimitry Andric#include <__type_traits/type_identity.h>
348bdd1243dSDimitry Andric#include <__utility/exception_guard.h>
349fe6060f1SDimitry Andric#include <__utility/forward.h>
35081ad6265SDimitry Andric#include <__utility/move.h>
351*06c3fb27SDimitry Andric#include <__utility/pair.h>
35281ad6265SDimitry Andric#include <__utility/swap.h>
3530b57cec5SDimitry Andric#include <climits>
354fe6060f1SDimitry Andric#include <cstring>
355fe6060f1SDimitry Andric#include <iosfwd> // for forward declaration of vector
356fe6060f1SDimitry Andric#include <limits>
3570b57cec5SDimitry Andric#include <stdexcept>
3580b57cec5SDimitry Andric#include <version>
3590b57cec5SDimitry Andric
36081ad6265SDimitry Andric// standard-mandated includes
36181ad6265SDimitry Andric
36281ad6265SDimitry Andric// [iterator.range]
36381ad6265SDimitry Andric#include <__iterator/access.h>
36481ad6265SDimitry Andric#include <__iterator/data.h>
36581ad6265SDimitry Andric#include <__iterator/empty.h>
36681ad6265SDimitry Andric#include <__iterator/reverse_access.h>
36781ad6265SDimitry Andric#include <__iterator/size.h>
36881ad6265SDimitry Andric
36981ad6265SDimitry Andric// [vector.syn]
37081ad6265SDimitry Andric#include <compare>
37181ad6265SDimitry Andric#include <initializer_list>
37281ad6265SDimitry Andric
3730b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3740b57cec5SDimitry Andric#  pragma GCC system_header
3750b57cec5SDimitry Andric#endif
3760b57cec5SDimitry Andric
3770b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS
3780b57cec5SDimitry Andric#include <__undef_macros>
3790b57cec5SDimitry Andric
3800b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
3810b57cec5SDimitry Andric
3820b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator /* = allocator<_Tp> */>
3830b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector
3840b57cec5SDimitry Andric{
3850b57cec5SDimitry Andricprivate:
3860b57cec5SDimitry Andric    typedef allocator<_Tp>                                  __default_allocator_type;
3870b57cec5SDimitry Andricpublic:
3880b57cec5SDimitry Andric    typedef vector                                          __self;
3890b57cec5SDimitry Andric    typedef _Tp                                             value_type;
3900b57cec5SDimitry Andric    typedef _Allocator                                      allocator_type;
391349cc55cSDimitry Andric    typedef allocator_traits<allocator_type>                __alloc_traits;
392349cc55cSDimitry Andric    typedef value_type&                                     reference;
393349cc55cSDimitry Andric    typedef const value_type&                               const_reference;
3944824e7fdSDimitry Andric    typedef typename __alloc_traits::size_type              size_type;
395349cc55cSDimitry Andric    typedef typename __alloc_traits::difference_type        difference_type;
396349cc55cSDimitry Andric    typedef typename __alloc_traits::pointer                pointer;
397349cc55cSDimitry Andric    typedef typename __alloc_traits::const_pointer          const_pointer;
398bdd1243dSDimitry Andric    // TODO: Implement iterator bounds checking without requiring the global database.
3990b57cec5SDimitry Andric    typedef __wrap_iter<pointer>                            iterator;
4000b57cec5SDimitry Andric    typedef __wrap_iter<const_pointer>                      const_iterator;
401bdd1243dSDimitry Andric    typedef std::reverse_iterator<iterator>               reverse_iterator;
402bdd1243dSDimitry Andric    typedef std::reverse_iterator<const_iterator>         const_reverse_iterator;
4030b57cec5SDimitry Andric
4040b57cec5SDimitry Andric    static_assert((is_same<typename allocator_type::value_type, value_type>::value),
4050b57cec5SDimitry Andric                  "Allocator::value_type must be same type as value_type");
4060b57cec5SDimitry Andric
407bdd1243dSDimitry Andric    static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value,
408bdd1243dSDimitry Andric                  "[allocator.requirements] states that rebinding an allocator to the same type should result in the "
409bdd1243dSDimitry Andric                  "original allocator");
410bdd1243dSDimitry Andric
411bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
4120b57cec5SDimitry Andric    vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
4130b57cec5SDimitry Andric    {
4140b57cec5SDimitry Andric    }
415bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(const allocator_type& __a)
4160b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
4170b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
4180b57cec5SDimitry Andric#else
4190b57cec5SDimitry Andric        _NOEXCEPT
4200b57cec5SDimitry Andric#endif
421d56accc7SDimitry Andric        : __end_cap_(nullptr, __a)
4220b57cec5SDimitry Andric    {
4230b57cec5SDimitry Andric    }
424bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n);
425*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
426bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n, const allocator_type& __a);
4270b57cec5SDimitry Andric#endif
428bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(size_type __n, const value_type& __x);
4294824e7fdSDimitry Andric
4304824e7fdSDimitry Andric    template <class = __enable_if_t<__is_allocator<_Allocator>::value> >
431bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
4324824e7fdSDimitry Andric    vector(size_type __n, const value_type& __x, const allocator_type& __a)
433d56accc7SDimitry Andric        : __end_cap_(nullptr, __a)
4344824e7fdSDimitry Andric    {
4354824e7fdSDimitry Andric      if (__n > 0)
4364824e7fdSDimitry Andric      {
4374824e7fdSDimitry Andric          __vallocate(__n);
4384824e7fdSDimitry Andric          __construct_at_end(__n, __x);
4394824e7fdSDimitry Andric      }
4404824e7fdSDimitry Andric    }
4414824e7fdSDimitry Andric
442bdd1243dSDimitry Andric  template <class _InputIterator,
443*06c3fb27SDimitry Andric            __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
444bdd1243dSDimitry Andric                              is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,
445bdd1243dSDimitry Andric                          int> = 0>
446bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(_InputIterator __first, _InputIterator __last);
447bdd1243dSDimitry Andric  template <class _InputIterator,
448*06c3fb27SDimitry Andric            __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
449bdd1243dSDimitry Andric                              is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,
450bdd1243dSDimitry Andric                          int> = 0>
451bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
452bdd1243dSDimitry Andric  vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
453bdd1243dSDimitry Andric
454bdd1243dSDimitry Andric  template <
455bdd1243dSDimitry Andric      class _ForwardIterator,
456*06c3fb27SDimitry Andric      __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
457bdd1243dSDimitry Andric                        is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
458bdd1243dSDimitry Andric                    int> = 0>
459bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(_ForwardIterator __first, _ForwardIterator __last);
460bdd1243dSDimitry Andric
461bdd1243dSDimitry Andric  template <class _ForwardIterator,
462*06c3fb27SDimitry 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
468*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
469*06c3fb27SDimitry Andric  template <_ContainerCompatibleRange<_Tp> _Range>
470*06c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr vector(from_range_t, _Range&& __range,
471*06c3fb27SDimitry Andric      const allocator_type& __alloc = allocator_type()) : __end_cap_(nullptr, __alloc) {
472*06c3fb27SDimitry Andric    if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
473*06c3fb27SDimitry Andric      auto __n = static_cast<size_type>(ranges::distance(__range));
474*06c3fb27SDimitry Andric      __init_with_size(ranges::begin(__range), ranges::end(__range), __n);
475*06c3fb27SDimitry Andric
476*06c3fb27SDimitry Andric    } else {
477*06c3fb27SDimitry Andric      __init_with_sentinel(ranges::begin(__range), ranges::end(__range));
478*06c3fb27SDimitry Andric    }
479*06c3fb27SDimitry Andric  }
480*06c3fb27SDimitry Andric#endif
481*06c3fb27SDimitry Andric
48250d7464cSDimitry Andricprivate:
48350d7464cSDimitry Andric  class __destroy_vector {
48450d7464cSDimitry Andric    public:
485*06c3fb27SDimitry Andric      _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI __destroy_vector(vector& __vec) : __vec_(__vec) {}
486349cc55cSDimitry Andric
487bdd1243dSDimitry Andric      _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() {
48850d7464cSDimitry Andric          if (__vec_.__begin_ != nullptr) {
48950d7464cSDimitry Andric            __vec_.__clear();
490*06c3fb27SDimitry Andric            __vec_.__annotate_delete();
49150d7464cSDimitry Andric            __alloc_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.capacity());
492349cc55cSDimitry Andric          }
4930b57cec5SDimitry Andric      }
4940b57cec5SDimitry Andric
49550d7464cSDimitry Andric    private:
49650d7464cSDimitry Andric      vector& __vec_;
49750d7464cSDimitry Andric  };
49850d7464cSDimitry Andric
49950d7464cSDimitry Andricpublic:
500bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~vector() { __destroy_vector(*this)(); }
50150d7464cSDimitry Andric
502bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(const vector& __x);
503bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector(const vector& __x, const __type_identity_t<allocator_type>& __a);
504bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
5050b57cec5SDimitry Andric    vector& operator=(const vector& __x);
5060b57cec5SDimitry Andric
5070b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
508bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
5090b57cec5SDimitry Andric    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
514bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
51581ad6265SDimitry Andric    vector& operator=(initializer_list<value_type> __il)
51681ad6265SDimitry Andric        {assign(__il.begin(), __il.end()); return *this;}
51781ad6265SDimitry Andric#endif // !_LIBCPP_CXX03_LANG
51881ad6265SDimitry Andric
519bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
5200b57cec5SDimitry Andric    vector(vector&& __x)
521*06c3fb27SDimitry 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);
529bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
5300b57cec5SDimitry Andric    vector& operator=(vector&& __x)
5310b57cec5SDimitry Andric        _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
5320b57cec5SDimitry Andric
533bdd1243dSDimitry Andric  template <class _InputIterator,
534*06c3fb27SDimitry Andric            __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
535bdd1243dSDimitry Andric                              is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,
536bdd1243dSDimitry Andric                          int> = 0>
537bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(_InputIterator __first, _InputIterator __last);
538bdd1243dSDimitry Andric  template <
539bdd1243dSDimitry Andric      class _ForwardIterator,
540*06c3fb27SDimitry Andric      __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
541bdd1243dSDimitry Andric                        is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
542bdd1243dSDimitry Andric                    int> = 0>
543bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(_ForwardIterator __first, _ForwardIterator __last);
5440b57cec5SDimitry Andric
545*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
546*06c3fb27SDimitry Andric    template <_ContainerCompatibleRange<_Tp> _Range>
547*06c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI
548*06c3fb27SDimitry Andric    constexpr void assign_range(_Range&& __range) {
549*06c3fb27SDimitry Andric      if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
550*06c3fb27SDimitry Andric        auto __n = static_cast<size_type>(ranges::distance(__range));
551*06c3fb27SDimitry Andric        __assign_with_size(ranges::begin(__range), ranges::end(__range), __n);
552*06c3fb27SDimitry Andric
553*06c3fb27SDimitry Andric      } else {
554*06c3fb27SDimitry Andric        __assign_with_sentinel(ranges::begin(__range), ranges::end(__range));
555*06c3fb27SDimitry Andric      }
556*06c3fb27SDimitry Andric    }
557*06c3fb27SDimitry Andric#endif
558*06c3fb27SDimitry Andric
559bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const_reference __u);
5600b57cec5SDimitry Andric
5610b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
562bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
5630b57cec5SDimitry Andric    void assign(initializer_list<value_type> __il)
5640b57cec5SDimitry Andric        {assign(__il.begin(), __il.end());}
5650b57cec5SDimitry Andric#endif
5660b57cec5SDimitry Andric
567bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
5680b57cec5SDimitry Andric    allocator_type get_allocator() const _NOEXCEPT
5690b57cec5SDimitry Andric        {return this->__alloc();}
5700b57cec5SDimitry Andric
571bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator               begin() _NOEXCEPT;
572bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator         begin()   const _NOEXCEPT;
573bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator               end() _NOEXCEPT;
574bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_iterator         end()     const _NOEXCEPT;
5750b57cec5SDimitry Andric
576bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
5770b57cec5SDimitry Andric    reverse_iterator       rbegin() _NOEXCEPT
5780b57cec5SDimitry Andric        {return       reverse_iterator(end());}
579bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
5800b57cec5SDimitry Andric    const_reverse_iterator rbegin()  const _NOEXCEPT
5810b57cec5SDimitry Andric        {return const_reverse_iterator(end());}
582bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
5830b57cec5SDimitry Andric    reverse_iterator       rend() _NOEXCEPT
5840b57cec5SDimitry Andric        {return       reverse_iterator(begin());}
585bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
5860b57cec5SDimitry Andric    const_reverse_iterator rend()    const _NOEXCEPT
5870b57cec5SDimitry Andric        {return const_reverse_iterator(begin());}
5880b57cec5SDimitry Andric
589bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
5900b57cec5SDimitry Andric    const_iterator         cbegin()  const _NOEXCEPT
5910b57cec5SDimitry Andric        {return begin();}
592bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
5930b57cec5SDimitry Andric    const_iterator         cend()    const _NOEXCEPT
5940b57cec5SDimitry Andric        {return end();}
595bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
5960b57cec5SDimitry Andric    const_reverse_iterator crbegin() const _NOEXCEPT
5970b57cec5SDimitry Andric        {return rbegin();}
598bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
5990b57cec5SDimitry Andric    const_reverse_iterator crend()   const _NOEXCEPT
6000b57cec5SDimitry Andric        {return rend();}
6010b57cec5SDimitry Andric
602bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
6030b57cec5SDimitry Andric    size_type size() const _NOEXCEPT
6040b57cec5SDimitry Andric        {return static_cast<size_type>(this->__end_ - this->__begin_);}
605bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
6060b57cec5SDimitry Andric    size_type capacity() const _NOEXCEPT
607349cc55cSDimitry Andric        {return static_cast<size_type>(__end_cap() - this->__begin_);}
608bdd1243dSDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
6090b57cec5SDimitry Andric    bool empty() const _NOEXCEPT
6100b57cec5SDimitry Andric        {return this->__begin_ == this->__end_;}
611bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT;
612bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void reserve(size_type __n);
613bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void shrink_to_fit() _NOEXCEPT;
6140b57cec5SDimitry Andric
615bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference       operator[](size_type __n) _NOEXCEPT;
616bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference operator[](size_type __n) const _NOEXCEPT;
617bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference       at(size_type __n);
618bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __n) const;
6190b57cec5SDimitry Andric
620bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference       front() _NOEXCEPT
6210b57cec5SDimitry Andric    {
622*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "front() called on an empty vector");
6230b57cec5SDimitry Andric        return *this->__begin_;
6240b57cec5SDimitry Andric    }
625bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference front() const _NOEXCEPT
6260b57cec5SDimitry Andric    {
627*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "front() called on an empty vector");
6280b57cec5SDimitry Andric        return *this->__begin_;
6290b57cec5SDimitry Andric    }
630bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI reference       back() _NOEXCEPT
6310b57cec5SDimitry Andric    {
632*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "back() called on an empty vector");
6330b57cec5SDimitry Andric        return *(this->__end_ - 1);
6340b57cec5SDimitry Andric    }
635bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI const_reference back()  const _NOEXCEPT
6360b57cec5SDimitry Andric    {
637*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "back() called on an empty vector");
6380b57cec5SDimitry Andric        return *(this->__end_ - 1);
6390b57cec5SDimitry Andric    }
6400b57cec5SDimitry Andric
641bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
6420b57cec5SDimitry Andric    value_type*       data() _NOEXCEPT
643bdd1243dSDimitry Andric        {return std::__to_address(this->__begin_);}
64461cfbce3SDimitry Andric
645bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
6460b57cec5SDimitry Andric    const value_type* data() const _NOEXCEPT
647bdd1243dSDimitry Andric        {return std::__to_address(this->__begin_);}
6480b57cec5SDimitry Andric
649bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_back(const_reference __x);
6500b57cec5SDimitry Andric
651bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __x);
6520b57cec5SDimitry Andric
6530b57cec5SDimitry Andric    template <class... _Args>
654bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
655*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
6560b57cec5SDimitry Andric        reference emplace_back(_Args&&... __args);
6570b57cec5SDimitry Andric#else
6580b57cec5SDimitry Andric        void      emplace_back(_Args&&... __args);
6590b57cec5SDimitry Andric#endif
6600b57cec5SDimitry Andric
661*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
662*06c3fb27SDimitry Andric    template <_ContainerCompatibleRange<_Tp> _Range>
663*06c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI
664*06c3fb27SDimitry Andric    constexpr void append_range(_Range&& __range) {
665*06c3fb27SDimitry Andric      insert_range(end(), std::forward<_Range>(__range));
666*06c3fb27SDimitry Andric    }
667*06c3fb27SDimitry Andric#endif
668*06c3fb27SDimitry Andric
669bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
6700b57cec5SDimitry Andric    void pop_back();
6710b57cec5SDimitry Andric
672bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, const_reference __x);
6730b57cec5SDimitry Andric
674bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, value_type&& __x);
6750b57cec5SDimitry Andric    template <class... _Args>
676bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __position, _Args&&... __args);
6770b57cec5SDimitry Andric
678bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
679bdd1243dSDimitry Andric    iterator insert(const_iterator __position, size_type __n, const_reference __x);
680bdd1243dSDimitry Andric
681bdd1243dSDimitry Andric  template <class _InputIterator,
682*06c3fb27SDimitry Andric            __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
683bdd1243dSDimitry Andric                              is_constructible< value_type, typename iterator_traits<_InputIterator>::reference>::value,
684bdd1243dSDimitry Andric                          int> = 0>
685bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
6860b57cec5SDimitry Andric  insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
687bdd1243dSDimitry Andric
688*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
689*06c3fb27SDimitry Andric    template <_ContainerCompatibleRange<_Tp> _Range>
690*06c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI
691*06c3fb27SDimitry Andric    constexpr iterator insert_range(const_iterator __position, _Range&& __range) {
692*06c3fb27SDimitry Andric      if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
693*06c3fb27SDimitry Andric        auto __n = static_cast<size_type>(ranges::distance(__range));
694*06c3fb27SDimitry Andric        return __insert_with_size(__position, ranges::begin(__range), ranges::end(__range), __n);
695*06c3fb27SDimitry Andric
696*06c3fb27SDimitry Andric      } else {
697*06c3fb27SDimitry Andric        return __insert_with_sentinel(__position, ranges::begin(__range), ranges::end(__range));
698*06c3fb27SDimitry Andric      }
699*06c3fb27SDimitry Andric    }
700*06c3fb27SDimitry Andric#endif
701*06c3fb27SDimitry Andric
702bdd1243dSDimitry Andric  template <
703bdd1243dSDimitry Andric      class _ForwardIterator,
704*06c3fb27SDimitry Andric      __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
705bdd1243dSDimitry Andric                        is_constructible< value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
706bdd1243dSDimitry Andric                    int> = 0>
707bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
7080b57cec5SDimitry Andric  insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
7090b57cec5SDimitry Andric
7100b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
711bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
7120b57cec5SDimitry Andric    iterator insert(const_iterator __position, initializer_list<value_type> __il)
7130b57cec5SDimitry Andric        {return insert(__position, __il.begin(), __il.end());}
7140b57cec5SDimitry Andric#endif
7150b57cec5SDimitry Andric
716bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __position);
717bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last);
7180b57cec5SDimitry Andric
719bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
7200b57cec5SDimitry Andric    void clear() _NOEXCEPT
7210b57cec5SDimitry Andric    {
7220b57cec5SDimitry Andric        size_type __old_size = size();
723349cc55cSDimitry Andric        __clear();
7240b57cec5SDimitry Andric        __annotate_shrink(__old_size);
7250b57cec5SDimitry Andric    }
7260b57cec5SDimitry Andric
727bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz);
728bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz, const_reference __x);
7290b57cec5SDimitry Andric
730bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void swap(vector&)
7310b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
7320b57cec5SDimitry Andric        _NOEXCEPT;
7330b57cec5SDimitry Andric#else
7340b57cec5SDimitry Andric        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
7350b57cec5SDimitry Andric                    __is_nothrow_swappable<allocator_type>::value);
7360b57cec5SDimitry Andric#endif
7370b57cec5SDimitry Andric
738bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI bool __invariants() const;
7390b57cec5SDimitry Andric
7400b57cec5SDimitry Andricprivate:
741d56accc7SDimitry Andric    pointer __begin_ = nullptr;
742d56accc7SDimitry Andric    pointer __end_ = nullptr;
743d56accc7SDimitry Andric    __compressed_pair<pointer, allocator_type> __end_cap_ =
744d56accc7SDimitry Andric        __compressed_pair<pointer, allocator_type>(nullptr, __default_init_tag());
745d56accc7SDimitry Andric
74681ad6265SDimitry Andric    //  Allocate space for __n objects
74781ad6265SDimitry Andric    //  throws length_error if __n > max_size()
74881ad6265SDimitry Andric    //  throws (probably bad_alloc) if memory run out
74981ad6265SDimitry Andric    //  Precondition:  __begin_ == __end_ == __end_cap() == 0
75081ad6265SDimitry Andric    //  Precondition:  __n > 0
75181ad6265SDimitry Andric    //  Postcondition:  capacity() >= __n
75281ad6265SDimitry Andric    //  Postcondition:  size() == 0
753bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) {
75481ad6265SDimitry Andric        if (__n > max_size())
75581ad6265SDimitry Andric            __throw_length_error();
75681ad6265SDimitry Andric        auto __allocation = std::__allocate_at_least(__alloc(), __n);
75781ad6265SDimitry Andric        __begin_ = __allocation.ptr;
75881ad6265SDimitry Andric        __end_ = __allocation.ptr;
75981ad6265SDimitry Andric        __end_cap() = __begin_ + __allocation.count;
76081ad6265SDimitry Andric        __annotate_new(0);
76181ad6265SDimitry Andric    }
76281ad6265SDimitry Andric
763bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __vdeallocate() _NOEXCEPT;
764bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI size_type __recommend(size_type __new_size) const;
765bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __construct_at_end(size_type __n);
766bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
7670b57cec5SDimitry Andric    void __construct_at_end(size_type __n, const_reference __x);
768bdd1243dSDimitry Andric
769*06c3fb27SDimitry Andric    template <class _InputIterator, class _Sentinel>
770*06c3fb27SDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
771*06c3fb27SDimitry Andric    void __init_with_size(_InputIterator __first, _Sentinel __last, size_type __n) {
772*06c3fb27SDimitry Andric      auto __guard = std::__make_exception_guard(__destroy_vector(*this));
773*06c3fb27SDimitry Andric
774*06c3fb27SDimitry Andric      if (__n > 0) {
775*06c3fb27SDimitry Andric        __vallocate(__n);
776*06c3fb27SDimitry Andric        __construct_at_end(__first, __last, __n);
777*06c3fb27SDimitry Andric      }
778*06c3fb27SDimitry Andric
779*06c3fb27SDimitry Andric      __guard.__complete();
780*06c3fb27SDimitry Andric    }
781*06c3fb27SDimitry Andric
782*06c3fb27SDimitry Andric    template <class _InputIterator, class _Sentinel>
783*06c3fb27SDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
784*06c3fb27SDimitry Andric    void __init_with_sentinel(_InputIterator __first, _Sentinel __last) {
785*06c3fb27SDimitry Andric      auto __guard = std::__make_exception_guard(__destroy_vector(*this));
786*06c3fb27SDimitry Andric
787*06c3fb27SDimitry Andric      for (; __first != __last; ++__first)
788*06c3fb27SDimitry Andric        emplace_back(*__first);
789*06c3fb27SDimitry Andric
790*06c3fb27SDimitry Andric      __guard.__complete();
791*06c3fb27SDimitry Andric    }
792*06c3fb27SDimitry Andric
793*06c3fb27SDimitry Andric    template <class _Iterator, class _Sentinel>
794*06c3fb27SDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
795*06c3fb27SDimitry Andric    void __assign_with_sentinel(_Iterator __first, _Sentinel __last);
796*06c3fb27SDimitry Andric
797*06c3fb27SDimitry Andric    template <class _ForwardIterator, class _Sentinel>
798*06c3fb27SDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
799*06c3fb27SDimitry Andric    void __assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __n);
800*06c3fb27SDimitry Andric
801*06c3fb27SDimitry Andric    template <class _InputIterator, class _Sentinel>
802*06c3fb27SDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
803*06c3fb27SDimitry Andric    iterator __insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last);
804*06c3fb27SDimitry Andric
805*06c3fb27SDimitry Andric    template <class _Iterator, class _Sentinel>
806*06c3fb27SDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
807*06c3fb27SDimitry Andric    iterator __insert_with_size(const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n);
808*06c3fb27SDimitry Andric
809*06c3fb27SDimitry Andric    template <class _InputIterator, class _Sentinel>
810*06c3fb27SDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
811*06c3fb27SDimitry Andric    void __construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n);
812bdd1243dSDimitry Andric
813bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __append(size_type __n);
814bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __append(size_type __n, const_reference __x);
815bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
816*06c3fb27SDimitry Andric    iterator       __make_iter(pointer __p) _NOEXCEPT { return iterator(__p); }
817bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
818*06c3fb27SDimitry Andric    const_iterator __make_iter(const_pointer __p) const _NOEXCEPT { return const_iterator(__p); }
819bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
820bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
821bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_range(pointer __from_s, pointer __from_e, pointer __to);
822bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, true_type)
8230b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
824bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, false_type)
8250b57cec5SDimitry Andric        _NOEXCEPT_(__alloc_traits::is_always_equal::value);
826bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
8270b57cec5SDimitry Andric    void __destruct_at_end(pointer __new_last) _NOEXCEPT
8280b57cec5SDimitry Andric    {
8290b57cec5SDimitry Andric        size_type __old_size = size();
830349cc55cSDimitry Andric        __base_destruct_at_end(__new_last);
8310b57cec5SDimitry Andric        __annotate_shrink(__old_size);
8320b57cec5SDimitry Andric    }
8330b57cec5SDimitry Andric
8340b57cec5SDimitry Andric    template <class _Up>
835bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
8360b57cec5SDimitry Andric    inline void __push_back_slow_path(_Up&& __x);
8370b57cec5SDimitry Andric
8380b57cec5SDimitry Andric    template <class... _Args>
839bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
8400b57cec5SDimitry Andric    inline void __emplace_back_slow_path(_Args&&... __args);
8410b57cec5SDimitry Andric
8420b57cec5SDimitry Andric    // The following functions are no-ops outside of AddressSanitizer mode.
843*06c3fb27SDimitry Andric    // We call annotations for every allocator, unless explicitly disabled.
844*06c3fb27SDimitry Andric    //
845*06c3fb27SDimitry Andric    // To disable annotations for a particular allocator, change value of
846*06c3fb27SDimitry Andric    // __asan_annotate_container_with_allocator to false.
847*06c3fb27SDimitry Andric    // For more details, see the "Using libc++" documentation page or
848*06c3fb27SDimitry Andric    // the documentation for __sanitizer_annotate_contiguous_container.
8490b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
850bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20
8510b57cec5SDimitry Andric    void __annotate_contiguous_container(const void *__beg, const void *__end,
8520b57cec5SDimitry Andric                                         const void *__old_mid,
8530b57cec5SDimitry Andric                                         const void *__new_mid) const
8540b57cec5SDimitry Andric    {
855*06c3fb27SDimitry Andric      if (!__libcpp_is_constant_evaluated() && __beg != nullptr && __asan_annotate_container_with_allocator<_Allocator>::value)
8560b57cec5SDimitry Andric        __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
8570b57cec5SDimitry Andric    }
8580b57cec5SDimitry Andric#else
859bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
8600b57cec5SDimitry Andric    void __annotate_contiguous_container(const void*, const void*, const void*,
861e40139ffSDimitry Andric                                         const void*) const _NOEXCEPT {}
8620b57cec5SDimitry Andric#endif
863bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
864e40139ffSDimitry Andric    void __annotate_new(size_type __current_size) const _NOEXCEPT {
8650b57cec5SDimitry Andric      __annotate_contiguous_container(data(), data() + capacity(),
8660b57cec5SDimitry Andric                                      data() + capacity(), data() + __current_size);
8670b57cec5SDimitry Andric    }
8680b57cec5SDimitry Andric
869bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
870e40139ffSDimitry Andric    void __annotate_delete() const _NOEXCEPT {
8710b57cec5SDimitry Andric      __annotate_contiguous_container(data(), data() + capacity(),
8720b57cec5SDimitry Andric                                      data() + size(), data() + capacity());
8730b57cec5SDimitry Andric    }
8740b57cec5SDimitry Andric
875bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
876e40139ffSDimitry Andric    void __annotate_increase(size_type __n) const _NOEXCEPT
8770b57cec5SDimitry Andric    {
8780b57cec5SDimitry Andric      __annotate_contiguous_container(data(), data() + capacity(),
8790b57cec5SDimitry Andric                                      data() + size(), data() + size() + __n);
8800b57cec5SDimitry Andric    }
8810b57cec5SDimitry Andric
882bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
883e40139ffSDimitry Andric    void __annotate_shrink(size_type __old_size) const _NOEXCEPT
8840b57cec5SDimitry Andric    {
8850b57cec5SDimitry Andric      __annotate_contiguous_container(data(), data() + capacity(),
8860b57cec5SDimitry Andric                                      data() + __old_size, data() + size());
8870b57cec5SDimitry Andric    }
8880b57cec5SDimitry Andric
889e40139ffSDimitry Andric  struct _ConstructTransaction {
890bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
891e40139ffSDimitry Andric    explicit _ConstructTransaction(vector &__v, size_type __n)
892e40139ffSDimitry Andric      : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) {
893e40139ffSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
894e40139ffSDimitry Andric      __v_.__annotate_increase(__n);
895e40139ffSDimitry Andric#endif
896e40139ffSDimitry Andric    }
897bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI ~_ConstructTransaction() {
898e40139ffSDimitry Andric      __v_.__end_ = __pos_;
899e40139ffSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
900e40139ffSDimitry Andric      if (__pos_ != __new_end_) {
901e40139ffSDimitry Andric        __v_.__annotate_shrink(__new_end_ - __v_.__begin_);
902e40139ffSDimitry Andric      }
903e40139ffSDimitry Andric#endif
904e40139ffSDimitry Andric    }
905e40139ffSDimitry Andric
906e40139ffSDimitry Andric    vector &__v_;
907e40139ffSDimitry Andric    pointer __pos_;
908e40139ffSDimitry Andric    const_pointer const __new_end_;
909e40139ffSDimitry Andric
910e40139ffSDimitry Andric  private:
911e40139ffSDimitry Andric    _ConstructTransaction(_ConstructTransaction const&) = delete;
912e40139ffSDimitry Andric    _ConstructTransaction& operator=(_ConstructTransaction const&) = delete;
913e40139ffSDimitry Andric  };
914e40139ffSDimitry Andric
915e40139ffSDimitry Andric  template <class ..._Args>
916bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
917e40139ffSDimitry Andric  void __construct_one_at_end(_Args&& ...__args) {
918e40139ffSDimitry Andric    _ConstructTransaction __tx(*this, 1);
919bdd1243dSDimitry Andric    __alloc_traits::construct(this->__alloc(), std::__to_address(__tx.__pos_),
920bdd1243dSDimitry Andric        std::forward<_Args>(__args)...);
921e40139ffSDimitry Andric    ++__tx.__pos_;
922e40139ffSDimitry Andric  }
923349cc55cSDimitry Andric
924bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
925349cc55cSDimitry Andric  allocator_type& __alloc() _NOEXCEPT
926349cc55cSDimitry Andric      {return this->__end_cap_.second();}
927bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
928349cc55cSDimitry Andric  const allocator_type& __alloc() const _NOEXCEPT
929349cc55cSDimitry Andric      {return this->__end_cap_.second();}
930bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
931349cc55cSDimitry Andric  pointer& __end_cap() _NOEXCEPT
932349cc55cSDimitry Andric      {return this->__end_cap_.first();}
933bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
934349cc55cSDimitry Andric  const pointer& __end_cap() const _NOEXCEPT
935349cc55cSDimitry Andric      {return this->__end_cap_.first();}
936349cc55cSDimitry Andric
937bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
938349cc55cSDimitry Andric  void __clear() _NOEXCEPT {__base_destruct_at_end(this->__begin_);}
939349cc55cSDimitry Andric
940bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
941349cc55cSDimitry Andric  void __base_destruct_at_end(pointer __new_last) _NOEXCEPT {
942349cc55cSDimitry Andric    pointer __soon_to_be_end = this->__end_;
943349cc55cSDimitry Andric    while (__new_last != __soon_to_be_end)
944bdd1243dSDimitry Andric        __alloc_traits::destroy(__alloc(), std::__to_address(--__soon_to_be_end));
945349cc55cSDimitry Andric    this->__end_ = __new_last;
946349cc55cSDimitry Andric  }
947349cc55cSDimitry Andric
948bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
949349cc55cSDimitry Andric  void __copy_assign_alloc(const vector& __c)
950349cc55cSDimitry Andric      {__copy_assign_alloc(__c, integral_constant<bool,
951349cc55cSDimitry Andric                    __alloc_traits::propagate_on_container_copy_assignment::value>());}
952349cc55cSDimitry Andric
953bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
954349cc55cSDimitry Andric  void __move_assign_alloc(vector& __c)
955349cc55cSDimitry Andric      _NOEXCEPT_(
956349cc55cSDimitry Andric          !__alloc_traits::propagate_on_container_move_assignment::value ||
957349cc55cSDimitry Andric          is_nothrow_move_assignable<allocator_type>::value)
958349cc55cSDimitry Andric      {__move_assign_alloc(__c, integral_constant<bool,
959349cc55cSDimitry Andric                    __alloc_traits::propagate_on_container_move_assignment::value>());}
960349cc55cSDimitry Andric
961349cc55cSDimitry Andric  _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
962349cc55cSDimitry Andric  void __throw_length_error() const {
963bdd1243dSDimitry Andric      std::__throw_length_error("vector");
964349cc55cSDimitry Andric  }
965349cc55cSDimitry Andric
966349cc55cSDimitry Andric  _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
967349cc55cSDimitry Andric  void __throw_out_of_range() const {
968bdd1243dSDimitry Andric      std::__throw_out_of_range("vector");
969349cc55cSDimitry Andric  }
970349cc55cSDimitry Andric
971bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
972349cc55cSDimitry Andric  void __copy_assign_alloc(const vector& __c, true_type)
973349cc55cSDimitry Andric  {
974349cc55cSDimitry Andric    if (__alloc() != __c.__alloc())
975349cc55cSDimitry Andric    {
976349cc55cSDimitry Andric      __clear();
977*06c3fb27SDimitry Andric      __annotate_delete();
978349cc55cSDimitry Andric      __alloc_traits::deallocate(__alloc(), this->__begin_, capacity());
979349cc55cSDimitry Andric      this->__begin_ = this->__end_ = __end_cap() = nullptr;
980349cc55cSDimitry Andric    }
981349cc55cSDimitry Andric    __alloc() = __c.__alloc();
982349cc55cSDimitry Andric  }
983349cc55cSDimitry Andric
984bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
985349cc55cSDimitry Andric  void __copy_assign_alloc(const vector&, false_type)
986349cc55cSDimitry Andric  {}
987349cc55cSDimitry Andric
988bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
989349cc55cSDimitry Andric  void __move_assign_alloc(vector& __c, true_type)
990349cc55cSDimitry Andric      _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
991349cc55cSDimitry Andric  {
992bdd1243dSDimitry Andric    __alloc() = std::move(__c.__alloc());
993349cc55cSDimitry Andric  }
994349cc55cSDimitry Andric
995bdd1243dSDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
996349cc55cSDimitry Andric  void __move_assign_alloc(vector&, false_type)
997349cc55cSDimitry Andric      _NOEXCEPT
998349cc55cSDimitry Andric  {}
9990b57cec5SDimitry Andric};
10000b57cec5SDimitry Andric
1001349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17
10020b57cec5SDimitry Andrictemplate<class _InputIterator,
1003fe6060f1SDimitry Andric         class _Alloc = allocator<__iter_value_type<_InputIterator>>,
1004*06c3fb27SDimitry Andric         class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
1005349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Alloc>::value>
10060b57cec5SDimitry Andric         >
10070b57cec5SDimitry Andricvector(_InputIterator, _InputIterator)
1008fe6060f1SDimitry Andric  -> vector<__iter_value_type<_InputIterator>, _Alloc>;
10090b57cec5SDimitry Andric
10100b57cec5SDimitry Andrictemplate<class _InputIterator,
10110b57cec5SDimitry Andric         class _Alloc,
1012*06c3fb27SDimitry Andric         class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
1013349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Alloc>::value>
10140b57cec5SDimitry Andric         >
10150b57cec5SDimitry Andricvector(_InputIterator, _InputIterator, _Alloc)
1016fe6060f1SDimitry Andric  -> vector<__iter_value_type<_InputIterator>, _Alloc>;
10170b57cec5SDimitry Andric#endif
10180b57cec5SDimitry Andric
1019*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
1020*06c3fb27SDimitry Andrictemplate <ranges::input_range _Range,
1021*06c3fb27SDimitry Andric          class _Alloc = allocator<ranges::range_value_t<_Range>>,
1022*06c3fb27SDimitry Andric          class = enable_if_t<__is_allocator<_Alloc>::value>
1023*06c3fb27SDimitry Andric          >
1024*06c3fb27SDimitry Andricvector(from_range_t, _Range&&, _Alloc = _Alloc())
1025*06c3fb27SDimitry Andric  -> vector<ranges::range_value_t<_Range>, _Alloc>;
1026*06c3fb27SDimitry Andric#endif
1027*06c3fb27SDimitry Andric
10280b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1029bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
10300b57cec5SDimitry Andricvoid
10310b57cec5SDimitry Andricvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
10320b57cec5SDimitry Andric{
10330b57cec5SDimitry Andric    __annotate_delete();
1034972a253aSDimitry Andric    using _RevIter = std::reverse_iterator<pointer>;
1035972a253aSDimitry Andric    __v.__begin_   = std::__uninitialized_allocator_move_if_noexcept(
1036972a253aSDimitry Andric                       __alloc(), _RevIter(__end_), _RevIter(__begin_), _RevIter(__v.__begin_))
1037972a253aSDimitry Andric                       .base();
1038bdd1243dSDimitry Andric    std::swap(this->__begin_, __v.__begin_);
1039bdd1243dSDimitry Andric    std::swap(this->__end_, __v.__end_);
1040bdd1243dSDimitry Andric    std::swap(this->__end_cap(), __v.__end_cap());
10410b57cec5SDimitry Andric    __v.__first_ = __v.__begin_;
10420b57cec5SDimitry Andric    __annotate_new(size());
10430b57cec5SDimitry Andric}
10440b57cec5SDimitry Andric
10450b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1046bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
10470b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::pointer
10480b57cec5SDimitry Andricvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
10490b57cec5SDimitry Andric{
10500b57cec5SDimitry Andric    __annotate_delete();
10510b57cec5SDimitry Andric    pointer __r = __v.__begin_;
1052972a253aSDimitry Andric    using _RevIter = std::reverse_iterator<pointer>;
1053972a253aSDimitry Andric    __v.__begin_   = std::__uninitialized_allocator_move_if_noexcept(
1054972a253aSDimitry Andric                       __alloc(), _RevIter(__p), _RevIter(__begin_), _RevIter(__v.__begin_))
1055972a253aSDimitry Andric                       .base();
1056972a253aSDimitry Andric    __v.__end_ = std::__uninitialized_allocator_move_if_noexcept(__alloc(), __p, __end_, __v.__end_);
1057bdd1243dSDimitry Andric    std::swap(this->__begin_, __v.__begin_);
1058bdd1243dSDimitry Andric    std::swap(this->__end_, __v.__end_);
1059bdd1243dSDimitry Andric    std::swap(this->__end_cap(), __v.__end_cap());
10600b57cec5SDimitry Andric    __v.__first_ = __v.__begin_;
10610b57cec5SDimitry Andric    __annotate_new(size());
10620b57cec5SDimitry Andric    return __r;
10630b57cec5SDimitry Andric}
10640b57cec5SDimitry Andric
10650b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1066bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
10670b57cec5SDimitry Andricvoid
10680b57cec5SDimitry Andricvector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT
10690b57cec5SDimitry Andric{
10700b57cec5SDimitry Andric    if (this->__begin_ != nullptr)
10710b57cec5SDimitry Andric    {
10720b57cec5SDimitry Andric        clear();
1073*06c3fb27SDimitry Andric        __annotate_delete();
10740b57cec5SDimitry Andric        __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
10750b57cec5SDimitry Andric        this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
10760b57cec5SDimitry Andric    }
10770b57cec5SDimitry Andric}
10780b57cec5SDimitry Andric
10790b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1080bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
10810b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::size_type
10820b57cec5SDimitry Andricvector<_Tp, _Allocator>::max_size() const _NOEXCEPT
10830b57cec5SDimitry Andric{
1084bdd1243dSDimitry Andric    return std::min<size_type>(__alloc_traits::max_size(this->__alloc()),
10850b57cec5SDimitry Andric                                 numeric_limits<difference_type>::max());
10860b57cec5SDimitry Andric}
10870b57cec5SDimitry Andric
10880b57cec5SDimitry Andric//  Precondition:  __new_size > capacity()
10890b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1090bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
1091bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
10920b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::size_type
10930b57cec5SDimitry Andricvector<_Tp, _Allocator>::__recommend(size_type __new_size) const
10940b57cec5SDimitry Andric{
10950b57cec5SDimitry Andric    const size_type __ms = max_size();
10960b57cec5SDimitry Andric    if (__new_size > __ms)
10970b57cec5SDimitry Andric        this->__throw_length_error();
10980b57cec5SDimitry Andric    const size_type __cap = capacity();
10990b57cec5SDimitry Andric    if (__cap >= __ms / 2)
11000b57cec5SDimitry Andric        return __ms;
1101bdd1243dSDimitry Andric    return std::max<size_type>(2 * __cap, __new_size);
11020b57cec5SDimitry Andric}
11030b57cec5SDimitry Andric
11040b57cec5SDimitry Andric//  Default constructs __n objects starting at __end_
11050b57cec5SDimitry Andric//  throws if construction throws
11060b57cec5SDimitry Andric//  Precondition:  __n > 0
11070b57cec5SDimitry Andric//  Precondition:  size() + __n <= capacity()
11080b57cec5SDimitry Andric//  Postcondition:  size() == size() + __n
11090b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1110bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
11110b57cec5SDimitry Andricvoid
11120b57cec5SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(size_type __n)
11130b57cec5SDimitry Andric{
1114e40139ffSDimitry Andric    _ConstructTransaction __tx(*this, __n);
11155ffd83dbSDimitry Andric    const_pointer __new_end = __tx.__new_end_;
1116349cc55cSDimitry Andric    for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
1117bdd1243dSDimitry Andric        __alloc_traits::construct(this->__alloc(), std::__to_address(__pos));
1118e40139ffSDimitry Andric    }
11190b57cec5SDimitry Andric}
11200b57cec5SDimitry Andric
11210b57cec5SDimitry Andric//  Copy constructs __n objects starting at __end_ from __x
11220b57cec5SDimitry Andric//  throws if construction throws
11230b57cec5SDimitry Andric//  Precondition:  __n > 0
11240b57cec5SDimitry Andric//  Precondition:  size() + __n <= capacity()
11250b57cec5SDimitry Andric//  Postcondition:  size() == old size() + __n
11260b57cec5SDimitry Andric//  Postcondition:  [i] == __x for all i in [size() - __n, __n)
11270b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1128bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
11290b57cec5SDimitry Andricinline
11300b57cec5SDimitry Andricvoid
11310b57cec5SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
11320b57cec5SDimitry Andric{
1133e40139ffSDimitry Andric    _ConstructTransaction __tx(*this, __n);
11345ffd83dbSDimitry Andric    const_pointer __new_end = __tx.__new_end_;
1135349cc55cSDimitry Andric    for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
1136bdd1243dSDimitry Andric        __alloc_traits::construct(this->__alloc(), std::__to_address(__pos), __x);
1137e40139ffSDimitry Andric    }
11380b57cec5SDimitry Andric}
11390b57cec5SDimitry Andric
11400b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1141*06c3fb27SDimitry Andrictemplate <class _InputIterator, class _Sentinel>
1142bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void
1143*06c3fb27SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) {
1144e40139ffSDimitry Andric  _ConstructTransaction __tx(*this, __n);
1145972a253aSDimitry Andric  __tx.__pos_ = std::__uninitialized_allocator_copy(__alloc(), __first, __last, __tx.__pos_);
11460b57cec5SDimitry Andric}
11470b57cec5SDimitry Andric
11480b57cec5SDimitry Andric//  Default constructs __n objects starting at __end_
11490b57cec5SDimitry Andric//  throws if construction throws
11500b57cec5SDimitry Andric//  Postcondition:  size() == size() + __n
11510b57cec5SDimitry Andric//  Exception safety: strong.
11520b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1153bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
11540b57cec5SDimitry Andricvoid
11550b57cec5SDimitry Andricvector<_Tp, _Allocator>::__append(size_type __n)
11560b57cec5SDimitry Andric{
11570b57cec5SDimitry Andric    if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
11580b57cec5SDimitry Andric        this->__construct_at_end(__n);
11590b57cec5SDimitry Andric    else
11600b57cec5SDimitry Andric    {
11610b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
11620b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
11630b57cec5SDimitry Andric        __v.__construct_at_end(__n);
11640b57cec5SDimitry Andric        __swap_out_circular_buffer(__v);
11650b57cec5SDimitry Andric    }
11660b57cec5SDimitry Andric}
11670b57cec5SDimitry Andric
11680b57cec5SDimitry Andric//  Default constructs __n objects starting at __end_
11690b57cec5SDimitry Andric//  throws if construction throws
11700b57cec5SDimitry Andric//  Postcondition:  size() == size() + __n
11710b57cec5SDimitry Andric//  Exception safety: strong.
11720b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1173bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
11740b57cec5SDimitry Andricvoid
11750b57cec5SDimitry Andricvector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
11760b57cec5SDimitry Andric{
11770b57cec5SDimitry Andric    if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
11780b57cec5SDimitry Andric        this->__construct_at_end(__n, __x);
11790b57cec5SDimitry Andric    else
11800b57cec5SDimitry Andric    {
11810b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
11820b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
11830b57cec5SDimitry Andric        __v.__construct_at_end(__n, __x);
11840b57cec5SDimitry Andric        __swap_out_circular_buffer(__v);
11850b57cec5SDimitry Andric    }
11860b57cec5SDimitry Andric}
11870b57cec5SDimitry Andric
11880b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1189bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
11900b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n)
11910b57cec5SDimitry Andric{
1192bdd1243dSDimitry Andric    auto __guard = std::__make_exception_guard(__destroy_vector(*this));
11930b57cec5SDimitry Andric    if (__n > 0)
11940b57cec5SDimitry Andric    {
11950b57cec5SDimitry Andric        __vallocate(__n);
11960b57cec5SDimitry Andric        __construct_at_end(__n);
11970b57cec5SDimitry Andric    }
119850d7464cSDimitry Andric    __guard.__complete();
11990b57cec5SDimitry Andric}
12000b57cec5SDimitry Andric
1201*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
12020b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1203bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
12040b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
1205d56accc7SDimitry Andric    : __end_cap_(nullptr, __a)
12060b57cec5SDimitry Andric{
1207bdd1243dSDimitry Andric    auto __guard = std::__make_exception_guard(__destroy_vector(*this));
12080b57cec5SDimitry Andric    if (__n > 0)
12090b57cec5SDimitry Andric    {
12100b57cec5SDimitry Andric        __vallocate(__n);
12110b57cec5SDimitry Andric        __construct_at_end(__n);
12120b57cec5SDimitry Andric    }
121350d7464cSDimitry Andric    __guard.__complete();
12140b57cec5SDimitry Andric}
12150b57cec5SDimitry Andric#endif
12160b57cec5SDimitry Andric
12170b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1218bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
12190b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x)
12200b57cec5SDimitry Andric{
1221bdd1243dSDimitry Andric    auto __guard = std::__make_exception_guard(__destroy_vector(*this));
12220b57cec5SDimitry Andric    if (__n > 0)
12230b57cec5SDimitry Andric    {
12240b57cec5SDimitry Andric        __vallocate(__n);
12250b57cec5SDimitry Andric        __construct_at_end(__n, __x);
12260b57cec5SDimitry Andric    }
122750d7464cSDimitry Andric    __guard.__complete();
12280b57cec5SDimitry Andric}
12290b57cec5SDimitry Andric
12300b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1231*06c3fb27SDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
1232bdd1243dSDimitry Andric                              is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
1233bdd1243dSDimitry Andric                          int> >
1234bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
1235bdd1243dSDimitry Andricvector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last)
12360b57cec5SDimitry Andric{
1237*06c3fb27SDimitry Andric  __init_with_sentinel(__first, __last);
12380b57cec5SDimitry Andric}
12390b57cec5SDimitry Andric
12400b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1241*06c3fb27SDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
1242bdd1243dSDimitry Andric                              is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
1243bdd1243dSDimitry Andric                          int> >
1244bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
1245bdd1243dSDimitry Andricvector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a)
1246d56accc7SDimitry Andric    : __end_cap_(nullptr, __a)
12470b57cec5SDimitry Andric{
1248*06c3fb27SDimitry Andric  __init_with_sentinel(__first, __last);
12490b57cec5SDimitry Andric}
12500b57cec5SDimitry Andric
12510b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1252*06c3fb27SDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
1253bdd1243dSDimitry Andric                        is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
1254bdd1243dSDimitry Andric                    int> >
1255bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
1256bdd1243dSDimitry Andricvector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last)
12570b57cec5SDimitry Andric{
125850d7464cSDimitry Andric  size_type __n = static_cast<size_type>(std::distance(__first, __last));
1259*06c3fb27SDimitry Andric  __init_with_size(__first, __last, __n);
12600b57cec5SDimitry Andric}
12610b57cec5SDimitry Andric
12620b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1263*06c3fb27SDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
1264bdd1243dSDimitry Andric                        is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
1265bdd1243dSDimitry Andric                    int> >
1266bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
1267bdd1243dSDimitry Andricvector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a)
1268d56accc7SDimitry Andric    : __end_cap_(nullptr, __a)
12690b57cec5SDimitry Andric{
127050d7464cSDimitry Andric  size_type __n = static_cast<size_type>(std::distance(__first, __last));
1271*06c3fb27SDimitry Andric  __init_with_size(__first, __last, __n);
12720b57cec5SDimitry Andric}
12730b57cec5SDimitry Andric
12740b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1275bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
12760b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(const vector& __x)
1277d56accc7SDimitry Andric    : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc()))
12780b57cec5SDimitry Andric{
1279*06c3fb27SDimitry Andric  __init_with_size(__x.__begin_, __x.__end_, __x.size());
12800b57cec5SDimitry Andric}
12810b57cec5SDimitry Andric
12820b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1283bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
128481ad6265SDimitry Andricvector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
1285d56accc7SDimitry Andric    : __end_cap_(nullptr, __a)
12860b57cec5SDimitry Andric{
1287*06c3fb27SDimitry Andric  __init_with_size(__x.__begin_, __x.__end_, __x.size());
12880b57cec5SDimitry Andric}
12890b57cec5SDimitry Andric
12900b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1291bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
1292bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
12930b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(vector&& __x)
1294*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
129581ad6265SDimitry Andric        noexcept
12960b57cec5SDimitry Andric#else
12970b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
12980b57cec5SDimitry Andric#endif
1299bdd1243dSDimitry Andric    : __end_cap_(nullptr, std::move(__x.__alloc()))
13000b57cec5SDimitry Andric{
13010b57cec5SDimitry Andric    this->__begin_ = __x.__begin_;
13020b57cec5SDimitry Andric    this->__end_ = __x.__end_;
13030b57cec5SDimitry Andric    this->__end_cap() = __x.__end_cap();
13040b57cec5SDimitry Andric    __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
13050b57cec5SDimitry Andric}
13060b57cec5SDimitry Andric
13070b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1308bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
1309bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
131081ad6265SDimitry Andricvector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_type>& __a)
1311d56accc7SDimitry Andric    : __end_cap_(nullptr, __a)
13120b57cec5SDimitry Andric{
13130b57cec5SDimitry Andric    if (__a == __x.__alloc())
13140b57cec5SDimitry Andric    {
13150b57cec5SDimitry Andric        this->__begin_ = __x.__begin_;
13160b57cec5SDimitry Andric        this->__end_ = __x.__end_;
13170b57cec5SDimitry Andric        this->__end_cap() = __x.__end_cap();
13180b57cec5SDimitry Andric        __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
13190b57cec5SDimitry Andric    }
13200b57cec5SDimitry Andric    else
13210b57cec5SDimitry Andric    {
13220b57cec5SDimitry Andric        typedef move_iterator<iterator> _Ip;
1323bdd1243dSDimitry Andric        auto __guard = std::__make_exception_guard(__destroy_vector(*this));
13240b57cec5SDimitry Andric        assign(_Ip(__x.begin()), _Ip(__x.end()));
132550d7464cSDimitry Andric        __guard.__complete();
13260b57cec5SDimitry Andric    }
13270b57cec5SDimitry Andric}
13280b57cec5SDimitry Andric
132981ad6265SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
133081ad6265SDimitry Andric
13310b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1332bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
1333bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
13340b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
13350b57cec5SDimitry Andric{
1336bdd1243dSDimitry Andric    auto __guard = std::__make_exception_guard(__destroy_vector(*this));
13370b57cec5SDimitry Andric    if (__il.size() > 0)
13380b57cec5SDimitry Andric    {
13390b57cec5SDimitry Andric        __vallocate(__il.size());
13400b57cec5SDimitry Andric        __construct_at_end(__il.begin(), __il.end(), __il.size());
13410b57cec5SDimitry Andric    }
134250d7464cSDimitry Andric    __guard.__complete();
13430b57cec5SDimitry Andric}
13440b57cec5SDimitry Andric
13450b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1346bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
1347bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
13480b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1349d56accc7SDimitry Andric    : __end_cap_(nullptr, __a)
13500b57cec5SDimitry Andric{
1351bdd1243dSDimitry Andric    auto __guard = std::__make_exception_guard(__destroy_vector(*this));
13520b57cec5SDimitry Andric    if (__il.size() > 0)
13530b57cec5SDimitry Andric    {
13540b57cec5SDimitry Andric        __vallocate(__il.size());
13550b57cec5SDimitry Andric        __construct_at_end(__il.begin(), __il.end(), __il.size());
13560b57cec5SDimitry Andric    }
135750d7464cSDimitry Andric    __guard.__complete();
13580b57cec5SDimitry Andric}
13590b57cec5SDimitry Andric
136081ad6265SDimitry Andric#endif // _LIBCPP_CXX03_LANG
136181ad6265SDimitry Andric
13620b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1363bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
1364bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
13650b57cec5SDimitry Andricvector<_Tp, _Allocator>&
13660b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator=(vector&& __x)
13670b57cec5SDimitry Andric    _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
13680b57cec5SDimitry Andric{
13690b57cec5SDimitry Andric    __move_assign(__x, integral_constant<bool,
13700b57cec5SDimitry Andric          __alloc_traits::propagate_on_container_move_assignment::value>());
13710b57cec5SDimitry Andric    return *this;
13720b57cec5SDimitry Andric}
13730b57cec5SDimitry Andric
13740b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1375bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
13760b57cec5SDimitry Andricvoid
13770b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
13780b57cec5SDimitry Andric    _NOEXCEPT_(__alloc_traits::is_always_equal::value)
13790b57cec5SDimitry Andric{
1380349cc55cSDimitry Andric    if (__alloc() != __c.__alloc())
13810b57cec5SDimitry Andric    {
13820b57cec5SDimitry Andric        typedef move_iterator<iterator> _Ip;
13830b57cec5SDimitry Andric        assign(_Ip(__c.begin()), _Ip(__c.end()));
13840b57cec5SDimitry Andric    }
13850b57cec5SDimitry Andric    else
13860b57cec5SDimitry Andric        __move_assign(__c, true_type());
13870b57cec5SDimitry Andric}
13880b57cec5SDimitry Andric
13890b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1390bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
13910b57cec5SDimitry Andricvoid
13920b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
13930b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
13940b57cec5SDimitry Andric{
13950b57cec5SDimitry Andric    __vdeallocate();
1396349cc55cSDimitry Andric    __move_assign_alloc(__c); // this can throw
13970b57cec5SDimitry Andric    this->__begin_ = __c.__begin_;
13980b57cec5SDimitry Andric    this->__end_ = __c.__end_;
13990b57cec5SDimitry Andric    this->__end_cap() = __c.__end_cap();
14000b57cec5SDimitry Andric    __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
14010b57cec5SDimitry Andric}
14020b57cec5SDimitry Andric
14030b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1404bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
1405bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
14060b57cec5SDimitry Andricvector<_Tp, _Allocator>&
14070b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator=(const vector& __x)
14080b57cec5SDimitry Andric{
1409bdd1243dSDimitry Andric    if (this != std::addressof(__x))
14100b57cec5SDimitry Andric    {
1411349cc55cSDimitry Andric        __copy_assign_alloc(__x);
14120b57cec5SDimitry Andric        assign(__x.__begin_, __x.__end_);
14130b57cec5SDimitry Andric    }
14140b57cec5SDimitry Andric    return *this;
14150b57cec5SDimitry Andric}
14160b57cec5SDimitry Andric
14170b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1418*06c3fb27SDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
1419bdd1243dSDimitry Andric                              is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
1420bdd1243dSDimitry Andric                          int> >
1421bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void
14220b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
14230b57cec5SDimitry Andric{
1424*06c3fb27SDimitry Andric  __assign_with_sentinel(__first, __last);
1425*06c3fb27SDimitry Andric}
1426*06c3fb27SDimitry Andric
1427*06c3fb27SDimitry Andrictemplate <class _Tp, class _Allocator>
1428*06c3fb27SDimitry Andrictemplate <class _Iterator, class _Sentinel>
1429*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
1430*06c3fb27SDimitry Andricvoid vector<_Tp, _Allocator>::__assign_with_sentinel(_Iterator __first, _Sentinel __last) {
14310b57cec5SDimitry Andric    clear();
14320b57cec5SDimitry Andric    for (; __first != __last; ++__first)
143381ad6265SDimitry Andric        emplace_back(*__first);
14340b57cec5SDimitry Andric}
14350b57cec5SDimitry Andric
14360b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1437*06c3fb27SDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
1438bdd1243dSDimitry Andric                        is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
1439bdd1243dSDimitry Andric                    int> >
1440bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void
14410b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
14420b57cec5SDimitry Andric{
1443*06c3fb27SDimitry Andric  __assign_with_size(__first, __last, std::distance(__first, __last));
1444*06c3fb27SDimitry Andric}
1445*06c3fb27SDimitry Andric
1446*06c3fb27SDimitry Andrictemplate <class _Tp, class _Allocator>
1447*06c3fb27SDimitry Andrictemplate <class _ForwardIterator, class _Sentinel>
1448*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
1449*06c3fb27SDimitry Andricvoid vector<_Tp, _Allocator>::__assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __n) {
1450*06c3fb27SDimitry Andric    size_type __new_size = static_cast<size_type>(__n);
14510b57cec5SDimitry Andric    if (__new_size <= capacity())
14520b57cec5SDimitry Andric    {
14530b57cec5SDimitry Andric        if (__new_size > size())
14540b57cec5SDimitry Andric        {
1455*06c3fb27SDimitry Andric            _ForwardIterator __mid = std::next(__first, size());
1456*06c3fb27SDimitry Andric            std::copy(__first, __mid, this->__begin_);
14570b57cec5SDimitry Andric            __construct_at_end(__mid, __last, __new_size - size());
1458*06c3fb27SDimitry Andric        }
14590b57cec5SDimitry Andric        else
1460*06c3fb27SDimitry Andric        {
1461*06c3fb27SDimitry Andric            pointer __m = std::__copy<_ClassicAlgPolicy>(__first, __last, this->__begin_).second;
14620b57cec5SDimitry Andric            this->__destruct_at_end(__m);
14630b57cec5SDimitry Andric        }
1464*06c3fb27SDimitry Andric    }
14650b57cec5SDimitry Andric    else
14660b57cec5SDimitry Andric    {
14670b57cec5SDimitry Andric        __vdeallocate();
14680b57cec5SDimitry Andric        __vallocate(__recommend(__new_size));
14690b57cec5SDimitry Andric        __construct_at_end(__first, __last, __new_size);
14700b57cec5SDimitry Andric    }
14710b57cec5SDimitry Andric}
14720b57cec5SDimitry Andric
14730b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1474bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
14750b57cec5SDimitry Andricvoid
14760b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
14770b57cec5SDimitry Andric{
14780b57cec5SDimitry Andric    if (__n <= capacity())
14790b57cec5SDimitry Andric    {
14800b57cec5SDimitry Andric        size_type __s = size();
1481bdd1243dSDimitry Andric        std::fill_n(this->__begin_, std::min(__n, __s), __u);
14820b57cec5SDimitry Andric        if (__n > __s)
14830b57cec5SDimitry Andric            __construct_at_end(__n - __s, __u);
14840b57cec5SDimitry Andric        else
14850b57cec5SDimitry Andric            this->__destruct_at_end(this->__begin_ + __n);
14860b57cec5SDimitry Andric    }
14870b57cec5SDimitry Andric    else
14880b57cec5SDimitry Andric    {
14890b57cec5SDimitry Andric        __vdeallocate();
14900b57cec5SDimitry Andric        __vallocate(__recommend(static_cast<size_type>(__n)));
14910b57cec5SDimitry Andric        __construct_at_end(__n, __u);
14920b57cec5SDimitry Andric    }
14930b57cec5SDimitry Andric}
14940b57cec5SDimitry Andric
14950b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1496bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
1497bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
14980b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
14990b57cec5SDimitry Andricvector<_Tp, _Allocator>::begin() _NOEXCEPT
15000b57cec5SDimitry Andric{
1501bdd1243dSDimitry Andric    return __make_iter(this->__begin_);
15020b57cec5SDimitry Andric}
15030b57cec5SDimitry Andric
15040b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1505bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
1506bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
15070b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_iterator
15080b57cec5SDimitry Andricvector<_Tp, _Allocator>::begin() const _NOEXCEPT
15090b57cec5SDimitry Andric{
1510bdd1243dSDimitry Andric    return __make_iter(this->__begin_);
15110b57cec5SDimitry Andric}
15120b57cec5SDimitry Andric
15130b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1514bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
1515bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
15160b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
15170b57cec5SDimitry Andricvector<_Tp, _Allocator>::end() _NOEXCEPT
15180b57cec5SDimitry Andric{
1519bdd1243dSDimitry Andric    return __make_iter(this->__end_);
15200b57cec5SDimitry Andric}
15210b57cec5SDimitry Andric
15220b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1523bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
1524bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
15250b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_iterator
15260b57cec5SDimitry Andricvector<_Tp, _Allocator>::end() const _NOEXCEPT
15270b57cec5SDimitry Andric{
1528bdd1243dSDimitry Andric    return __make_iter(this->__end_);
15290b57cec5SDimitry Andric}
15300b57cec5SDimitry Andric
15310b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1532bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
1533bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
15340b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference
15350b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT
15360b57cec5SDimitry Andric{
1537*06c3fb27SDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < size(), "vector[] index out of bounds");
15380b57cec5SDimitry Andric    return this->__begin_[__n];
15390b57cec5SDimitry Andric}
15400b57cec5SDimitry Andric
15410b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1542bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
1543bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
15440b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_reference
15450b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT
15460b57cec5SDimitry Andric{
1547*06c3fb27SDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < size(), "vector[] index out of bounds");
15480b57cec5SDimitry Andric    return this->__begin_[__n];
15490b57cec5SDimitry Andric}
15500b57cec5SDimitry Andric
15510b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1552bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
15530b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference
15540b57cec5SDimitry Andricvector<_Tp, _Allocator>::at(size_type __n)
15550b57cec5SDimitry Andric{
15560b57cec5SDimitry Andric    if (__n >= size())
15570b57cec5SDimitry Andric        this->__throw_out_of_range();
15580b57cec5SDimitry Andric    return this->__begin_[__n];
15590b57cec5SDimitry Andric}
15600b57cec5SDimitry Andric
15610b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1562bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
15630b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_reference
15640b57cec5SDimitry Andricvector<_Tp, _Allocator>::at(size_type __n) const
15650b57cec5SDimitry Andric{
15660b57cec5SDimitry Andric    if (__n >= size())
15670b57cec5SDimitry Andric        this->__throw_out_of_range();
15680b57cec5SDimitry Andric    return this->__begin_[__n];
15690b57cec5SDimitry Andric}
15700b57cec5SDimitry Andric
15710b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1572bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
15730b57cec5SDimitry Andricvoid
15740b57cec5SDimitry Andricvector<_Tp, _Allocator>::reserve(size_type __n)
15750b57cec5SDimitry Andric{
15760b57cec5SDimitry Andric    if (__n > capacity())
15770b57cec5SDimitry Andric    {
1578349cc55cSDimitry Andric        if (__n > max_size())
1579349cc55cSDimitry Andric            this->__throw_length_error();
15800b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
15810b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
15820b57cec5SDimitry Andric        __swap_out_circular_buffer(__v);
15830b57cec5SDimitry Andric    }
15840b57cec5SDimitry Andric}
15850b57cec5SDimitry Andric
15860b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1587bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
15880b57cec5SDimitry Andricvoid
15890b57cec5SDimitry Andricvector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
15900b57cec5SDimitry Andric{
15910b57cec5SDimitry Andric    if (capacity() > size())
15920b57cec5SDimitry Andric    {
1593*06c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
15940b57cec5SDimitry Andric        try
15950b57cec5SDimitry Andric        {
1596*06c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
15970b57cec5SDimitry Andric            allocator_type& __a = this->__alloc();
15980b57cec5SDimitry Andric            __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
15990b57cec5SDimitry Andric            __swap_out_circular_buffer(__v);
1600*06c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
16010b57cec5SDimitry Andric        }
16020b57cec5SDimitry Andric        catch (...)
16030b57cec5SDimitry Andric        {
16040b57cec5SDimitry Andric        }
1605*06c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
16060b57cec5SDimitry Andric    }
16070b57cec5SDimitry Andric}
16080b57cec5SDimitry Andric
16090b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
16100b57cec5SDimitry Andrictemplate <class _Up>
1611bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
16120b57cec5SDimitry Andricvoid
16130b57cec5SDimitry Andricvector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
16140b57cec5SDimitry Andric{
16150b57cec5SDimitry Andric    allocator_type& __a = this->__alloc();
16160b57cec5SDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1617bdd1243dSDimitry Andric    // __v.push_back(std::forward<_Up>(__x));
1618bdd1243dSDimitry Andric    __alloc_traits::construct(__a, std::__to_address(__v.__end_), std::forward<_Up>(__x));
16190b57cec5SDimitry Andric    __v.__end_++;
16200b57cec5SDimitry Andric    __swap_out_circular_buffer(__v);
16210b57cec5SDimitry Andric}
16220b57cec5SDimitry Andric
16230b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1624bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
1625bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
16260b57cec5SDimitry Andricvoid
16270b57cec5SDimitry Andricvector<_Tp, _Allocator>::push_back(const_reference __x)
16280b57cec5SDimitry Andric{
16290b57cec5SDimitry Andric    if (this->__end_ != this->__end_cap())
16300b57cec5SDimitry Andric    {
1631e40139ffSDimitry Andric        __construct_one_at_end(__x);
16320b57cec5SDimitry Andric    }
16330b57cec5SDimitry Andric    else
16340b57cec5SDimitry Andric        __push_back_slow_path(__x);
16350b57cec5SDimitry Andric}
16360b57cec5SDimitry Andric
16370b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1638bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
1639bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
16400b57cec5SDimitry Andricvoid
16410b57cec5SDimitry Andricvector<_Tp, _Allocator>::push_back(value_type&& __x)
16420b57cec5SDimitry Andric{
16430b57cec5SDimitry Andric    if (this->__end_ < this->__end_cap())
16440b57cec5SDimitry Andric    {
1645bdd1243dSDimitry Andric        __construct_one_at_end(std::move(__x));
16460b57cec5SDimitry Andric    }
16470b57cec5SDimitry Andric    else
1648bdd1243dSDimitry Andric        __push_back_slow_path(std::move(__x));
16490b57cec5SDimitry Andric}
16500b57cec5SDimitry Andric
16510b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
16520b57cec5SDimitry Andrictemplate <class... _Args>
1653bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
16540b57cec5SDimitry Andricvoid
16550b57cec5SDimitry Andricvector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
16560b57cec5SDimitry Andric{
16570b57cec5SDimitry Andric    allocator_type& __a = this->__alloc();
16580b57cec5SDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1659bdd1243dSDimitry Andric//    __v.emplace_back(std::forward<_Args>(__args)...);
1660bdd1243dSDimitry Andric    __alloc_traits::construct(__a, std::__to_address(__v.__end_), std::forward<_Args>(__args)...);
16610b57cec5SDimitry Andric    __v.__end_++;
16620b57cec5SDimitry Andric    __swap_out_circular_buffer(__v);
16630b57cec5SDimitry Andric}
16640b57cec5SDimitry Andric
16650b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
16660b57cec5SDimitry Andrictemplate <class... _Args>
1667bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
16680b57cec5SDimitry Andricinline
1669*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
16700b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference
16710b57cec5SDimitry Andric#else
16720b57cec5SDimitry Andricvoid
16730b57cec5SDimitry Andric#endif
16740b57cec5SDimitry Andricvector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
16750b57cec5SDimitry Andric{
16760b57cec5SDimitry Andric    if (this->__end_ < this->__end_cap())
16770b57cec5SDimitry Andric    {
1678bdd1243dSDimitry Andric        __construct_one_at_end(std::forward<_Args>(__args)...);
16790b57cec5SDimitry Andric    }
16800b57cec5SDimitry Andric    else
1681bdd1243dSDimitry Andric        __emplace_back_slow_path(std::forward<_Args>(__args)...);
1682*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
16830b57cec5SDimitry Andric    return this->back();
16840b57cec5SDimitry Andric#endif
16850b57cec5SDimitry Andric}
16860b57cec5SDimitry Andric
16870b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1688bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
16890b57cec5SDimitry Andricinline
16900b57cec5SDimitry Andricvoid
16910b57cec5SDimitry Andricvector<_Tp, _Allocator>::pop_back()
16920b57cec5SDimitry Andric{
1693*06c3fb27SDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "vector::pop_back called on an empty vector");
16940b57cec5SDimitry Andric    this->__destruct_at_end(this->__end_ - 1);
16950b57cec5SDimitry Andric}
16960b57cec5SDimitry Andric
16970b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1698bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
1699bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
17000b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
17010b57cec5SDimitry Andricvector<_Tp, _Allocator>::erase(const_iterator __position)
17020b57cec5SDimitry Andric{
1703*06c3fb27SDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__position != end(),
17040b57cec5SDimitry Andric        "vector::erase(iterator) called with a non-dereferenceable iterator");
17050b57cec5SDimitry Andric    difference_type __ps = __position - cbegin();
17060b57cec5SDimitry Andric    pointer __p = this->__begin_ + __ps;
1707bdd1243dSDimitry Andric    this->__destruct_at_end(std::move(__p + 1, this->__end_, __p));
1708bdd1243dSDimitry Andric    return __make_iter(__p);
17090b57cec5SDimitry Andric}
17100b57cec5SDimitry Andric
17110b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1712bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
17130b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
17140b57cec5SDimitry Andricvector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
17150b57cec5SDimitry Andric{
1716*06c3fb27SDimitry Andric    _LIBCPP_ASSERT_VALID_INPUT_RANGE(__first <= __last, "vector::erase(first, last) called with invalid range");
17170b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__first - begin());
17180b57cec5SDimitry Andric    if (__first != __last) {
1719bdd1243dSDimitry Andric        this->__destruct_at_end(std::move(__p + (__last - __first), this->__end_, __p));
17200b57cec5SDimitry Andric    }
1721bdd1243dSDimitry Andric    return __make_iter(__p);
17220b57cec5SDimitry Andric}
17230b57cec5SDimitry Andric
17240b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1725bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
17260b57cec5SDimitry Andricvoid
17270b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
17280b57cec5SDimitry Andric{
17290b57cec5SDimitry Andric    pointer __old_last = this->__end_;
17300b57cec5SDimitry Andric    difference_type __n = __old_last - __to;
1731e40139ffSDimitry Andric    {
1732e40139ffSDimitry Andric      pointer __i = __from_s + __n;
1733e40139ffSDimitry Andric      _ConstructTransaction __tx(*this, __from_e - __i);
17345ffd83dbSDimitry Andric      for (pointer __pos = __tx.__pos_; __i < __from_e;
1735349cc55cSDimitry Andric           ++__i, (void) ++__pos, __tx.__pos_ = __pos) {
17360b57cec5SDimitry Andric          __alloc_traits::construct(this->__alloc(),
1737bdd1243dSDimitry Andric                                    std::__to_address(__pos),
1738bdd1243dSDimitry Andric                                    std::move(*__i));
1739e40139ffSDimitry Andric      }
1740e40139ffSDimitry Andric    }
1741bdd1243dSDimitry Andric    std::move_backward(__from_s, __from_s + __n, __old_last);
17420b57cec5SDimitry Andric}
17430b57cec5SDimitry Andric
17440b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1745bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
17460b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
17470b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
17480b57cec5SDimitry Andric{
17490b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__position - begin());
175061cfbce3SDimitry Andric    // We can't compare unrelated pointers inside constant expressions
175161cfbce3SDimitry Andric    if (!__libcpp_is_constant_evaluated() && this->__end_ < this->__end_cap())
17520b57cec5SDimitry Andric    {
17530b57cec5SDimitry Andric        if (__p == this->__end_)
17540b57cec5SDimitry Andric        {
1755e40139ffSDimitry Andric            __construct_one_at_end(__x);
17560b57cec5SDimitry Andric        }
17570b57cec5SDimitry Andric        else
17580b57cec5SDimitry Andric        {
17590b57cec5SDimitry Andric            __move_range(__p, this->__end_, __p + 1);
17600b57cec5SDimitry Andric            const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
17610b57cec5SDimitry Andric            if (__p <= __xr && __xr < this->__end_)
17620b57cec5SDimitry Andric                ++__xr;
17630b57cec5SDimitry Andric            *__p = *__xr;
17640b57cec5SDimitry Andric        }
17650b57cec5SDimitry Andric    }
17660b57cec5SDimitry Andric    else
17670b57cec5SDimitry Andric    {
17680b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
17690b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
17700b57cec5SDimitry Andric        __v.push_back(__x);
17710b57cec5SDimitry Andric        __p = __swap_out_circular_buffer(__v, __p);
17720b57cec5SDimitry Andric    }
1773bdd1243dSDimitry Andric    return __make_iter(__p);
17740b57cec5SDimitry Andric}
17750b57cec5SDimitry Andric
17760b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1777bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
17780b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
17790b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
17800b57cec5SDimitry Andric{
17810b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__position - begin());
17820b57cec5SDimitry Andric    if (this->__end_ < this->__end_cap())
17830b57cec5SDimitry Andric    {
17840b57cec5SDimitry Andric        if (__p == this->__end_)
17850b57cec5SDimitry Andric        {
1786bdd1243dSDimitry Andric            __construct_one_at_end(std::move(__x));
17870b57cec5SDimitry Andric        }
17880b57cec5SDimitry Andric        else
17890b57cec5SDimitry Andric        {
17900b57cec5SDimitry Andric            __move_range(__p, this->__end_, __p + 1);
1791bdd1243dSDimitry Andric            *__p = std::move(__x);
17920b57cec5SDimitry Andric        }
17930b57cec5SDimitry Andric    }
17940b57cec5SDimitry Andric    else
17950b57cec5SDimitry Andric    {
17960b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
17970b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1798bdd1243dSDimitry Andric        __v.push_back(std::move(__x));
17990b57cec5SDimitry Andric        __p = __swap_out_circular_buffer(__v, __p);
18000b57cec5SDimitry Andric    }
1801bdd1243dSDimitry Andric    return __make_iter(__p);
18020b57cec5SDimitry Andric}
18030b57cec5SDimitry Andric
18040b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
18050b57cec5SDimitry Andrictemplate <class... _Args>
1806bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
18070b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
18080b57cec5SDimitry Andricvector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
18090b57cec5SDimitry Andric{
18100b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__position - begin());
18110b57cec5SDimitry Andric    if (this->__end_ < this->__end_cap())
18120b57cec5SDimitry Andric    {
18130b57cec5SDimitry Andric        if (__p == this->__end_)
18140b57cec5SDimitry Andric        {
1815bdd1243dSDimitry Andric            __construct_one_at_end(std::forward<_Args>(__args)...);
18160b57cec5SDimitry Andric        }
18170b57cec5SDimitry Andric        else
18180b57cec5SDimitry Andric        {
1819bdd1243dSDimitry Andric            __temp_value<value_type, _Allocator> __tmp(this->__alloc(), std::forward<_Args>(__args)...);
18200b57cec5SDimitry Andric            __move_range(__p, this->__end_, __p + 1);
1821bdd1243dSDimitry Andric            *__p = std::move(__tmp.get());
18220b57cec5SDimitry Andric        }
18230b57cec5SDimitry Andric    }
18240b57cec5SDimitry Andric    else
18250b57cec5SDimitry Andric    {
18260b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
18270b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1828bdd1243dSDimitry Andric        __v.emplace_back(std::forward<_Args>(__args)...);
18290b57cec5SDimitry Andric        __p = __swap_out_circular_buffer(__v, __p);
18300b57cec5SDimitry Andric    }
1831bdd1243dSDimitry Andric    return __make_iter(__p);
18320b57cec5SDimitry Andric}
18330b57cec5SDimitry Andric
18340b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1835bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
18360b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
18370b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
18380b57cec5SDimitry Andric{
18390b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__position - begin());
18400b57cec5SDimitry Andric    if (__n > 0)
18410b57cec5SDimitry Andric    {
184261cfbce3SDimitry Andric        // We can't compare unrelated pointers inside constant expressions
184361cfbce3SDimitry Andric        if (!__libcpp_is_constant_evaluated() && __n <= static_cast<size_type>(this->__end_cap() - this->__end_))
18440b57cec5SDimitry Andric        {
18450b57cec5SDimitry Andric            size_type __old_n = __n;
18460b57cec5SDimitry Andric            pointer __old_last = this->__end_;
18470b57cec5SDimitry Andric            if (__n > static_cast<size_type>(this->__end_ - __p))
18480b57cec5SDimitry Andric            {
18490b57cec5SDimitry Andric                size_type __cx = __n - (this->__end_ - __p);
18500b57cec5SDimitry Andric                __construct_at_end(__cx, __x);
18510b57cec5SDimitry Andric                __n -= __cx;
18520b57cec5SDimitry Andric            }
18530b57cec5SDimitry Andric            if (__n > 0)
18540b57cec5SDimitry Andric            {
18550b57cec5SDimitry Andric                __move_range(__p, __old_last, __p + __old_n);
18560b57cec5SDimitry Andric                const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
18570b57cec5SDimitry Andric                if (__p <= __xr && __xr < this->__end_)
18580b57cec5SDimitry Andric                    __xr += __old_n;
1859bdd1243dSDimitry Andric                std::fill_n(__p, __n, *__xr);
18600b57cec5SDimitry Andric            }
18610b57cec5SDimitry Andric        }
18620b57cec5SDimitry Andric        else
18630b57cec5SDimitry Andric        {
18640b57cec5SDimitry Andric            allocator_type& __a = this->__alloc();
18650b57cec5SDimitry Andric            __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
18660b57cec5SDimitry Andric            __v.__construct_at_end(__n, __x);
18670b57cec5SDimitry Andric            __p = __swap_out_circular_buffer(__v, __p);
18680b57cec5SDimitry Andric        }
18690b57cec5SDimitry Andric    }
1870bdd1243dSDimitry Andric    return __make_iter(__p);
18710b57cec5SDimitry Andric}
18720b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1873*06c3fb27SDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
1874bdd1243dSDimitry Andric                              is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
1875bdd1243dSDimitry Andric                          int> >
1876bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
18770b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
18780b57cec5SDimitry Andric{
1879*06c3fb27SDimitry Andric  return __insert_with_sentinel(__position, __first, __last);
1880*06c3fb27SDimitry Andric}
1881*06c3fb27SDimitry Andric
1882*06c3fb27SDimitry Andrictemplate <class _Tp, class _Allocator>
1883*06c3fb27SDimitry Andrictemplate <class _InputIterator, class _Sentinel>
1884*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
1885*06c3fb27SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
1886*06c3fb27SDimitry Andricvector<_Tp, _Allocator>::__insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last) {
18870b57cec5SDimitry Andric    difference_type __off = __position - begin();
18880b57cec5SDimitry Andric    pointer __p = this->__begin_ + __off;
18890b57cec5SDimitry Andric    allocator_type& __a = this->__alloc();
18900b57cec5SDimitry Andric    pointer __old_last = this->__end_;
18910b57cec5SDimitry Andric    for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
18920b57cec5SDimitry Andric    {
1893e40139ffSDimitry Andric        __construct_one_at_end(*__first);
18940b57cec5SDimitry Andric    }
18950b57cec5SDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__a);
18960b57cec5SDimitry Andric    if (__first != __last)
18970b57cec5SDimitry Andric    {
1898*06c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
18990b57cec5SDimitry Andric        try
19000b57cec5SDimitry Andric        {
1901*06c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1902*06c3fb27SDimitry Andric            __v.__construct_at_end_with_sentinel(std::move(__first), std::move(__last));
19030b57cec5SDimitry Andric            difference_type __old_size = __old_last - this->__begin_;
19040b57cec5SDimitry Andric            difference_type __old_p = __p - this->__begin_;
19050b57cec5SDimitry Andric            reserve(__recommend(size() + __v.size()));
19060b57cec5SDimitry Andric            __p = this->__begin_ + __old_p;
19070b57cec5SDimitry Andric            __old_last = this->__begin_ + __old_size;
1908*06c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
19090b57cec5SDimitry Andric        }
19100b57cec5SDimitry Andric        catch (...)
19110b57cec5SDimitry Andric        {
1912bdd1243dSDimitry Andric            erase(__make_iter(__old_last), end());
19130b57cec5SDimitry Andric            throw;
19140b57cec5SDimitry Andric        }
1915*06c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
19160b57cec5SDimitry Andric    }
1917bdd1243dSDimitry Andric    __p = std::rotate(__p, __old_last, this->__end_);
1918bdd1243dSDimitry Andric    insert(__make_iter(__p), std::make_move_iterator(__v.begin()),
1919bdd1243dSDimitry Andric                             std::make_move_iterator(__v.end()));
19200b57cec5SDimitry Andric    return begin() + __off;
19210b57cec5SDimitry Andric}
19220b57cec5SDimitry Andric
19230b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1924*06c3fb27SDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
1925bdd1243dSDimitry Andric                        is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
1926bdd1243dSDimitry Andric                    int> >
1927bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<_Tp, _Allocator>::iterator
19280b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
19290b57cec5SDimitry Andric{
1930*06c3fb27SDimitry Andric  return __insert_with_size(__position, __first, __last, std::distance(__first, __last));
1931*06c3fb27SDimitry Andric}
1932*06c3fb27SDimitry Andric
1933*06c3fb27SDimitry Andrictemplate <class _Tp, class _Allocator>
1934*06c3fb27SDimitry Andrictemplate <class _Iterator, class _Sentinel>
1935*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
1936*06c3fb27SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
1937*06c3fb27SDimitry Andricvector<_Tp, _Allocator>::__insert_with_size(const_iterator __position, _Iterator __first, _Sentinel __last,
1938*06c3fb27SDimitry Andric                                            difference_type __n) {
1939*06c3fb27SDimitry Andric    auto __insertion_size = __n;
19400b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__position - begin());
19410b57cec5SDimitry Andric    if (__n > 0)
19420b57cec5SDimitry Andric    {
19430b57cec5SDimitry Andric        if (__n <= this->__end_cap() - this->__end_)
19440b57cec5SDimitry Andric        {
19450b57cec5SDimitry Andric            size_type __old_n = __n;
19460b57cec5SDimitry Andric            pointer __old_last = this->__end_;
1947*06c3fb27SDimitry Andric            _Iterator __m = std::next(__first, __n);
19480b57cec5SDimitry Andric            difference_type __dx = this->__end_ - __p;
19490b57cec5SDimitry Andric            if (__n > __dx)
19500b57cec5SDimitry Andric            {
19510b57cec5SDimitry Andric                __m = __first;
19520b57cec5SDimitry Andric                difference_type __diff = this->__end_ - __p;
1953bdd1243dSDimitry Andric                std::advance(__m, __diff);
19540b57cec5SDimitry Andric                __construct_at_end(__m, __last, __n - __diff);
19550b57cec5SDimitry Andric                __n = __dx;
19560b57cec5SDimitry Andric            }
19570b57cec5SDimitry Andric            if (__n > 0)
19580b57cec5SDimitry Andric            {
19590b57cec5SDimitry Andric                __move_range(__p, __old_last, __p + __old_n);
1960bdd1243dSDimitry Andric                std::copy(__first, __m, __p);
19610b57cec5SDimitry Andric            }
19620b57cec5SDimitry Andric        }
19630b57cec5SDimitry Andric        else
19640b57cec5SDimitry Andric        {
19650b57cec5SDimitry Andric            allocator_type& __a = this->__alloc();
19660b57cec5SDimitry Andric            __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1967*06c3fb27SDimitry Andric            __v.__construct_at_end_with_size(__first, __insertion_size);
19680b57cec5SDimitry Andric            __p = __swap_out_circular_buffer(__v, __p);
19690b57cec5SDimitry Andric        }
19700b57cec5SDimitry Andric    }
1971bdd1243dSDimitry Andric    return __make_iter(__p);
19720b57cec5SDimitry Andric}
19730b57cec5SDimitry Andric
19740b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1975bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
19760b57cec5SDimitry Andricvoid
19770b57cec5SDimitry Andricvector<_Tp, _Allocator>::resize(size_type __sz)
19780b57cec5SDimitry Andric{
19790b57cec5SDimitry Andric    size_type __cs = size();
19800b57cec5SDimitry Andric    if (__cs < __sz)
19810b57cec5SDimitry Andric        this->__append(__sz - __cs);
19820b57cec5SDimitry Andric    else if (__cs > __sz)
19830b57cec5SDimitry Andric        this->__destruct_at_end(this->__begin_ + __sz);
19840b57cec5SDimitry Andric}
19850b57cec5SDimitry Andric
19860b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1987bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
19880b57cec5SDimitry Andricvoid
19890b57cec5SDimitry Andricvector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
19900b57cec5SDimitry Andric{
19910b57cec5SDimitry Andric    size_type __cs = size();
19920b57cec5SDimitry Andric    if (__cs < __sz)
19930b57cec5SDimitry Andric        this->__append(__sz - __cs, __x);
19940b57cec5SDimitry Andric    else if (__cs > __sz)
19950b57cec5SDimitry Andric        this->__destruct_at_end(this->__begin_ + __sz);
19960b57cec5SDimitry Andric}
19970b57cec5SDimitry Andric
19980b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1999bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
20000b57cec5SDimitry Andricvoid
20010b57cec5SDimitry Andricvector<_Tp, _Allocator>::swap(vector& __x)
20020b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
20030b57cec5SDimitry Andric    _NOEXCEPT
20040b57cec5SDimitry Andric#else
20050b57cec5SDimitry Andric    _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
20060b57cec5SDimitry Andric                __is_nothrow_swappable<allocator_type>::value)
20070b57cec5SDimitry Andric#endif
20080b57cec5SDimitry Andric{
2009*06c3fb27SDimitry Andric    _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(__alloc_traits::propagate_on_container_swap::value ||
20100b57cec5SDimitry Andric                                        this->__alloc() == __x.__alloc(),
20110b57cec5SDimitry Andric                                        "vector::swap: Either propagate_on_container_swap must be true"
20120b57cec5SDimitry Andric                                        " or the allocators must compare equal");
2013bdd1243dSDimitry Andric    std::swap(this->__begin_, __x.__begin_);
2014bdd1243dSDimitry Andric    std::swap(this->__end_, __x.__end_);
2015bdd1243dSDimitry Andric    std::swap(this->__end_cap(), __x.__end_cap());
2016bdd1243dSDimitry Andric    std::__swap_allocator(this->__alloc(), __x.__alloc(),
20170b57cec5SDimitry Andric        integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>());
20180b57cec5SDimitry Andric}
20190b57cec5SDimitry Andric
20200b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
2021bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
20220b57cec5SDimitry Andricbool
20230b57cec5SDimitry Andricvector<_Tp, _Allocator>::__invariants() const
20240b57cec5SDimitry Andric{
20250b57cec5SDimitry Andric    if (this->__begin_ == nullptr)
20260b57cec5SDimitry Andric    {
20270b57cec5SDimitry Andric        if (this->__end_ != nullptr || this->__end_cap() != nullptr)
20280b57cec5SDimitry Andric            return false;
20290b57cec5SDimitry Andric    }
20300b57cec5SDimitry Andric    else
20310b57cec5SDimitry Andric    {
20320b57cec5SDimitry Andric        if (this->__begin_ > this->__end_)
20330b57cec5SDimitry Andric            return false;
20340b57cec5SDimitry Andric        if (this->__begin_ == this->__end_cap())
20350b57cec5SDimitry Andric            return false;
20360b57cec5SDimitry Andric        if (this->__end_ > this->__end_cap())
20370b57cec5SDimitry Andric            return false;
20380b57cec5SDimitry Andric    }
20390b57cec5SDimitry Andric    return true;
20400b57cec5SDimitry Andric}
20410b57cec5SDimitry Andric
20420b57cec5SDimitry Andric// vector<bool>
20430b57cec5SDimitry Andric
20440b57cec5SDimitry Andrictemplate <class _Allocator> class vector<bool, _Allocator>;
20450b57cec5SDimitry Andric
20460b57cec5SDimitry Andrictemplate <class _Allocator> struct hash<vector<bool, _Allocator> >;
20470b57cec5SDimitry Andric
20480b57cec5SDimitry Andrictemplate <class _Allocator>
20490b57cec5SDimitry Andricstruct __has_storage_type<vector<bool, _Allocator> >
20500b57cec5SDimitry Andric{
20510b57cec5SDimitry Andric    static const bool value = true;
20520b57cec5SDimitry Andric};
20530b57cec5SDimitry Andric
20540b57cec5SDimitry Andrictemplate <class _Allocator>
20550b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator>
20560b57cec5SDimitry Andric{
20570b57cec5SDimitry Andricpublic:
20580b57cec5SDimitry Andric    typedef vector                                   __self;
20590b57cec5SDimitry Andric    typedef bool                                     value_type;
20600b57cec5SDimitry Andric    typedef _Allocator                               allocator_type;
20610b57cec5SDimitry Andric    typedef allocator_traits<allocator_type>         __alloc_traits;
20620b57cec5SDimitry Andric    typedef typename __alloc_traits::size_type       size_type;
20630b57cec5SDimitry Andric    typedef typename __alloc_traits::difference_type difference_type;
20640b57cec5SDimitry Andric    typedef size_type __storage_type;
20650b57cec5SDimitry Andric    typedef __bit_iterator<vector, false>            pointer;
20660b57cec5SDimitry Andric    typedef __bit_iterator<vector, true>             const_pointer;
20670b57cec5SDimitry Andric    typedef pointer                                  iterator;
20680b57cec5SDimitry Andric    typedef const_pointer                            const_iterator;
2069bdd1243dSDimitry Andric    typedef std::reverse_iterator<iterator>         reverse_iterator;
2070bdd1243dSDimitry Andric    typedef std::reverse_iterator<const_iterator>   const_reverse_iterator;
20710b57cec5SDimitry Andric
20720b57cec5SDimitry Andricprivate:
2073bdd1243dSDimitry Andric    typedef __rebind_alloc<__alloc_traits, __storage_type> __storage_allocator;
20740b57cec5SDimitry Andric    typedef allocator_traits<__storage_allocator>    __storage_traits;
20750b57cec5SDimitry Andric    typedef typename __storage_traits::pointer       __storage_pointer;
20760b57cec5SDimitry Andric    typedef typename __storage_traits::const_pointer __const_storage_pointer;
20770b57cec5SDimitry Andric
20780b57cec5SDimitry Andric    __storage_pointer                                      __begin_;
20790b57cec5SDimitry Andric    size_type                                              __size_;
20800b57cec5SDimitry Andric    __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
20810b57cec5SDimitry Andricpublic:
20820b57cec5SDimitry Andric    typedef __bit_reference<vector>                  reference;
208381ad6265SDimitry Andric#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
208481ad6265SDimitry Andric    using const_reference = bool;
208581ad6265SDimitry Andric#else
20860b57cec5SDimitry Andric    typedef __bit_const_reference<vector>            const_reference;
208781ad6265SDimitry Andric#endif
20880b57cec5SDimitry Andricprivate:
2089bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
20900b57cec5SDimitry Andric    size_type& __cap() _NOEXCEPT
20910b57cec5SDimitry Andric        {return __cap_alloc_.first();}
2092bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
20930b57cec5SDimitry Andric    const size_type& __cap() const _NOEXCEPT
20940b57cec5SDimitry Andric        {return __cap_alloc_.first();}
2095bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
20960b57cec5SDimitry Andric    __storage_allocator& __alloc() _NOEXCEPT
20970b57cec5SDimitry Andric        {return __cap_alloc_.second();}
2098bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
20990b57cec5SDimitry Andric    const __storage_allocator& __alloc() const _NOEXCEPT
21000b57cec5SDimitry Andric        {return __cap_alloc_.second();}
21010b57cec5SDimitry Andric
21020b57cec5SDimitry Andric    static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
21030b57cec5SDimitry Andric
2104bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
21050b57cec5SDimitry Andric    static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
21060b57cec5SDimitry Andric        {return __n * __bits_per_word;}
2107bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
21080b57cec5SDimitry Andric    static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
21090b57cec5SDimitry Andric        {return (__n - 1) / __bits_per_word + 1;}
21100b57cec5SDimitry Andric
21110b57cec5SDimitry Andricpublic:
2112bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
21130b57cec5SDimitry Andric    vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
21140b57cec5SDimitry Andric
2115bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(const allocator_type& __a)
21160b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
21170b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
21180b57cec5SDimitry Andric#else
21190b57cec5SDimitry Andric        _NOEXCEPT;
21200b57cec5SDimitry Andric#endif
212150d7464cSDimitry Andric
212250d7464cSDimitry Andricprivate:
212350d7464cSDimitry Andric  class __destroy_vector {
212450d7464cSDimitry Andric    public:
2125*06c3fb27SDimitry Andric      _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI __destroy_vector(vector& __vec) : __vec_(__vec) {}
212650d7464cSDimitry Andric
2127bdd1243dSDimitry Andric      _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void operator()() {
212850d7464cSDimitry Andric        if (__vec_.__begin_ != nullptr)
212950d7464cSDimitry Andric            __storage_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.__cap());
213050d7464cSDimitry Andric      }
213150d7464cSDimitry Andric
213250d7464cSDimitry Andric    private:
213350d7464cSDimitry Andric      vector& __vec_;
213450d7464cSDimitry Andric  };
213550d7464cSDimitry Andric
213650d7464cSDimitry Andricpublic:
2137bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 ~vector() { __destroy_vector(*this)(); }
213850d7464cSDimitry Andric
2139bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n);
2140*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
2141bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit vector(size_type __n, const allocator_type& __a);
21420b57cec5SDimitry Andric#endif
2143bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(size_type __n, const value_type& __v);
2144bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(size_type __n, const value_type& __v, const allocator_type& __a);
21450b57cec5SDimitry Andric    template <class _InputIterator>
2146bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_InputIterator __first, _InputIterator __last,
2147*06c3fb27SDimitry Andric               typename enable_if<__has_exactly_input_iterator_category<_InputIterator>::value>::type* = 0);
21480b57cec5SDimitry Andric    template <class _InputIterator>
2149bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2150*06c3fb27SDimitry Andric               typename enable_if<__has_exactly_input_iterator_category<_InputIterator>::value>::type* = 0);
21510b57cec5SDimitry Andric    template <class _ForwardIterator>
2152bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_ForwardIterator __first, _ForwardIterator __last,
2153*06c3fb27SDimitry Andric               typename enable_if<__has_forward_iterator_category<_ForwardIterator>::value>::type* = 0);
21540b57cec5SDimitry Andric    template <class _ForwardIterator>
2155bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2156*06c3fb27SDimitry Andric               typename enable_if<__has_forward_iterator_category<_ForwardIterator>::value>::type* = 0);
2157*06c3fb27SDimitry Andric
2158*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
2159*06c3fb27SDimitry Andric    template <_ContainerCompatibleRange<bool> _Range>
2160*06c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI constexpr
2161*06c3fb27SDimitry Andric    vector(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type())
2162*06c3fb27SDimitry Andric    : __begin_(nullptr),
2163*06c3fb27SDimitry Andric      __size_(0),
2164*06c3fb27SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a)) {
2165*06c3fb27SDimitry Andric      if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
2166*06c3fb27SDimitry Andric        auto __n = static_cast<size_type>(ranges::distance(__range));
2167*06c3fb27SDimitry Andric        __init_with_size(ranges::begin(__range), ranges::end(__range), __n);
2168*06c3fb27SDimitry Andric
2169*06c3fb27SDimitry Andric      } else {
2170*06c3fb27SDimitry Andric        __init_with_sentinel(ranges::begin(__range), ranges::end(__range));
2171*06c3fb27SDimitry Andric      }
2172*06c3fb27SDimitry Andric    }
2173*06c3fb27SDimitry Andric#endif
21740b57cec5SDimitry Andric
2175bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(const vector& __v);
2176bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(const vector& __v, const allocator_type& __a);
2177bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector& operator=(const vector& __v);
21780b57cec5SDimitry Andric
21790b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
2180bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(initializer_list<value_type> __il);
2181bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(initializer_list<value_type> __il, const allocator_type& __a);
21820b57cec5SDimitry Andric
2183bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
21840b57cec5SDimitry Andric    vector& operator=(initializer_list<value_type> __il)
21850b57cec5SDimitry Andric        {assign(__il.begin(), __il.end()); return *this;}
21860b57cec5SDimitry Andric
21870b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG
21880b57cec5SDimitry Andric
2189bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
219081ad6265SDimitry Andric    vector(vector&& __v)
2191*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
219281ad6265SDimitry Andric        noexcept;
219381ad6265SDimitry Andric#else
219481ad6265SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
219581ad6265SDimitry Andric#endif
2196bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector(vector&& __v, const __type_identity_t<allocator_type>& __a);
2197bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
219881ad6265SDimitry Andric    vector& operator=(vector&& __v)
219981ad6265SDimitry Andric        _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
220081ad6265SDimitry Andric
22010b57cec5SDimitry Andric    template <class _InputIterator>
2202*06c3fb27SDimitry Andric        typename enable_if <__has_exactly_input_iterator_category<_InputIterator>::value,
22030b57cec5SDimitry Andric           void
22040b57cec5SDimitry Andric        >::type
2205bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 assign(_InputIterator __first, _InputIterator __last);
22060b57cec5SDimitry Andric    template <class _ForwardIterator>
22070b57cec5SDimitry Andric        typename enable_if
22080b57cec5SDimitry Andric        <
2209*06c3fb27SDimitry Andric            __has_forward_iterator_category<_ForwardIterator>::value,
22100b57cec5SDimitry Andric           void
22110b57cec5SDimitry Andric        >::type
2212bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 assign(_ForwardIterator __first, _ForwardIterator __last);
22130b57cec5SDimitry Andric
2214*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
2215*06c3fb27SDimitry Andric    template <_ContainerCompatibleRange<bool> _Range>
2216*06c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI
2217*06c3fb27SDimitry Andric    constexpr void assign_range(_Range&& __range) {
2218*06c3fb27SDimitry Andric      if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
2219*06c3fb27SDimitry Andric        auto __n = static_cast<size_type>(ranges::distance(__range));
2220*06c3fb27SDimitry Andric        __assign_with_size(ranges::begin(__range), ranges::end(__range), __n);
2221*06c3fb27SDimitry Andric
2222*06c3fb27SDimitry Andric      } else {
2223*06c3fb27SDimitry Andric        __assign_with_sentinel(ranges::begin(__range), ranges::end(__range));
2224*06c3fb27SDimitry Andric      }
2225*06c3fb27SDimitry Andric    }
2226*06c3fb27SDimitry Andric#endif
2227*06c3fb27SDimitry Andric
2228bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void assign(size_type __n, const value_type& __x);
22290b57cec5SDimitry Andric
22300b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
2231bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
22320b57cec5SDimitry Andric    void assign(initializer_list<value_type> __il)
22330b57cec5SDimitry Andric        {assign(__il.begin(), __il.end());}
22340b57cec5SDimitry Andric#endif
22350b57cec5SDimitry Andric
2236bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator_type get_allocator() const _NOEXCEPT
22370b57cec5SDimitry Andric        {return allocator_type(this->__alloc());}
22380b57cec5SDimitry Andric
2239bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type max_size() const _NOEXCEPT;
2240bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
22410b57cec5SDimitry Andric    size_type capacity() const _NOEXCEPT
22420b57cec5SDimitry Andric        {return __internal_cap_to_external(__cap());}
2243bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
22440b57cec5SDimitry Andric    size_type size() const _NOEXCEPT
22450b57cec5SDimitry Andric        {return __size_;}
2246bdd1243dSDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
22470b57cec5SDimitry Andric    bool empty() const _NOEXCEPT
22480b57cec5SDimitry Andric        {return __size_ == 0;}
2249bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void reserve(size_type __n);
2250bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void shrink_to_fit() _NOEXCEPT;
22510b57cec5SDimitry Andric
2252bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
22530b57cec5SDimitry Andric    iterator begin() _NOEXCEPT
22540b57cec5SDimitry Andric        {return __make_iter(0);}
2255bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
22560b57cec5SDimitry Andric    const_iterator begin() const _NOEXCEPT
22570b57cec5SDimitry Andric        {return __make_iter(0);}
2258bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
22590b57cec5SDimitry Andric    iterator end() _NOEXCEPT
22600b57cec5SDimitry Andric        {return __make_iter(__size_);}
2261bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
22620b57cec5SDimitry Andric    const_iterator end()   const _NOEXCEPT
22630b57cec5SDimitry Andric        {return __make_iter(__size_);}
22640b57cec5SDimitry Andric
2265bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
22660b57cec5SDimitry Andric    reverse_iterator rbegin() _NOEXCEPT
22670b57cec5SDimitry Andric        {return       reverse_iterator(end());}
2268bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
22690b57cec5SDimitry Andric    const_reverse_iterator rbegin() const _NOEXCEPT
22700b57cec5SDimitry Andric        {return const_reverse_iterator(end());}
2271bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
22720b57cec5SDimitry Andric    reverse_iterator rend() _NOEXCEPT
22730b57cec5SDimitry Andric        {return       reverse_iterator(begin());}
2274bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
22750b57cec5SDimitry Andric    const_reverse_iterator rend()   const _NOEXCEPT
22760b57cec5SDimitry Andric        {return const_reverse_iterator(begin());}
22770b57cec5SDimitry Andric
2278bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
22790b57cec5SDimitry Andric    const_iterator         cbegin()  const _NOEXCEPT
22800b57cec5SDimitry Andric        {return __make_iter(0);}
2281bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
22820b57cec5SDimitry Andric    const_iterator         cend()    const _NOEXCEPT
22830b57cec5SDimitry Andric        {return __make_iter(__size_);}
2284bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
22850b57cec5SDimitry Andric    const_reverse_iterator crbegin() const _NOEXCEPT
22860b57cec5SDimitry Andric        {return rbegin();}
2287bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
22880b57cec5SDimitry Andric    const_reverse_iterator crend()   const _NOEXCEPT
22890b57cec5SDimitry Andric        {return rend();}
22900b57cec5SDimitry Andric
2291bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference       operator[](size_type __n)       {return __make_ref(__n);}
2292bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference operator[](size_type __n) const {return __make_ref(__n);}
2293bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI reference       at(size_type __n);
2294bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __n) const;
22950b57cec5SDimitry Andric
2296bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference       front()       {return __make_ref(0);}
2297bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference front() const {return __make_ref(0);}
2298bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference       back()        {return __make_ref(__size_ - 1);}
2299bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference back()  const {return __make_ref(__size_ - 1);}
23000b57cec5SDimitry Andric
2301bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void push_back(const value_type& __x);
2302*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
23030b57cec5SDimitry Andric    template <class... _Args>
2304*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
2305bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference emplace_back(_Args&&... __args)
23060b57cec5SDimitry Andric#else
2307bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI void      emplace_back(_Args&&... __args)
23080b57cec5SDimitry Andric#endif
23090b57cec5SDimitry Andric    {
2310bdd1243dSDimitry Andric        push_back ( value_type ( std::forward<_Args>(__args)... ));
2311*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
23120b57cec5SDimitry Andric        return this->back();
23130b57cec5SDimitry Andric#endif
23140b57cec5SDimitry Andric    }
23150b57cec5SDimitry Andric#endif
23160b57cec5SDimitry Andric
2317*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
2318*06c3fb27SDimitry Andric    template <_ContainerCompatibleRange<bool> _Range>
2319*06c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI
2320*06c3fb27SDimitry Andric    constexpr void append_range(_Range&& __range) {
2321*06c3fb27SDimitry Andric      insert_range(end(), std::forward<_Range>(__range));
2322*06c3fb27SDimitry Andric    }
2323*06c3fb27SDimitry Andric#endif
2324*06c3fb27SDimitry Andric
2325bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void pop_back() {--__size_;}
23260b57cec5SDimitry Andric
2327*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
23280b57cec5SDimitry Andric    template <class... _Args>
2329bdd1243dSDimitry Andric   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator emplace(const_iterator __position, _Args&&... __args)
2330bdd1243dSDimitry Andric        { return insert ( __position, value_type ( std::forward<_Args>(__args)... )); }
23310b57cec5SDimitry Andric#endif
23320b57cec5SDimitry Andric
2333bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __position, const value_type& __x);
2334bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
23350b57cec5SDimitry Andric    template <class _InputIterator>
2336*06c3fb27SDimitry Andric        typename enable_if <__has_exactly_input_iterator_category<_InputIterator>::value,
23370b57cec5SDimitry Andric            iterator
23380b57cec5SDimitry Andric        >::type
2339bdd1243dSDimitry Andric        _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
23400b57cec5SDimitry Andric    template <class _ForwardIterator>
23410b57cec5SDimitry Andric        typename enable_if
23420b57cec5SDimitry Andric        <
2343*06c3fb27SDimitry Andric            __has_forward_iterator_category<_ForwardIterator>::value,
23440b57cec5SDimitry Andric            iterator
23450b57cec5SDimitry Andric        >::type
2346bdd1243dSDimitry Andric        _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
23470b57cec5SDimitry Andric
2348*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
2349*06c3fb27SDimitry Andric    template <_ContainerCompatibleRange<bool> _Range>
2350*06c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI
2351*06c3fb27SDimitry Andric    constexpr iterator insert_range(const_iterator __position, _Range&& __range) {
2352*06c3fb27SDimitry Andric      if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
2353*06c3fb27SDimitry Andric        auto __n = static_cast<size_type>(ranges::distance(__range));
2354*06c3fb27SDimitry Andric        return __insert_with_size(__position, ranges::begin(__range), ranges::end(__range), __n);
2355*06c3fb27SDimitry Andric
2356*06c3fb27SDimitry Andric      } else {
2357*06c3fb27SDimitry Andric        return __insert_with_sentinel(__position, ranges::begin(__range), ranges::end(__range));
2358*06c3fb27SDimitry Andric      }
2359*06c3fb27SDimitry Andric    }
2360*06c3fb27SDimitry Andric#endif
2361*06c3fb27SDimitry Andric
23620b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
2363bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
23640b57cec5SDimitry Andric    iterator insert(const_iterator __position, initializer_list<value_type> __il)
23650b57cec5SDimitry Andric        {return insert(__position, __il.begin(), __il.end());}
23660b57cec5SDimitry Andric#endif
23670b57cec5SDimitry Andric
2368bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __position);
2369bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator erase(const_iterator __first, const_iterator __last);
23700b57cec5SDimitry Andric
2371bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
23720b57cec5SDimitry Andric    void clear() _NOEXCEPT {__size_ = 0;}
23730b57cec5SDimitry Andric
2374*06c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(vector&)
23750b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
23760b57cec5SDimitry Andric        _NOEXCEPT;
23770b57cec5SDimitry Andric#else
23780b57cec5SDimitry Andric        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
23790b57cec5SDimitry Andric                    __is_nothrow_swappable<allocator_type>::value);
23800b57cec5SDimitry Andric#endif
2381bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static void swap(reference __x, reference __y) _NOEXCEPT { std::swap(__x, __y); }
23820b57cec5SDimitry Andric
2383bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void resize(size_type __sz, value_type __x = false);
2384bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void flip() _NOEXCEPT;
23850b57cec5SDimitry Andric
2386bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __invariants() const;
23870b57cec5SDimitry Andric
23880b57cec5SDimitry Andricprivate:
2389d56accc7SDimitry Andric    _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
2390d56accc7SDimitry Andric    void __throw_length_error() const {
2391bdd1243dSDimitry Andric        std::__throw_length_error("vector");
2392d56accc7SDimitry Andric    }
2393d56accc7SDimitry Andric
2394d56accc7SDimitry Andric    _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
2395d56accc7SDimitry Andric    void __throw_out_of_range() const {
2396bdd1243dSDimitry Andric        std::__throw_out_of_range("vector");
2397d56accc7SDimitry Andric    }
2398d56accc7SDimitry Andric
2399*06c3fb27SDimitry Andric    template <class _InputIterator, class _Sentinel>
2400*06c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
2401*06c3fb27SDimitry Andric    void __init_with_size(_InputIterator __first, _Sentinel __last, size_type __n) {
2402*06c3fb27SDimitry Andric      auto __guard = std::__make_exception_guard(__destroy_vector(*this));
2403*06c3fb27SDimitry Andric
2404*06c3fb27SDimitry Andric      if (__n > 0) {
2405*06c3fb27SDimitry Andric        __vallocate(__n);
2406*06c3fb27SDimitry Andric        __construct_at_end(std::move(__first), std::move(__last), __n);
2407*06c3fb27SDimitry Andric      }
2408*06c3fb27SDimitry Andric
2409*06c3fb27SDimitry Andric      __guard.__complete();
2410*06c3fb27SDimitry Andric    }
2411*06c3fb27SDimitry Andric
2412*06c3fb27SDimitry Andric    template <class _InputIterator, class _Sentinel>
2413*06c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
2414*06c3fb27SDimitry Andric    void __init_with_sentinel(_InputIterator __first, _Sentinel __last) {
2415*06c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2416*06c3fb27SDimitry Andric      try {
2417*06c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2418*06c3fb27SDimitry Andric        for (; __first != __last; ++__first)
2419*06c3fb27SDimitry Andric            push_back(*__first);
2420*06c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2421*06c3fb27SDimitry Andric      } catch (...) {
2422*06c3fb27SDimitry Andric        if (__begin_ != nullptr)
2423*06c3fb27SDimitry Andric          __storage_traits::deallocate(__alloc(), __begin_, __cap());
2424*06c3fb27SDimitry Andric        throw;
2425*06c3fb27SDimitry Andric      }
2426*06c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2427*06c3fb27SDimitry Andric    }
2428*06c3fb27SDimitry Andric
2429*06c3fb27SDimitry Andric  template <class _Iterator, class _Sentinel>
2430*06c3fb27SDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
2431*06c3fb27SDimitry Andric  void __assign_with_sentinel(_Iterator __first, _Sentinel __last);
2432*06c3fb27SDimitry Andric
2433*06c3fb27SDimitry Andric  template <class _ForwardIterator, class _Sentinel>
2434*06c3fb27SDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
2435*06c3fb27SDimitry Andric  void __assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __ns);
2436*06c3fb27SDimitry Andric
2437*06c3fb27SDimitry Andric  template <class _InputIterator, class _Sentinel>
2438*06c3fb27SDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
2439*06c3fb27SDimitry Andric  iterator __insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last);
2440*06c3fb27SDimitry Andric
2441*06c3fb27SDimitry Andric  template <class _Iterator, class _Sentinel>
2442*06c3fb27SDimitry Andric  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
2443*06c3fb27SDimitry Andric  iterator __insert_with_size(const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n);
2444*06c3fb27SDimitry Andric
244581ad6265SDimitry Andric    //  Allocate space for __n objects
244681ad6265SDimitry Andric    //  throws length_error if __n > max_size()
244781ad6265SDimitry Andric    //  throws (probably bad_alloc) if memory run out
244881ad6265SDimitry Andric    //  Precondition:  __begin_ == __end_ == __cap() == 0
244981ad6265SDimitry Andric    //  Precondition:  __n > 0
245081ad6265SDimitry Andric    //  Postcondition:  capacity() >= __n
245181ad6265SDimitry Andric    //  Postcondition:  size() == 0
2452bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __vallocate(size_type __n) {
245381ad6265SDimitry Andric        if (__n > max_size())
245481ad6265SDimitry Andric            __throw_length_error();
245581ad6265SDimitry Andric        auto __allocation = std::__allocate_at_least(__alloc(), __external_cap_to_internal(__n));
245681ad6265SDimitry Andric        __begin_ = __allocation.ptr;
245781ad6265SDimitry Andric        __size_ = 0;
245881ad6265SDimitry Andric        __cap() = __allocation.count;
245961cfbce3SDimitry Andric        if (__libcpp_is_constant_evaluated()) {
246061cfbce3SDimitry Andric            for (size_type __i = 0; __i != __cap(); ++__i)
246161cfbce3SDimitry Andric                std::__construct_at(std::__to_address(__begin_) + __i);
246261cfbce3SDimitry Andric        }
246381ad6265SDimitry Andric    }
246481ad6265SDimitry Andric
2465bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __vdeallocate() _NOEXCEPT;
2466bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
24670b57cec5SDimitry Andric    static size_type __align_it(size_type __new_size) _NOEXCEPT
246881ad6265SDimitry Andric        {return (__new_size + (__bits_per_word-1)) & ~((size_type)__bits_per_word-1);}
2469bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20  size_type __recommend(size_type __new_size) const;
2470bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __construct_at_end(size_type __n, bool __x);
2471*06c3fb27SDimitry Andric    template <class _InputIterator, class _Sentinel>
2472*06c3fb27SDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
2473*06c3fb27SDimitry Andric    void __construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n);
2474bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __append(size_type __n, const_reference __x);
2475bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
24760b57cec5SDimitry Andric    reference __make_ref(size_type __pos) _NOEXCEPT
24770b57cec5SDimitry Andric        {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2478bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
247981ad6265SDimitry Andric    const_reference __make_ref(size_type __pos) const _NOEXCEPT {
248081ad6265SDimitry Andric        return __bit_const_reference<vector>(__begin_ + __pos / __bits_per_word,
248181ad6265SDimitry Andric                                             __storage_type(1) << __pos % __bits_per_word);
248281ad6265SDimitry Andric    }
2483bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
24840b57cec5SDimitry Andric    iterator __make_iter(size_type __pos) _NOEXCEPT
24850b57cec5SDimitry Andric        {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2486bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
24870b57cec5SDimitry Andric    const_iterator __make_iter(size_type __pos) const _NOEXCEPT
24880b57cec5SDimitry Andric        {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2489bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
24900b57cec5SDimitry Andric    iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
24910b57cec5SDimitry Andric        {return begin() + (__p - cbegin());}
24920b57cec5SDimitry Andric
2493bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
24940b57cec5SDimitry Andric    void __copy_assign_alloc(const vector& __v)
24950b57cec5SDimitry Andric        {__copy_assign_alloc(__v, integral_constant<bool,
24960b57cec5SDimitry Andric                      __storage_traits::propagate_on_container_copy_assignment::value>());}
2497bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
24980b57cec5SDimitry Andric    void __copy_assign_alloc(const vector& __c, true_type)
24990b57cec5SDimitry Andric        {
25000b57cec5SDimitry Andric            if (__alloc() != __c.__alloc())
25010b57cec5SDimitry Andric                __vdeallocate();
25020b57cec5SDimitry Andric            __alloc() = __c.__alloc();
25030b57cec5SDimitry Andric        }
25040b57cec5SDimitry Andric
2505bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
25060b57cec5SDimitry Andric    void __copy_assign_alloc(const vector&, false_type)
25070b57cec5SDimitry Andric        {}
25080b57cec5SDimitry Andric
2509bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign(vector& __c, false_type);
2510bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __move_assign(vector& __c, true_type)
25110b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
2512bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
25130b57cec5SDimitry Andric    void __move_assign_alloc(vector& __c)
25140b57cec5SDimitry Andric        _NOEXCEPT_(
25150b57cec5SDimitry Andric            !__storage_traits::propagate_on_container_move_assignment::value ||
25160b57cec5SDimitry Andric            is_nothrow_move_assignable<allocator_type>::value)
25170b57cec5SDimitry Andric        {__move_assign_alloc(__c, integral_constant<bool,
25180b57cec5SDimitry Andric                      __storage_traits::propagate_on_container_move_assignment::value>());}
2519bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
25200b57cec5SDimitry Andric    void __move_assign_alloc(vector& __c, true_type)
25210b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
25220b57cec5SDimitry Andric        {
2523bdd1243dSDimitry Andric            __alloc() = std::move(__c.__alloc());
25240b57cec5SDimitry Andric        }
25250b57cec5SDimitry Andric
2526bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
25270b57cec5SDimitry Andric    void __move_assign_alloc(vector&, false_type)
25280b57cec5SDimitry Andric        _NOEXCEPT
25290b57cec5SDimitry Andric        {}
25300b57cec5SDimitry Andric
2531bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_t __hash_code() const _NOEXCEPT;
25320b57cec5SDimitry Andric
25330b57cec5SDimitry Andric    friend class __bit_reference<vector>;
25340b57cec5SDimitry Andric    friend class __bit_const_reference<vector>;
25350b57cec5SDimitry Andric    friend class __bit_iterator<vector, false>;
25360b57cec5SDimitry Andric    friend class __bit_iterator<vector, true>;
25370b57cec5SDimitry Andric    friend struct __bit_array<vector>;
25380b57cec5SDimitry Andric    friend struct _LIBCPP_TEMPLATE_VIS hash<vector>;
25390b57cec5SDimitry Andric};
25400b57cec5SDimitry Andric
25410b57cec5SDimitry Andrictemplate <class _Allocator>
2542bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void
25430b57cec5SDimitry Andricvector<bool, _Allocator>::__vdeallocate() _NOEXCEPT
25440b57cec5SDimitry Andric{
25450b57cec5SDimitry Andric    if (this->__begin_ != nullptr)
25460b57cec5SDimitry Andric    {
25470b57cec5SDimitry Andric        __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
25480b57cec5SDimitry Andric        this->__begin_ = nullptr;
25490b57cec5SDimitry Andric        this->__size_ = this->__cap() = 0;
25500b57cec5SDimitry Andric    }
25510b57cec5SDimitry Andric}
25520b57cec5SDimitry Andric
25530b57cec5SDimitry Andrictemplate <class _Allocator>
2554bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
25550b57cec5SDimitry Andrictypename vector<bool, _Allocator>::size_type
25560b57cec5SDimitry Andricvector<bool, _Allocator>::max_size() const _NOEXCEPT
25570b57cec5SDimitry Andric{
25580b57cec5SDimitry Andric    size_type __amax = __storage_traits::max_size(__alloc());
25590b57cec5SDimitry Andric    size_type __nmax = numeric_limits<size_type>::max() / 2;  // end() >= begin(), always
25600b57cec5SDimitry Andric    if (__nmax / __bits_per_word <= __amax)
25610b57cec5SDimitry Andric        return __nmax;
25620b57cec5SDimitry Andric    return __internal_cap_to_external(__amax);
25630b57cec5SDimitry Andric}
25640b57cec5SDimitry Andric
25650b57cec5SDimitry Andric//  Precondition:  __new_size > capacity()
25660b57cec5SDimitry Andrictemplate <class _Allocator>
2567bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
25680b57cec5SDimitry Andrictypename vector<bool, _Allocator>::size_type
25690b57cec5SDimitry Andricvector<bool, _Allocator>::__recommend(size_type __new_size) const
25700b57cec5SDimitry Andric{
25710b57cec5SDimitry Andric    const size_type __ms = max_size();
25720b57cec5SDimitry Andric    if (__new_size > __ms)
25730b57cec5SDimitry Andric        this->__throw_length_error();
25740b57cec5SDimitry Andric    const size_type __cap = capacity();
25750b57cec5SDimitry Andric    if (__cap >= __ms / 2)
25760b57cec5SDimitry Andric        return __ms;
2577bdd1243dSDimitry Andric    return std::max(2 * __cap, __align_it(__new_size));
25780b57cec5SDimitry Andric}
25790b57cec5SDimitry Andric
25800b57cec5SDimitry Andric//  Default constructs __n objects starting at __end_
25810b57cec5SDimitry Andric//  Precondition:  __n > 0
25820b57cec5SDimitry Andric//  Precondition:  size() + __n <= capacity()
25830b57cec5SDimitry Andric//  Postcondition:  size() == size() + __n
25840b57cec5SDimitry Andrictemplate <class _Allocator>
2585bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
25860b57cec5SDimitry Andricvoid
25870b57cec5SDimitry Andricvector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
25880b57cec5SDimitry Andric{
25890b57cec5SDimitry Andric    size_type __old_size = this->__size_;
25900b57cec5SDimitry Andric    this->__size_ += __n;
25910b57cec5SDimitry Andric    if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word))
25920b57cec5SDimitry Andric    {
25930b57cec5SDimitry Andric        if (this->__size_ <= __bits_per_word)
25940b57cec5SDimitry Andric            this->__begin_[0] = __storage_type(0);
25950b57cec5SDimitry Andric        else
25960b57cec5SDimitry Andric            this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
25970b57cec5SDimitry Andric    }
2598bdd1243dSDimitry Andric    std::fill_n(__make_iter(__old_size), __n, __x);
25990b57cec5SDimitry Andric}
26000b57cec5SDimitry Andric
26010b57cec5SDimitry Andrictemplate <class _Allocator>
2602*06c3fb27SDimitry Andrictemplate <class _InputIterator, class _Sentinel>
2603bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
2604*06c3fb27SDimitry Andricvoid vector<bool, _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) {
26050b57cec5SDimitry Andric    size_type __old_size = this->__size_;
2606*06c3fb27SDimitry Andric    this->__size_ += __n;
26070b57cec5SDimitry Andric    if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word))
26080b57cec5SDimitry Andric    {
26090b57cec5SDimitry Andric        if (this->__size_ <= __bits_per_word)
26100b57cec5SDimitry Andric            this->__begin_[0] = __storage_type(0);
26110b57cec5SDimitry Andric        else
26120b57cec5SDimitry Andric            this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
26130b57cec5SDimitry Andric    }
2614*06c3fb27SDimitry Andric    std::__copy<_ClassicAlgPolicy>(__first, __last, __make_iter(__old_size));
26150b57cec5SDimitry Andric}
26160b57cec5SDimitry Andric
26170b57cec5SDimitry Andrictemplate <class _Allocator>
2618bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
26190b57cec5SDimitry Andricvector<bool, _Allocator>::vector()
26200b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
26210b57cec5SDimitry Andric    : __begin_(nullptr),
26220b57cec5SDimitry Andric      __size_(0),
2623480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
26240b57cec5SDimitry Andric{
26250b57cec5SDimitry Andric}
26260b57cec5SDimitry Andric
26270b57cec5SDimitry Andrictemplate <class _Allocator>
2628bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
26290b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const allocator_type& __a)
26300b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
26310b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
26320b57cec5SDimitry Andric#else
26330b57cec5SDimitry Andric        _NOEXCEPT
26340b57cec5SDimitry Andric#endif
26350b57cec5SDimitry Andric    : __begin_(nullptr),
26360b57cec5SDimitry Andric      __size_(0),
26370b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
26380b57cec5SDimitry Andric{
26390b57cec5SDimitry Andric}
26400b57cec5SDimitry Andric
26410b57cec5SDimitry Andrictemplate <class _Allocator>
2642bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
26430b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n)
26440b57cec5SDimitry Andric    : __begin_(nullptr),
26450b57cec5SDimitry Andric      __size_(0),
2646480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
26470b57cec5SDimitry Andric{
26480b57cec5SDimitry Andric    if (__n > 0)
26490b57cec5SDimitry Andric    {
26500b57cec5SDimitry Andric        __vallocate(__n);
26510b57cec5SDimitry Andric        __construct_at_end(__n, false);
26520b57cec5SDimitry Andric    }
26530b57cec5SDimitry Andric}
26540b57cec5SDimitry Andric
2655*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
26560b57cec5SDimitry Andrictemplate <class _Allocator>
2657bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
26580b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
26590b57cec5SDimitry Andric    : __begin_(nullptr),
26600b57cec5SDimitry Andric      __size_(0),
26610b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
26620b57cec5SDimitry Andric{
26630b57cec5SDimitry Andric    if (__n > 0)
26640b57cec5SDimitry Andric    {
26650b57cec5SDimitry Andric        __vallocate(__n);
26660b57cec5SDimitry Andric        __construct_at_end(__n, false);
26670b57cec5SDimitry Andric    }
26680b57cec5SDimitry Andric}
26690b57cec5SDimitry Andric#endif
26700b57cec5SDimitry Andric
26710b57cec5SDimitry Andrictemplate <class _Allocator>
2672bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
26730b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
26740b57cec5SDimitry Andric    : __begin_(nullptr),
26750b57cec5SDimitry Andric      __size_(0),
2676480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
26770b57cec5SDimitry Andric{
26780b57cec5SDimitry Andric    if (__n > 0)
26790b57cec5SDimitry Andric    {
26800b57cec5SDimitry Andric        __vallocate(__n);
26810b57cec5SDimitry Andric        __construct_at_end(__n, __x);
26820b57cec5SDimitry Andric    }
26830b57cec5SDimitry Andric}
26840b57cec5SDimitry Andric
26850b57cec5SDimitry Andrictemplate <class _Allocator>
2686bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
26870b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
26880b57cec5SDimitry Andric    : __begin_(nullptr),
26890b57cec5SDimitry Andric      __size_(0),
26900b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
26910b57cec5SDimitry Andric{
26920b57cec5SDimitry Andric    if (__n > 0)
26930b57cec5SDimitry Andric    {
26940b57cec5SDimitry Andric        __vallocate(__n);
26950b57cec5SDimitry Andric        __construct_at_end(__n, __x);
26960b57cec5SDimitry Andric    }
26970b57cec5SDimitry Andric}
26980b57cec5SDimitry Andric
26990b57cec5SDimitry Andrictemplate <class _Allocator>
27000b57cec5SDimitry Andrictemplate <class _InputIterator>
2701bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
27020b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2703*06c3fb27SDimitry Andric       typename enable_if<__has_exactly_input_iterator_category<_InputIterator>::value>::type*)
27040b57cec5SDimitry Andric    : __begin_(nullptr),
27050b57cec5SDimitry Andric      __size_(0),
2706480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
27070b57cec5SDimitry Andric{
2708*06c3fb27SDimitry Andric  __init_with_sentinel(__first, __last);
27090b57cec5SDimitry Andric}
27100b57cec5SDimitry Andric
27110b57cec5SDimitry Andrictemplate <class _Allocator>
27120b57cec5SDimitry Andrictemplate <class _InputIterator>
2713bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
27140b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2715*06c3fb27SDimitry Andric       typename enable_if<__has_exactly_input_iterator_category<_InputIterator>::value>::type*)
27160b57cec5SDimitry Andric    : __begin_(nullptr),
27170b57cec5SDimitry Andric      __size_(0),
27180b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
27190b57cec5SDimitry Andric{
2720*06c3fb27SDimitry Andric  __init_with_sentinel(__first, __last);
27210b57cec5SDimitry Andric}
27220b57cec5SDimitry Andric
27230b57cec5SDimitry Andrictemplate <class _Allocator>
27240b57cec5SDimitry Andrictemplate <class _ForwardIterator>
2725bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
27260b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2727*06c3fb27SDimitry Andric                                typename enable_if<__has_forward_iterator_category<_ForwardIterator>::value>::type*)
27280b57cec5SDimitry Andric    : __begin_(nullptr),
27290b57cec5SDimitry Andric      __size_(0),
2730480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
27310b57cec5SDimitry Andric{
2732*06c3fb27SDimitry Andric  auto __n = static_cast<size_type>(std::distance(__first, __last));
2733*06c3fb27SDimitry Andric  __init_with_size(__first, __last, __n);
27340b57cec5SDimitry Andric}
27350b57cec5SDimitry Andric
27360b57cec5SDimitry Andrictemplate <class _Allocator>
27370b57cec5SDimitry Andrictemplate <class _ForwardIterator>
2738bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
27390b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2740*06c3fb27SDimitry Andric                                typename enable_if<__has_forward_iterator_category<_ForwardIterator>::value>::type*)
27410b57cec5SDimitry Andric    : __begin_(nullptr),
27420b57cec5SDimitry Andric      __size_(0),
27430b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
27440b57cec5SDimitry Andric{
2745*06c3fb27SDimitry Andric  auto __n = static_cast<size_type>(std::distance(__first, __last));
2746*06c3fb27SDimitry Andric  __init_with_size(__first, __last, __n);
27470b57cec5SDimitry Andric}
27480b57cec5SDimitry Andric
27490b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
27500b57cec5SDimitry Andric
27510b57cec5SDimitry Andrictemplate <class _Allocator>
2752bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
27530b57cec5SDimitry Andricvector<bool, _Allocator>::vector(initializer_list<value_type> __il)
27540b57cec5SDimitry Andric    : __begin_(nullptr),
27550b57cec5SDimitry Andric      __size_(0),
2756480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
27570b57cec5SDimitry Andric{
27580b57cec5SDimitry Andric    size_type __n = static_cast<size_type>(__il.size());
27590b57cec5SDimitry Andric    if (__n > 0)
27600b57cec5SDimitry Andric    {
27610b57cec5SDimitry Andric        __vallocate(__n);
2762*06c3fb27SDimitry Andric        __construct_at_end(__il.begin(), __il.end(), __n);
27630b57cec5SDimitry Andric    }
27640b57cec5SDimitry Andric}
27650b57cec5SDimitry Andric
27660b57cec5SDimitry Andrictemplate <class _Allocator>
2767bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
27680b57cec5SDimitry Andricvector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
27690b57cec5SDimitry Andric    : __begin_(nullptr),
27700b57cec5SDimitry Andric      __size_(0),
27710b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
27720b57cec5SDimitry Andric{
27730b57cec5SDimitry Andric    size_type __n = static_cast<size_type>(__il.size());
27740b57cec5SDimitry Andric    if (__n > 0)
27750b57cec5SDimitry Andric    {
27760b57cec5SDimitry Andric        __vallocate(__n);
2777*06c3fb27SDimitry Andric        __construct_at_end(__il.begin(), __il.end(), __n);
27780b57cec5SDimitry Andric    }
27790b57cec5SDimitry Andric}
27800b57cec5SDimitry Andric
27810b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
27820b57cec5SDimitry Andric
27830b57cec5SDimitry Andrictemplate <class _Allocator>
2784bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
27850b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const vector& __v)
27860b57cec5SDimitry Andric    : __begin_(nullptr),
27870b57cec5SDimitry Andric      __size_(0),
27880b57cec5SDimitry Andric      __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
27890b57cec5SDimitry Andric{
27900b57cec5SDimitry Andric    if (__v.size() > 0)
27910b57cec5SDimitry Andric    {
27920b57cec5SDimitry Andric        __vallocate(__v.size());
2793*06c3fb27SDimitry Andric        __construct_at_end(__v.begin(), __v.end(), __v.size());
27940b57cec5SDimitry Andric    }
27950b57cec5SDimitry Andric}
27960b57cec5SDimitry Andric
27970b57cec5SDimitry Andrictemplate <class _Allocator>
2798bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
27990b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
28000b57cec5SDimitry Andric    : __begin_(nullptr),
28010b57cec5SDimitry Andric      __size_(0),
28020b57cec5SDimitry Andric      __cap_alloc_(0, __a)
28030b57cec5SDimitry Andric{
28040b57cec5SDimitry Andric    if (__v.size() > 0)
28050b57cec5SDimitry Andric    {
28060b57cec5SDimitry Andric        __vallocate(__v.size());
2807*06c3fb27SDimitry Andric        __construct_at_end(__v.begin(), __v.end(), __v.size());
28080b57cec5SDimitry Andric    }
28090b57cec5SDimitry Andric}
28100b57cec5SDimitry Andric
28110b57cec5SDimitry Andrictemplate <class _Allocator>
2812bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
28130b57cec5SDimitry Andricvector<bool, _Allocator>&
28140b57cec5SDimitry Andricvector<bool, _Allocator>::operator=(const vector& __v)
28150b57cec5SDimitry Andric{
2816bdd1243dSDimitry Andric    if (this != std::addressof(__v))
28170b57cec5SDimitry Andric    {
28180b57cec5SDimitry Andric        __copy_assign_alloc(__v);
28190b57cec5SDimitry Andric        if (__v.__size_)
28200b57cec5SDimitry Andric        {
28210b57cec5SDimitry Andric            if (__v.__size_ > capacity())
28220b57cec5SDimitry Andric            {
28230b57cec5SDimitry Andric                __vdeallocate();
28240b57cec5SDimitry Andric                __vallocate(__v.__size_);
28250b57cec5SDimitry Andric            }
2826bdd1243dSDimitry Andric            std::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
28270b57cec5SDimitry Andric        }
28280b57cec5SDimitry Andric        __size_ = __v.__size_;
28290b57cec5SDimitry Andric    }
28300b57cec5SDimitry Andric    return *this;
28310b57cec5SDimitry Andric}
28320b57cec5SDimitry Andric
28330b57cec5SDimitry Andrictemplate <class _Allocator>
2834bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 vector<bool, _Allocator>::vector(vector&& __v)
2835*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
28360b57cec5SDimitry Andric    _NOEXCEPT
28370b57cec5SDimitry Andric#else
28380b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
28390b57cec5SDimitry Andric#endif
28400b57cec5SDimitry Andric    : __begin_(__v.__begin_),
28410b57cec5SDimitry Andric      __size_(__v.__size_),
2842bdd1243dSDimitry Andric      __cap_alloc_(std::move(__v.__cap_alloc_)) {
28430b57cec5SDimitry Andric    __v.__begin_ = nullptr;
28440b57cec5SDimitry Andric    __v.__size_ = 0;
28450b57cec5SDimitry Andric    __v.__cap() = 0;
28460b57cec5SDimitry Andric}
28470b57cec5SDimitry Andric
28480b57cec5SDimitry Andrictemplate <class _Allocator>
2849bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
285081ad6265SDimitry Andricvector<bool, _Allocator>::vector(vector&& __v, const __type_identity_t<allocator_type>& __a)
28510b57cec5SDimitry Andric    : __begin_(nullptr),
28520b57cec5SDimitry Andric      __size_(0),
28530b57cec5SDimitry Andric      __cap_alloc_(0, __a)
28540b57cec5SDimitry Andric{
28550b57cec5SDimitry Andric    if (__a == allocator_type(__v.__alloc()))
28560b57cec5SDimitry Andric    {
28570b57cec5SDimitry Andric        this->__begin_ = __v.__begin_;
28580b57cec5SDimitry Andric        this->__size_ = __v.__size_;
28590b57cec5SDimitry Andric        this->__cap() = __v.__cap();
28600b57cec5SDimitry Andric        __v.__begin_ = nullptr;
28610b57cec5SDimitry Andric        __v.__cap() = __v.__size_ = 0;
28620b57cec5SDimitry Andric    }
28630b57cec5SDimitry Andric    else if (__v.size() > 0)
28640b57cec5SDimitry Andric    {
28650b57cec5SDimitry Andric        __vallocate(__v.size());
2866*06c3fb27SDimitry Andric        __construct_at_end(__v.begin(), __v.end(), __v.size());
28670b57cec5SDimitry Andric    }
28680b57cec5SDimitry Andric}
28690b57cec5SDimitry Andric
28700b57cec5SDimitry Andrictemplate <class _Allocator>
2871bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
28720b57cec5SDimitry Andricvector<bool, _Allocator>&
28730b57cec5SDimitry Andricvector<bool, _Allocator>::operator=(vector&& __v)
28740b57cec5SDimitry Andric    _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
28750b57cec5SDimitry Andric{
28760b57cec5SDimitry Andric    __move_assign(__v, integral_constant<bool,
28770b57cec5SDimitry Andric          __storage_traits::propagate_on_container_move_assignment::value>());
28780b57cec5SDimitry Andric    return *this;
28790b57cec5SDimitry Andric}
28800b57cec5SDimitry Andric
28810b57cec5SDimitry Andrictemplate <class _Allocator>
2882bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void
28830b57cec5SDimitry Andricvector<bool, _Allocator>::__move_assign(vector& __c, false_type)
28840b57cec5SDimitry Andric{
28850b57cec5SDimitry Andric    if (__alloc() != __c.__alloc())
28860b57cec5SDimitry Andric        assign(__c.begin(), __c.end());
28870b57cec5SDimitry Andric    else
28880b57cec5SDimitry Andric        __move_assign(__c, true_type());
28890b57cec5SDimitry Andric}
28900b57cec5SDimitry Andric
28910b57cec5SDimitry Andrictemplate <class _Allocator>
2892bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void
28930b57cec5SDimitry Andricvector<bool, _Allocator>::__move_assign(vector& __c, true_type)
28940b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
28950b57cec5SDimitry Andric{
28960b57cec5SDimitry Andric    __vdeallocate();
28970b57cec5SDimitry Andric    __move_assign_alloc(__c);
28980b57cec5SDimitry Andric    this->__begin_ = __c.__begin_;
28990b57cec5SDimitry Andric    this->__size_ = __c.__size_;
29000b57cec5SDimitry Andric    this->__cap() = __c.__cap();
29010b57cec5SDimitry Andric    __c.__begin_ = nullptr;
29020b57cec5SDimitry Andric    __c.__cap() = __c.__size_ = 0;
29030b57cec5SDimitry Andric}
29040b57cec5SDimitry Andric
29050b57cec5SDimitry Andrictemplate <class _Allocator>
2906bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void
29070b57cec5SDimitry Andricvector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
29080b57cec5SDimitry Andric{
29090b57cec5SDimitry Andric    __size_ = 0;
29100b57cec5SDimitry Andric    if (__n > 0)
29110b57cec5SDimitry Andric    {
29120b57cec5SDimitry Andric        size_type __c = capacity();
29130b57cec5SDimitry Andric        if (__n <= __c)
29140b57cec5SDimitry Andric            __size_ = __n;
29150b57cec5SDimitry Andric        else
29160b57cec5SDimitry Andric        {
2917349cc55cSDimitry Andric            vector __v(get_allocator());
29180b57cec5SDimitry Andric            __v.reserve(__recommend(__n));
29190b57cec5SDimitry Andric            __v.__size_ = __n;
29200b57cec5SDimitry Andric            swap(__v);
29210b57cec5SDimitry Andric        }
2922bdd1243dSDimitry Andric        std::fill_n(begin(), __n, __x);
29230b57cec5SDimitry Andric    }
29240b57cec5SDimitry Andric}
29250b57cec5SDimitry Andric
29260b57cec5SDimitry Andrictemplate <class _Allocator>
29270b57cec5SDimitry Andrictemplate <class _InputIterator>
2928*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename enable_if <__has_exactly_input_iterator_category<_InputIterator>::value,
29290b57cec5SDimitry Andric   void
29300b57cec5SDimitry Andric>::type
29310b57cec5SDimitry Andricvector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
29320b57cec5SDimitry Andric{
2933*06c3fb27SDimitry Andric  __assign_with_sentinel(__first, __last);
2934*06c3fb27SDimitry Andric}
2935*06c3fb27SDimitry Andric
2936*06c3fb27SDimitry Andrictemplate <class _Allocator>
2937*06c3fb27SDimitry Andrictemplate <class _Iterator, class _Sentinel>
2938*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
2939*06c3fb27SDimitry Andricvoid vector<bool, _Allocator>::__assign_with_sentinel(_Iterator __first, _Sentinel __last) {
29400b57cec5SDimitry Andric    clear();
29410b57cec5SDimitry Andric    for (; __first != __last; ++__first)
29420b57cec5SDimitry Andric        push_back(*__first);
29430b57cec5SDimitry Andric}
29440b57cec5SDimitry Andric
29450b57cec5SDimitry Andrictemplate <class _Allocator>
29460b57cec5SDimitry Andrictemplate <class _ForwardIterator>
2947bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
29480b57cec5SDimitry Andrictypename enable_if
29490b57cec5SDimitry Andric<
2950*06c3fb27SDimitry Andric    __has_forward_iterator_category<_ForwardIterator>::value,
29510b57cec5SDimitry Andric   void
29520b57cec5SDimitry Andric>::type
29530b57cec5SDimitry Andricvector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
29540b57cec5SDimitry Andric{
2955*06c3fb27SDimitry Andric  __assign_with_size(__first, __last, std::distance(__first, __last));
2956*06c3fb27SDimitry Andric}
2957*06c3fb27SDimitry Andric
2958*06c3fb27SDimitry Andrictemplate <class _Allocator>
2959*06c3fb27SDimitry Andrictemplate <class _ForwardIterator, class _Sentinel>
2960*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
2961*06c3fb27SDimitry Andricvoid vector<bool, _Allocator>::__assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __ns) {
2962*06c3fb27SDimitry Andric    _LIBCPP_ASSERT_VALID_INPUT_RANGE(__ns >= 0, "invalid range specified");
2963*06c3fb27SDimitry Andric
29640b57cec5SDimitry Andric    clear();
2965*06c3fb27SDimitry Andric
29660b57cec5SDimitry Andric    const size_t __n = static_cast<size_type>(__ns);
29670b57cec5SDimitry Andric    if (__n)
29680b57cec5SDimitry Andric    {
29690b57cec5SDimitry Andric        if (__n > capacity())
29700b57cec5SDimitry Andric        {
29710b57cec5SDimitry Andric            __vdeallocate();
29720b57cec5SDimitry Andric            __vallocate(__n);
29730b57cec5SDimitry Andric        }
2974*06c3fb27SDimitry Andric        __construct_at_end(__first, __last, __n);
29750b57cec5SDimitry Andric    }
29760b57cec5SDimitry Andric}
29770b57cec5SDimitry Andric
29780b57cec5SDimitry Andrictemplate <class _Allocator>
2979bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void
29800b57cec5SDimitry Andricvector<bool, _Allocator>::reserve(size_type __n)
29810b57cec5SDimitry Andric{
29820b57cec5SDimitry Andric    if (__n > capacity())
29830b57cec5SDimitry Andric    {
2984349cc55cSDimitry Andric        if (__n > max_size())
2985349cc55cSDimitry Andric            this->__throw_length_error();
2986349cc55cSDimitry Andric        vector __v(this->get_allocator());
29870b57cec5SDimitry Andric        __v.__vallocate(__n);
2988*06c3fb27SDimitry Andric        __v.__construct_at_end(this->begin(), this->end(), this->size());
29890b57cec5SDimitry Andric        swap(__v);
29900b57cec5SDimitry Andric    }
29910b57cec5SDimitry Andric}
29920b57cec5SDimitry Andric
29930b57cec5SDimitry Andrictemplate <class _Allocator>
2994bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void
29950b57cec5SDimitry Andricvector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
29960b57cec5SDimitry Andric{
29970b57cec5SDimitry Andric    if (__external_cap_to_internal(size()) > __cap())
29980b57cec5SDimitry Andric    {
2999*06c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
30000b57cec5SDimitry Andric        try
30010b57cec5SDimitry Andric        {
3002*06c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
30030b57cec5SDimitry Andric            vector(*this, allocator_type(__alloc())).swap(*this);
3004*06c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
30050b57cec5SDimitry Andric        }
30060b57cec5SDimitry Andric        catch (...)
30070b57cec5SDimitry Andric        {
30080b57cec5SDimitry Andric        }
3009*06c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
30100b57cec5SDimitry Andric    }
30110b57cec5SDimitry Andric}
30120b57cec5SDimitry Andric
30130b57cec5SDimitry Andrictemplate <class _Allocator>
30140b57cec5SDimitry Andrictypename vector<bool, _Allocator>::reference
30150b57cec5SDimitry Andricvector<bool, _Allocator>::at(size_type __n)
30160b57cec5SDimitry Andric{
30170b57cec5SDimitry Andric    if (__n >= size())
30180b57cec5SDimitry Andric        this->__throw_out_of_range();
30190b57cec5SDimitry Andric    return (*this)[__n];
30200b57cec5SDimitry Andric}
30210b57cec5SDimitry Andric
30220b57cec5SDimitry Andrictemplate <class _Allocator>
30230b57cec5SDimitry Andrictypename vector<bool, _Allocator>::const_reference
30240b57cec5SDimitry Andricvector<bool, _Allocator>::at(size_type __n) const
30250b57cec5SDimitry Andric{
30260b57cec5SDimitry Andric    if (__n >= size())
30270b57cec5SDimitry Andric        this->__throw_out_of_range();
30280b57cec5SDimitry Andric    return (*this)[__n];
30290b57cec5SDimitry Andric}
30300b57cec5SDimitry Andric
30310b57cec5SDimitry Andrictemplate <class _Allocator>
3032bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void
30330b57cec5SDimitry Andricvector<bool, _Allocator>::push_back(const value_type& __x)
30340b57cec5SDimitry Andric{
30350b57cec5SDimitry Andric    if (this->__size_ == this->capacity())
30360b57cec5SDimitry Andric        reserve(__recommend(this->__size_ + 1));
30370b57cec5SDimitry Andric    ++this->__size_;
30380b57cec5SDimitry Andric    back() = __x;
30390b57cec5SDimitry Andric}
30400b57cec5SDimitry Andric
30410b57cec5SDimitry Andrictemplate <class _Allocator>
3042bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
30430b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
30440b57cec5SDimitry Andric{
30450b57cec5SDimitry Andric    iterator __r;
30460b57cec5SDimitry Andric    if (size() < capacity())
30470b57cec5SDimitry Andric    {
30480b57cec5SDimitry Andric        const_iterator __old_end = end();
30490b57cec5SDimitry Andric        ++__size_;
3050bdd1243dSDimitry Andric        std::copy_backward(__position, __old_end, end());
30510b57cec5SDimitry Andric        __r = __const_iterator_cast(__position);
30520b57cec5SDimitry Andric    }
30530b57cec5SDimitry Andric    else
30540b57cec5SDimitry Andric    {
3055349cc55cSDimitry Andric        vector __v(get_allocator());
30560b57cec5SDimitry Andric        __v.reserve(__recommend(__size_ + 1));
30570b57cec5SDimitry Andric        __v.__size_ = __size_ + 1;
3058bdd1243dSDimitry Andric        __r = std::copy(cbegin(), __position, __v.begin());
3059bdd1243dSDimitry Andric        std::copy_backward(__position, cend(), __v.end());
30600b57cec5SDimitry Andric        swap(__v);
30610b57cec5SDimitry Andric    }
30620b57cec5SDimitry Andric    *__r = __x;
30630b57cec5SDimitry Andric    return __r;
30640b57cec5SDimitry Andric}
30650b57cec5SDimitry Andric
30660b57cec5SDimitry Andrictemplate <class _Allocator>
3067bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename vector<bool, _Allocator>::iterator
30680b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
30690b57cec5SDimitry Andric{
30700b57cec5SDimitry Andric    iterator __r;
30710b57cec5SDimitry Andric    size_type __c = capacity();
30720b57cec5SDimitry Andric    if (__n <= __c && size() <= __c - __n)
30730b57cec5SDimitry Andric    {
30740b57cec5SDimitry Andric        const_iterator __old_end = end();
30750b57cec5SDimitry Andric        __size_ += __n;
3076bdd1243dSDimitry Andric        std::copy_backward(__position, __old_end, end());
30770b57cec5SDimitry Andric        __r = __const_iterator_cast(__position);
30780b57cec5SDimitry Andric    }
30790b57cec5SDimitry Andric    else
30800b57cec5SDimitry Andric    {
3081349cc55cSDimitry Andric        vector __v(get_allocator());
30820b57cec5SDimitry Andric        __v.reserve(__recommend(__size_ + __n));
30830b57cec5SDimitry Andric        __v.__size_ = __size_ + __n;
3084bdd1243dSDimitry Andric        __r = std::copy(cbegin(), __position, __v.begin());
3085bdd1243dSDimitry Andric        std::copy_backward(__position, cend(), __v.end());
30860b57cec5SDimitry Andric        swap(__v);
30870b57cec5SDimitry Andric    }
3088bdd1243dSDimitry Andric    std::fill_n(__r, __n, __x);
30890b57cec5SDimitry Andric    return __r;
30900b57cec5SDimitry Andric}
30910b57cec5SDimitry Andric
30920b57cec5SDimitry Andrictemplate <class _Allocator>
30930b57cec5SDimitry Andrictemplate <class _InputIterator>
3094*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename enable_if <__has_exactly_input_iterator_category<_InputIterator>::value,
30950b57cec5SDimitry Andric    typename vector<bool, _Allocator>::iterator
30960b57cec5SDimitry Andric>::type
30970b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
30980b57cec5SDimitry Andric{
3099*06c3fb27SDimitry Andric  return __insert_with_sentinel(__position, __first, __last);
3100*06c3fb27SDimitry Andric}
3101*06c3fb27SDimitry Andric
3102*06c3fb27SDimitry Andrictemplate <class _Allocator>
3103*06c3fb27SDimitry Andrictemplate <class _InputIterator, class _Sentinel>
3104*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
3105*06c3fb27SDimitry Andrictypename vector<bool, _Allocator>::iterator
3106*06c3fb27SDimitry Andricvector<bool, _Allocator>::__insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last) {
31070b57cec5SDimitry Andric    difference_type __off = __position - begin();
31080b57cec5SDimitry Andric    iterator __p = __const_iterator_cast(__position);
31090b57cec5SDimitry Andric    iterator __old_end = end();
31100b57cec5SDimitry Andric    for (; size() != capacity() && __first != __last; ++__first)
31110b57cec5SDimitry Andric    {
31120b57cec5SDimitry Andric        ++this->__size_;
31130b57cec5SDimitry Andric        back() = *__first;
31140b57cec5SDimitry Andric    }
3115349cc55cSDimitry Andric    vector __v(get_allocator());
31160b57cec5SDimitry Andric    if (__first != __last)
31170b57cec5SDimitry Andric    {
3118*06c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
31190b57cec5SDimitry Andric        try
31200b57cec5SDimitry Andric        {
3121*06c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
3122*06c3fb27SDimitry Andric            __v.__assign_with_sentinel(std::move(__first), std::move(__last));
31230b57cec5SDimitry Andric            difference_type __old_size = static_cast<difference_type>(__old_end - begin());
31240b57cec5SDimitry Andric            difference_type __old_p = __p - begin();
31250b57cec5SDimitry Andric            reserve(__recommend(size() + __v.size()));
31260b57cec5SDimitry Andric            __p = begin() + __old_p;
31270b57cec5SDimitry Andric            __old_end = begin() + __old_size;
3128*06c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
31290b57cec5SDimitry Andric        }
31300b57cec5SDimitry Andric        catch (...)
31310b57cec5SDimitry Andric        {
31320b57cec5SDimitry Andric            erase(__old_end, end());
31330b57cec5SDimitry Andric            throw;
31340b57cec5SDimitry Andric        }
3135*06c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
31360b57cec5SDimitry Andric    }
3137bdd1243dSDimitry Andric    __p = std::rotate(__p, __old_end, end());
31380b57cec5SDimitry Andric    insert(__p, __v.begin(), __v.end());
31390b57cec5SDimitry Andric    return begin() + __off;
31400b57cec5SDimitry Andric}
31410b57cec5SDimitry Andric
31420b57cec5SDimitry Andrictemplate <class _Allocator>
31430b57cec5SDimitry Andrictemplate <class _ForwardIterator>
3144bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
31450b57cec5SDimitry Andrictypename enable_if
31460b57cec5SDimitry Andric<
3147*06c3fb27SDimitry Andric    __has_forward_iterator_category<_ForwardIterator>::value,
31480b57cec5SDimitry Andric    typename vector<bool, _Allocator>::iterator
31490b57cec5SDimitry Andric>::type
31500b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
31510b57cec5SDimitry Andric{
3152*06c3fb27SDimitry Andric  return __insert_with_size(__position, __first, __last, std::distance(__first, __last));
3153*06c3fb27SDimitry Andric}
3154*06c3fb27SDimitry Andric
3155*06c3fb27SDimitry Andrictemplate <class _Allocator>
3156*06c3fb27SDimitry Andrictemplate <class _ForwardIterator, class _Sentinel>
3157*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI
3158*06c3fb27SDimitry Andrictypename vector<bool, _Allocator>::iterator
3159*06c3fb27SDimitry Andricvector<bool, _Allocator>::__insert_with_size(const_iterator __position, _ForwardIterator __first, _Sentinel __last,
3160*06c3fb27SDimitry Andric                                             difference_type __n_signed) {
3161*06c3fb27SDimitry Andric    _LIBCPP_ASSERT_VALID_INPUT_RANGE(__n_signed >= 0, "invalid range specified");
31620b57cec5SDimitry Andric    const size_type __n = static_cast<size_type>(__n_signed);
31630b57cec5SDimitry Andric    iterator __r;
31640b57cec5SDimitry Andric    size_type __c = capacity();
31650b57cec5SDimitry Andric    if (__n <= __c && size() <= __c - __n)
31660b57cec5SDimitry Andric    {
31670b57cec5SDimitry Andric        const_iterator __old_end = end();
31680b57cec5SDimitry Andric        __size_ += __n;
3169bdd1243dSDimitry Andric        std::copy_backward(__position, __old_end, end());
31700b57cec5SDimitry Andric        __r = __const_iterator_cast(__position);
31710b57cec5SDimitry Andric    }
31720b57cec5SDimitry Andric    else
31730b57cec5SDimitry Andric    {
3174349cc55cSDimitry Andric        vector __v(get_allocator());
31750b57cec5SDimitry Andric        __v.reserve(__recommend(__size_ + __n));
31760b57cec5SDimitry Andric        __v.__size_ = __size_ + __n;
3177bdd1243dSDimitry Andric        __r = std::copy(cbegin(), __position, __v.begin());
3178bdd1243dSDimitry Andric        std::copy_backward(__position, cend(), __v.end());
31790b57cec5SDimitry Andric        swap(__v);
31800b57cec5SDimitry Andric    }
3181*06c3fb27SDimitry Andric    std::__copy<_ClassicAlgPolicy>(__first, __last, __r);
31820b57cec5SDimitry Andric    return __r;
31830b57cec5SDimitry Andric}
31840b57cec5SDimitry Andric
31850b57cec5SDimitry Andrictemplate <class _Allocator>
3186bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
31870b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator
31880b57cec5SDimitry Andricvector<bool, _Allocator>::erase(const_iterator __position)
31890b57cec5SDimitry Andric{
31900b57cec5SDimitry Andric    iterator __r = __const_iterator_cast(__position);
3191bdd1243dSDimitry Andric    std::copy(__position + 1, this->cend(), __r);
31920b57cec5SDimitry Andric    --__size_;
31930b57cec5SDimitry Andric    return __r;
31940b57cec5SDimitry Andric}
31950b57cec5SDimitry Andric
31960b57cec5SDimitry Andrictemplate <class _Allocator>
3197bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
31980b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator
31990b57cec5SDimitry Andricvector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
32000b57cec5SDimitry Andric{
32010b57cec5SDimitry Andric    iterator __r = __const_iterator_cast(__first);
32020b57cec5SDimitry Andric    difference_type __d = __last - __first;
3203bdd1243dSDimitry Andric    std::copy(__last, this->cend(), __r);
32040b57cec5SDimitry Andric    __size_ -= __d;
32050b57cec5SDimitry Andric    return __r;
32060b57cec5SDimitry Andric}
32070b57cec5SDimitry Andric
32080b57cec5SDimitry Andrictemplate <class _Allocator>
3209bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void
32100b57cec5SDimitry Andricvector<bool, _Allocator>::swap(vector& __x)
32110b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
32120b57cec5SDimitry Andric    _NOEXCEPT
32130b57cec5SDimitry Andric#else
32140b57cec5SDimitry Andric    _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
32150b57cec5SDimitry Andric                __is_nothrow_swappable<allocator_type>::value)
32160b57cec5SDimitry Andric#endif
32170b57cec5SDimitry Andric{
3218bdd1243dSDimitry Andric    std::swap(this->__begin_, __x.__begin_);
3219bdd1243dSDimitry Andric    std::swap(this->__size_, __x.__size_);
3220bdd1243dSDimitry Andric    std::swap(this->__cap(), __x.__cap());
3221bdd1243dSDimitry Andric    std::__swap_allocator(this->__alloc(), __x.__alloc(),
32220b57cec5SDimitry Andric        integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
32230b57cec5SDimitry Andric}
32240b57cec5SDimitry Andric
32250b57cec5SDimitry Andrictemplate <class _Allocator>
3226bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void
32270b57cec5SDimitry Andricvector<bool, _Allocator>::resize(size_type __sz, value_type __x)
32280b57cec5SDimitry Andric{
32290b57cec5SDimitry Andric    size_type __cs = size();
32300b57cec5SDimitry Andric    if (__cs < __sz)
32310b57cec5SDimitry Andric    {
32320b57cec5SDimitry Andric        iterator __r;
32330b57cec5SDimitry Andric        size_type __c = capacity();
32340b57cec5SDimitry Andric        size_type __n = __sz - __cs;
32350b57cec5SDimitry Andric        if (__n <= __c && __cs <= __c - __n)
32360b57cec5SDimitry Andric        {
32370b57cec5SDimitry Andric            __r = end();
32380b57cec5SDimitry Andric            __size_ += __n;
32390b57cec5SDimitry Andric        }
32400b57cec5SDimitry Andric        else
32410b57cec5SDimitry Andric        {
3242349cc55cSDimitry Andric            vector __v(get_allocator());
32430b57cec5SDimitry Andric            __v.reserve(__recommend(__size_ + __n));
32440b57cec5SDimitry Andric            __v.__size_ = __size_ + __n;
3245bdd1243dSDimitry Andric            __r = std::copy(cbegin(), cend(), __v.begin());
32460b57cec5SDimitry Andric            swap(__v);
32470b57cec5SDimitry Andric        }
3248bdd1243dSDimitry Andric        std::fill_n(__r, __n, __x);
32490b57cec5SDimitry Andric    }
32500b57cec5SDimitry Andric    else
32510b57cec5SDimitry Andric        __size_ = __sz;
32520b57cec5SDimitry Andric}
32530b57cec5SDimitry Andric
32540b57cec5SDimitry Andrictemplate <class _Allocator>
3255bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void
32560b57cec5SDimitry Andricvector<bool, _Allocator>::flip() _NOEXCEPT
32570b57cec5SDimitry Andric{
32580b57cec5SDimitry Andric    // do middle whole words
32590b57cec5SDimitry Andric    size_type __n = __size_;
32600b57cec5SDimitry Andric    __storage_pointer __p = __begin_;
32610b57cec5SDimitry Andric    for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
32620b57cec5SDimitry Andric        *__p = ~*__p;
32630b57cec5SDimitry Andric    // do last partial word
32640b57cec5SDimitry Andric    if (__n > 0)
32650b57cec5SDimitry Andric    {
32660b57cec5SDimitry Andric        __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
32670b57cec5SDimitry Andric        __storage_type __b = *__p & __m;
32680b57cec5SDimitry Andric        *__p &= ~__m;
32690b57cec5SDimitry Andric        *__p |= ~__b & __m;
32700b57cec5SDimitry Andric    }
32710b57cec5SDimitry Andric}
32720b57cec5SDimitry Andric
32730b57cec5SDimitry Andrictemplate <class _Allocator>
3274bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 bool
32750b57cec5SDimitry Andricvector<bool, _Allocator>::__invariants() const
32760b57cec5SDimitry Andric{
32770b57cec5SDimitry Andric    if (this->__begin_ == nullptr)
32780b57cec5SDimitry Andric    {
32790b57cec5SDimitry Andric        if (this->__size_ != 0 || this->__cap() != 0)
32800b57cec5SDimitry Andric            return false;
32810b57cec5SDimitry Andric    }
32820b57cec5SDimitry Andric    else
32830b57cec5SDimitry Andric    {
32840b57cec5SDimitry Andric        if (this->__cap() == 0)
32850b57cec5SDimitry Andric            return false;
32860b57cec5SDimitry Andric        if (this->__size_ > this->capacity())
32870b57cec5SDimitry Andric            return false;
32880b57cec5SDimitry Andric    }
32890b57cec5SDimitry Andric    return true;
32900b57cec5SDimitry Andric}
32910b57cec5SDimitry Andric
32920b57cec5SDimitry Andrictemplate <class _Allocator>
3293bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 size_t
32940b57cec5SDimitry Andricvector<bool, _Allocator>::__hash_code() const _NOEXCEPT
32950b57cec5SDimitry Andric{
32960b57cec5SDimitry Andric    size_t __h = 0;
32970b57cec5SDimitry Andric    // do middle whole words
32980b57cec5SDimitry Andric    size_type __n = __size_;
32990b57cec5SDimitry Andric    __storage_pointer __p = __begin_;
33000b57cec5SDimitry Andric    for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
33010b57cec5SDimitry Andric        __h ^= *__p;
33020b57cec5SDimitry Andric    // do last partial word
33030b57cec5SDimitry Andric    if (__n > 0)
33040b57cec5SDimitry Andric    {
33050b57cec5SDimitry Andric        const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
33060b57cec5SDimitry Andric        __h ^= *__p & __m;
33070b57cec5SDimitry Andric    }
33080b57cec5SDimitry Andric    return __h;
33090b57cec5SDimitry Andric}
33100b57cec5SDimitry Andric
33110b57cec5SDimitry Andrictemplate <class _Allocator>
33120b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
331381ad6265SDimitry Andric    : public __unary_function<vector<bool, _Allocator>, size_t>
33140b57cec5SDimitry Andric{
3315bdd1243dSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
33160b57cec5SDimitry Andric    size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
33170b57cec5SDimitry Andric        {return __vec.__hash_code();}
33180b57cec5SDimitry Andric};
33190b57cec5SDimitry Andric
33200b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
3321bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
3322bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
33230b57cec5SDimitry Andricbool
33240b57cec5SDimitry Andricoperator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
33250b57cec5SDimitry Andric{
33260b57cec5SDimitry Andric    const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
3327bdd1243dSDimitry Andric    return __sz == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
33280b57cec5SDimitry Andric}
33290b57cec5SDimitry Andric
3330*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER <= 17
3331*06c3fb27SDimitry Andric
33320b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
3333bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
33340b57cec5SDimitry Andricbool
33350b57cec5SDimitry Andricoperator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
33360b57cec5SDimitry Andric{
33370b57cec5SDimitry Andric    return !(__x == __y);
33380b57cec5SDimitry Andric}
33390b57cec5SDimitry Andric
33400b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
3341bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
33420b57cec5SDimitry Andricbool
33430b57cec5SDimitry Andricoperator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
33440b57cec5SDimitry Andric{
3345bdd1243dSDimitry Andric    return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
33460b57cec5SDimitry Andric}
33470b57cec5SDimitry Andric
33480b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
3349bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
33500b57cec5SDimitry Andricbool
33510b57cec5SDimitry Andricoperator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
33520b57cec5SDimitry Andric{
33530b57cec5SDimitry Andric    return __y < __x;
33540b57cec5SDimitry Andric}
33550b57cec5SDimitry Andric
33560b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
3357bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
33580b57cec5SDimitry Andricbool
33590b57cec5SDimitry Andricoperator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
33600b57cec5SDimitry Andric{
33610b57cec5SDimitry Andric    return !(__x < __y);
33620b57cec5SDimitry Andric}
33630b57cec5SDimitry Andric
33640b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
3365bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
33660b57cec5SDimitry Andricbool
33670b57cec5SDimitry Andricoperator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
33680b57cec5SDimitry Andric{
33690b57cec5SDimitry Andric    return !(__y < __x);
33700b57cec5SDimitry Andric}
33710b57cec5SDimitry Andric
3372*06c3fb27SDimitry Andric#else // _LIBCPP_STD_VER <= 17
3373*06c3fb27SDimitry Andric
3374*06c3fb27SDimitry Andrictemplate <class _Tp, class _Allocator>
3375*06c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr __synth_three_way_result<_Tp>
3376*06c3fb27SDimitry Andricoperator<=>(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
3377*06c3fb27SDimitry Andric    return std::lexicographical_compare_three_way(
3378*06c3fb27SDimitry Andric        __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way<_Tp, _Tp>);
3379*06c3fb27SDimitry Andric}
3380*06c3fb27SDimitry Andric
3381*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER <= 17
3382*06c3fb27SDimitry Andric
33830b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
3384bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
3385bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI
33860b57cec5SDimitry Andricvoid
33870b57cec5SDimitry Andricswap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
33880b57cec5SDimitry Andric    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
33890b57cec5SDimitry Andric{
33900b57cec5SDimitry Andric    __x.swap(__y);
33910b57cec5SDimitry Andric}
33920b57cec5SDimitry Andric
3393*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
33940b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Up>
3395bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
3396bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
33975ffd83dbSDimitry Andricerase(vector<_Tp, _Allocator>& __c, const _Up& __v) {
33985ffd83dbSDimitry Andric  auto __old_size = __c.size();
3399bdd1243dSDimitry Andric  __c.erase(std::remove(__c.begin(), __c.end(), __v), __c.end());
34005ffd83dbSDimitry Andric  return __old_size - __c.size();
34015ffd83dbSDimitry Andric}
34020b57cec5SDimitry Andric
34030b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Predicate>
3404bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20
3405bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
34065ffd83dbSDimitry Andricerase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) {
34075ffd83dbSDimitry Andric  auto __old_size = __c.size();
3408bdd1243dSDimitry Andric  __c.erase(std::remove_if(__c.begin(), __c.end(), __pred), __c.end());
34095ffd83dbSDimitry Andric  return __old_size - __c.size();
34105ffd83dbSDimitry Andric}
341181ad6265SDimitry Andric
341281ad6265SDimitry Andrictemplate <>
3413bdd1243dSDimitry Andricinline constexpr bool __format::__enable_insertable<vector<char>> = true;
341481ad6265SDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
341581ad6265SDimitry Andrictemplate <>
3416bdd1243dSDimitry Andricinline constexpr bool __format::__enable_insertable<vector<wchar_t>> = true;
34170b57cec5SDimitry Andric#endif
34180b57cec5SDimitry Andric
3419*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20
342081ad6265SDimitry Andric
3421*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
3422*06c3fb27SDimitry Andrictemplate <class _Tp, class _CharT>
3423bdd1243dSDimitry Andric// Since is-vector-bool-reference is only used once it's inlined here.
3424bdd1243dSDimitry Andric  requires same_as<typename _Tp::__container, vector<bool, typename _Tp::__container::allocator_type>>
3425*06c3fb27SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS formatter<_Tp, _CharT> {
3426bdd1243dSDimitry Andricprivate:
3427*06c3fb27SDimitry Andric  formatter<bool, _CharT> __underlying_;
3428bdd1243dSDimitry Andric
3429bdd1243dSDimitry Andricpublic:
3430bdd1243dSDimitry Andric  template <class _ParseContext>
3431bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
3432bdd1243dSDimitry Andric        return __underlying_.parse(__ctx);
3433bdd1243dSDimitry Andric  }
3434bdd1243dSDimitry Andric
3435bdd1243dSDimitry Andric  template <class _FormatContext>
3436bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(const _Tp& __ref, _FormatContext& __ctx) const {
3437bdd1243dSDimitry Andric        return __underlying_.format(__ref, __ctx);
3438bdd1243dSDimitry Andric  }
3439bdd1243dSDimitry Andric};
3440*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 23
3441bdd1243dSDimitry Andric
34420b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
34430b57cec5SDimitry Andric
3444*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
3445bdd1243dSDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
3446bdd1243dSDimitry Andricnamespace pmr {
3447bdd1243dSDimitry Andrictemplate <class _ValueT>
3448*06c3fb27SDimitry Andricusing vector _LIBCPP_AVAILABILITY_PMR = std::vector<_ValueT, polymorphic_allocator<_ValueT>>;
3449bdd1243dSDimitry Andric} // namespace pmr
3450bdd1243dSDimitry Andric_LIBCPP_END_NAMESPACE_STD
3451bdd1243dSDimitry Andric#endif
3452bdd1243dSDimitry Andric
34530b57cec5SDimitry Andric_LIBCPP_POP_MACROS
34540b57cec5SDimitry Andric
3455bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
3456bdd1243dSDimitry Andric#  include <algorithm>
3457bdd1243dSDimitry Andric#  include <atomic>
3458bdd1243dSDimitry Andric#  include <concepts>
3459*06c3fb27SDimitry Andric#  include <cstdlib>
3460*06c3fb27SDimitry Andric#  include <type_traits>
3461bdd1243dSDimitry Andric#  include <typeinfo>
3462bdd1243dSDimitry Andric#  include <utility>
3463bdd1243dSDimitry Andric#endif
3464bdd1243dSDimitry Andric
34650b57cec5SDimitry Andric#endif // _LIBCPP_VECTOR
3466