xref: /freebsd/contrib/llvm-project/libcxx/include/vector (revision 50d7464c3fe687c0a3d4dea6b96a5437779a3ef6)
10b57cec5SDimitry Andric// -*- C++ -*-
2349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
100b57cec5SDimitry Andric#ifndef _LIBCPP_VECTOR
110b57cec5SDimitry Andric#define _LIBCPP_VECTOR
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric/*
140b57cec5SDimitry Andric    vector synopsis
150b57cec5SDimitry Andric
160b57cec5SDimitry Andricnamespace std
170b57cec5SDimitry Andric{
180b57cec5SDimitry Andric
190b57cec5SDimitry Andrictemplate <class T, class Allocator = allocator<T> >
200b57cec5SDimitry Andricclass vector
210b57cec5SDimitry Andric{
220b57cec5SDimitry Andricpublic:
230b57cec5SDimitry Andric    typedef T                                        value_type;
240b57cec5SDimitry Andric    typedef Allocator                                allocator_type;
250b57cec5SDimitry Andric    typedef typename allocator_type::reference       reference;
260b57cec5SDimitry Andric    typedef typename allocator_type::const_reference const_reference;
270b57cec5SDimitry Andric    typedef implementation-defined                   iterator;
280b57cec5SDimitry Andric    typedef implementation-defined                   const_iterator;
290b57cec5SDimitry Andric    typedef typename allocator_type::size_type       size_type;
300b57cec5SDimitry Andric    typedef typename allocator_type::difference_type difference_type;
310b57cec5SDimitry Andric    typedef typename allocator_type::pointer         pointer;
320b57cec5SDimitry Andric    typedef typename allocator_type::const_pointer   const_pointer;
330b57cec5SDimitry Andric    typedef std::reverse_iterator<iterator>          reverse_iterator;
340b57cec5SDimitry Andric    typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
350b57cec5SDimitry Andric
360b57cec5SDimitry Andric    vector()
370b57cec5SDimitry Andric        noexcept(is_nothrow_default_constructible<allocator_type>::value);
380b57cec5SDimitry Andric    explicit vector(const allocator_type&);
390b57cec5SDimitry Andric    explicit vector(size_type n);
400b57cec5SDimitry Andric    explicit vector(size_type n, const allocator_type&); // C++14
410b57cec5SDimitry Andric    vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
420b57cec5SDimitry Andric    template <class InputIterator>
430b57cec5SDimitry Andric        vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
440b57cec5SDimitry Andric    vector(const vector& x);
450b57cec5SDimitry Andric    vector(vector&& x)
460b57cec5SDimitry Andric        noexcept(is_nothrow_move_constructible<allocator_type>::value);
470b57cec5SDimitry Andric    vector(initializer_list<value_type> il);
480b57cec5SDimitry Andric    vector(initializer_list<value_type> il, const allocator_type& a);
490b57cec5SDimitry Andric    ~vector();
500b57cec5SDimitry Andric    vector& operator=(const vector& x);
510b57cec5SDimitry Andric    vector& operator=(vector&& x)
520b57cec5SDimitry Andric        noexcept(
530b57cec5SDimitry Andric             allocator_type::propagate_on_container_move_assignment::value ||
540b57cec5SDimitry Andric             allocator_type::is_always_equal::value); // C++17
550b57cec5SDimitry Andric    vector& operator=(initializer_list<value_type> il);
560b57cec5SDimitry Andric    template <class InputIterator>
570b57cec5SDimitry Andric        void assign(InputIterator first, InputIterator last);
580b57cec5SDimitry Andric    void assign(size_type n, const value_type& u);
590b57cec5SDimitry Andric    void assign(initializer_list<value_type> il);
600b57cec5SDimitry Andric
610b57cec5SDimitry Andric    allocator_type get_allocator() const noexcept;
620b57cec5SDimitry Andric
630b57cec5SDimitry Andric    iterator               begin() noexcept;
640b57cec5SDimitry Andric    const_iterator         begin()   const noexcept;
650b57cec5SDimitry Andric    iterator               end() noexcept;
660b57cec5SDimitry Andric    const_iterator         end()     const noexcept;
670b57cec5SDimitry Andric
680b57cec5SDimitry Andric    reverse_iterator       rbegin() noexcept;
690b57cec5SDimitry Andric    const_reverse_iterator rbegin()  const noexcept;
700b57cec5SDimitry Andric    reverse_iterator       rend() noexcept;
710b57cec5SDimitry Andric    const_reverse_iterator rend()    const noexcept;
720b57cec5SDimitry Andric
730b57cec5SDimitry Andric    const_iterator         cbegin()  const noexcept;
740b57cec5SDimitry Andric    const_iterator         cend()    const noexcept;
750b57cec5SDimitry Andric    const_reverse_iterator crbegin() const noexcept;
760b57cec5SDimitry Andric    const_reverse_iterator crend()   const noexcept;
770b57cec5SDimitry Andric
780b57cec5SDimitry Andric    size_type size() const noexcept;
790b57cec5SDimitry Andric    size_type max_size() const noexcept;
800b57cec5SDimitry Andric    size_type capacity() const noexcept;
810b57cec5SDimitry Andric    bool empty() const noexcept;
820b57cec5SDimitry Andric    void reserve(size_type n);
830b57cec5SDimitry Andric    void shrink_to_fit() noexcept;
840b57cec5SDimitry Andric
850b57cec5SDimitry Andric    reference       operator[](size_type n);
860b57cec5SDimitry Andric    const_reference operator[](size_type n) const;
870b57cec5SDimitry Andric    reference       at(size_type n);
880b57cec5SDimitry Andric    const_reference at(size_type n) const;
890b57cec5SDimitry Andric
900b57cec5SDimitry Andric    reference       front();
910b57cec5SDimitry Andric    const_reference front() const;
920b57cec5SDimitry Andric    reference       back();
930b57cec5SDimitry Andric    const_reference back() const;
940b57cec5SDimitry Andric
950b57cec5SDimitry Andric    value_type*       data() noexcept;
960b57cec5SDimitry Andric    const value_type* data() const noexcept;
970b57cec5SDimitry Andric
980b57cec5SDimitry Andric    void push_back(const value_type& x);
990b57cec5SDimitry Andric    void push_back(value_type&& x);
1000b57cec5SDimitry Andric    template <class... Args>
1010b57cec5SDimitry Andric        reference emplace_back(Args&&... args); // reference in C++17
1020b57cec5SDimitry Andric    void pop_back();
1030b57cec5SDimitry Andric
1040b57cec5SDimitry Andric    template <class... Args> iterator emplace(const_iterator position, Args&&... args);
1050b57cec5SDimitry Andric    iterator insert(const_iterator position, const value_type& x);
1060b57cec5SDimitry Andric    iterator insert(const_iterator position, value_type&& x);
1070b57cec5SDimitry Andric    iterator insert(const_iterator position, size_type n, const value_type& x);
1080b57cec5SDimitry Andric    template <class InputIterator>
1090b57cec5SDimitry Andric        iterator insert(const_iterator position, InputIterator first, InputIterator last);
1100b57cec5SDimitry Andric    iterator insert(const_iterator position, initializer_list<value_type> il);
1110b57cec5SDimitry Andric
1120b57cec5SDimitry Andric    iterator erase(const_iterator position);
1130b57cec5SDimitry Andric    iterator erase(const_iterator first, const_iterator last);
1140b57cec5SDimitry Andric
1150b57cec5SDimitry Andric    void clear() noexcept;
1160b57cec5SDimitry Andric
1170b57cec5SDimitry Andric    void resize(size_type sz);
1180b57cec5SDimitry Andric    void resize(size_type sz, const value_type& c);
1190b57cec5SDimitry Andric
1200b57cec5SDimitry Andric    void swap(vector&)
1210b57cec5SDimitry Andric        noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
1220b57cec5SDimitry Andric                 allocator_traits<allocator_type>::is_always_equal::value);  // C++17
1230b57cec5SDimitry Andric
1240b57cec5SDimitry Andric    bool __invariants() const;
1250b57cec5SDimitry Andric};
1260b57cec5SDimitry Andric
1270b57cec5SDimitry Andrictemplate <class Allocator = allocator<T> >
1280b57cec5SDimitry Andricclass vector<bool, Allocator>
1290b57cec5SDimitry Andric{
1300b57cec5SDimitry Andricpublic:
1310b57cec5SDimitry Andric    typedef bool                                     value_type;
1320b57cec5SDimitry Andric    typedef Allocator                                allocator_type;
1330b57cec5SDimitry Andric    typedef implementation-defined                   iterator;
1340b57cec5SDimitry Andric    typedef implementation-defined                   const_iterator;
1350b57cec5SDimitry Andric    typedef typename allocator_type::size_type       size_type;
1360b57cec5SDimitry Andric    typedef typename allocator_type::difference_type difference_type;
1370b57cec5SDimitry Andric    typedef iterator                                 pointer;
1380b57cec5SDimitry Andric    typedef const_iterator                           const_pointer;
1390b57cec5SDimitry Andric    typedef std::reverse_iterator<iterator>          reverse_iterator;
1400b57cec5SDimitry Andric    typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
1410b57cec5SDimitry Andric
1420b57cec5SDimitry Andric    class reference
1430b57cec5SDimitry Andric    {
1440b57cec5SDimitry Andric    public:
1450b57cec5SDimitry Andric        reference(const reference&) noexcept;
1460b57cec5SDimitry Andric        operator bool() const noexcept;
147fe6060f1SDimitry Andric        reference& operator=(bool x) noexcept;
1480b57cec5SDimitry Andric        reference& operator=(const reference& x) noexcept;
1490b57cec5SDimitry Andric        iterator operator&() const noexcept;
1500b57cec5SDimitry Andric        void flip() noexcept;
1510b57cec5SDimitry Andric    };
1520b57cec5SDimitry Andric
1530b57cec5SDimitry Andric    class const_reference
1540b57cec5SDimitry Andric    {
1550b57cec5SDimitry Andric    public:
1560b57cec5SDimitry Andric        const_reference(const reference&) noexcept;
1570b57cec5SDimitry Andric        operator bool() const noexcept;
1580b57cec5SDimitry Andric        const_iterator operator&() const noexcept;
1590b57cec5SDimitry Andric    };
1600b57cec5SDimitry Andric
1610b57cec5SDimitry Andric    vector()
1620b57cec5SDimitry Andric        noexcept(is_nothrow_default_constructible<allocator_type>::value);
1630b57cec5SDimitry Andric    explicit vector(const allocator_type&);
1640b57cec5SDimitry Andric    explicit vector(size_type n, const allocator_type& a = allocator_type()); // C++14
1650b57cec5SDimitry Andric    vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
1660b57cec5SDimitry Andric    template <class InputIterator>
1670b57cec5SDimitry Andric        vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
1680b57cec5SDimitry Andric    vector(const vector& x);
1690b57cec5SDimitry Andric    vector(vector&& x)
1700b57cec5SDimitry Andric        noexcept(is_nothrow_move_constructible<allocator_type>::value);
1710b57cec5SDimitry Andric    vector(initializer_list<value_type> il);
1720b57cec5SDimitry Andric    vector(initializer_list<value_type> il, const allocator_type& a);
1730b57cec5SDimitry Andric    ~vector();
1740b57cec5SDimitry Andric    vector& operator=(const vector& x);
1750b57cec5SDimitry Andric    vector& operator=(vector&& x)
1760b57cec5SDimitry Andric        noexcept(
1770b57cec5SDimitry Andric             allocator_type::propagate_on_container_move_assignment::value ||
1780b57cec5SDimitry Andric             allocator_type::is_always_equal::value); // C++17
1790b57cec5SDimitry Andric    vector& operator=(initializer_list<value_type> il);
1800b57cec5SDimitry Andric    template <class InputIterator>
1810b57cec5SDimitry Andric        void assign(InputIterator first, InputIterator last);
1820b57cec5SDimitry Andric    void assign(size_type n, const value_type& u);
1830b57cec5SDimitry Andric    void assign(initializer_list<value_type> il);
1840b57cec5SDimitry Andric
1850b57cec5SDimitry Andric    allocator_type get_allocator() const noexcept;
1860b57cec5SDimitry Andric
1870b57cec5SDimitry Andric    iterator               begin() noexcept;
1880b57cec5SDimitry Andric    const_iterator         begin()   const noexcept;
1890b57cec5SDimitry Andric    iterator               end() noexcept;
1900b57cec5SDimitry Andric    const_iterator         end()     const noexcept;
1910b57cec5SDimitry Andric
1920b57cec5SDimitry Andric    reverse_iterator       rbegin() noexcept;
1930b57cec5SDimitry Andric    const_reverse_iterator rbegin()  const noexcept;
1940b57cec5SDimitry Andric    reverse_iterator       rend() noexcept;
1950b57cec5SDimitry Andric    const_reverse_iterator rend()    const noexcept;
1960b57cec5SDimitry Andric
1970b57cec5SDimitry Andric    const_iterator         cbegin()  const noexcept;
1980b57cec5SDimitry Andric    const_iterator         cend()    const noexcept;
1990b57cec5SDimitry Andric    const_reverse_iterator crbegin() const noexcept;
2000b57cec5SDimitry Andric    const_reverse_iterator crend()   const noexcept;
2010b57cec5SDimitry Andric
2020b57cec5SDimitry Andric    size_type size() const noexcept;
2030b57cec5SDimitry Andric    size_type max_size() const noexcept;
2040b57cec5SDimitry Andric    size_type capacity() const noexcept;
2050b57cec5SDimitry Andric    bool empty() const noexcept;
2060b57cec5SDimitry Andric    void reserve(size_type n);
2070b57cec5SDimitry Andric    void shrink_to_fit() noexcept;
2080b57cec5SDimitry Andric
2090b57cec5SDimitry Andric    reference       operator[](size_type n);
2100b57cec5SDimitry Andric    const_reference operator[](size_type n) const;
2110b57cec5SDimitry Andric    reference       at(size_type n);
2120b57cec5SDimitry Andric    const_reference at(size_type n) const;
2130b57cec5SDimitry Andric
2140b57cec5SDimitry Andric    reference       front();
2150b57cec5SDimitry Andric    const_reference front() const;
2160b57cec5SDimitry Andric    reference       back();
2170b57cec5SDimitry Andric    const_reference back() const;
2180b57cec5SDimitry Andric
2190b57cec5SDimitry Andric    void push_back(const value_type& x);
2200b57cec5SDimitry Andric    template <class... Args> reference emplace_back(Args&&... args);  // C++14; reference in C++17
2210b57cec5SDimitry Andric    void pop_back();
2220b57cec5SDimitry Andric
2230b57cec5SDimitry Andric    template <class... Args> iterator emplace(const_iterator position, Args&&... args);  // C++14
2240b57cec5SDimitry Andric    iterator insert(const_iterator position, const value_type& x);
2250b57cec5SDimitry Andric    iterator insert(const_iterator position, size_type n, const value_type& x);
2260b57cec5SDimitry Andric    template <class InputIterator>
2270b57cec5SDimitry Andric        iterator insert(const_iterator position, InputIterator first, InputIterator last);
2280b57cec5SDimitry Andric    iterator insert(const_iterator position, initializer_list<value_type> il);
2290b57cec5SDimitry Andric
2300b57cec5SDimitry Andric    iterator erase(const_iterator position);
2310b57cec5SDimitry Andric    iterator erase(const_iterator first, const_iterator last);
2320b57cec5SDimitry Andric
2330b57cec5SDimitry Andric    void clear() noexcept;
2340b57cec5SDimitry Andric
2350b57cec5SDimitry Andric    void resize(size_type sz);
2360b57cec5SDimitry Andric    void resize(size_type sz, value_type x);
2370b57cec5SDimitry Andric
2380b57cec5SDimitry Andric    void swap(vector&)
2390b57cec5SDimitry Andric        noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
2400b57cec5SDimitry Andric                 allocator_traits<allocator_type>::is_always_equal::value);  // C++17
2410b57cec5SDimitry Andric    void flip() noexcept;
2420b57cec5SDimitry Andric
2430b57cec5SDimitry Andric    bool __invariants() const;
2440b57cec5SDimitry Andric};
2450b57cec5SDimitry Andric
2460b57cec5SDimitry Andrictemplate <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
2470b57cec5SDimitry Andric   vector(InputIterator, InputIterator, Allocator = Allocator())
248349cc55cSDimitry Andric   -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17
2490b57cec5SDimitry Andric
2500b57cec5SDimitry Andrictemplate <class Allocator> struct hash<std::vector<bool, Allocator>>;
2510b57cec5SDimitry Andric
2520b57cec5SDimitry Andrictemplate <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
2530b57cec5SDimitry Andrictemplate <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
2540b57cec5SDimitry Andrictemplate <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
2550b57cec5SDimitry Andrictemplate <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
2560b57cec5SDimitry Andrictemplate <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
2570b57cec5SDimitry Andrictemplate <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
2580b57cec5SDimitry Andric
2590b57cec5SDimitry Andrictemplate <class T, class Allocator>
2600b57cec5SDimitry Andricvoid swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
2610b57cec5SDimitry Andric    noexcept(noexcept(x.swap(y)));
2620b57cec5SDimitry Andric
2630b57cec5SDimitry Andrictemplate <class T, class Allocator, class U>
2645ffd83dbSDimitry Andrictypename vector<T, Allocator>::size_type
2655ffd83dbSDimitry Andricerase(vector<T, Allocator>& c, const U& value);       // C++20
2660b57cec5SDimitry Andrictemplate <class T, class Allocator, class Predicate>
2675ffd83dbSDimitry Andrictypename vector<T, Allocator>::size_type
2685ffd83dbSDimitry Andricerase_if(vector<T, Allocator>& c, Predicate pred);    // C++20
2690b57cec5SDimitry Andric
2700b57cec5SDimitry Andric}  // std
2710b57cec5SDimitry Andric
2720b57cec5SDimitry Andric*/
2730b57cec5SDimitry Andric
27481ad6265SDimitry Andric#include <__algorithm/copy.h>
27581ad6265SDimitry Andric#include <__algorithm/equal.h>
27681ad6265SDimitry Andric#include <__algorithm/fill_n.h>
27781ad6265SDimitry Andric#include <__algorithm/lexicographical_compare.h>
27881ad6265SDimitry Andric#include <__algorithm/remove.h>
27981ad6265SDimitry Andric#include <__algorithm/remove_if.h>
28081ad6265SDimitry Andric#include <__algorithm/rotate.h>
28181ad6265SDimitry Andric#include <__algorithm/unwrap_iter.h>
28281ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler
2830b57cec5SDimitry Andric#include <__bit_reference>
28404eeddc0SDimitry Andric#include <__config>
285fe6060f1SDimitry Andric#include <__debug>
28681ad6265SDimitry Andric#include <__format/enable_insertable.h>
28781ad6265SDimitry Andric#include <__functional/hash.h>
28881ad6265SDimitry Andric#include <__functional/unary_function.h>
28981ad6265SDimitry Andric#include <__iterator/advance.h>
290349cc55cSDimitry Andric#include <__iterator/iterator_traits.h>
29181ad6265SDimitry Andric#include <__iterator/reverse_iterator.h>
292fe6060f1SDimitry Andric#include <__iterator/wrap_iter.h>
29381ad6265SDimitry Andric#include <__memory/allocate_at_least.h>
294972a253aSDimitry Andric#include <__memory/pointer_traits.h>
295972a253aSDimitry Andric#include <__memory/swap_allocator.h>
296fe6060f1SDimitry Andric#include <__split_buffer>
297fe6060f1SDimitry Andric#include <__utility/forward.h>
29881ad6265SDimitry Andric#include <__utility/move.h>
29981ad6265SDimitry Andric#include <__utility/swap.h>
300*50d7464cSDimitry Andric#include <__utility/transaction.h>
3010b57cec5SDimitry Andric#include <climits>
30269ade1e0SDimitry Andric#include <cstdlib>
303fe6060f1SDimitry Andric#include <cstring>
304fe6060f1SDimitry Andric#include <iosfwd> // for forward declaration of vector
305fe6060f1SDimitry Andric#include <limits>
3060b57cec5SDimitry Andric#include <memory>
3070b57cec5SDimitry Andric#include <stdexcept>
308fe6060f1SDimitry Andric#include <type_traits>
3090b57cec5SDimitry Andric#include <version>
3100b57cec5SDimitry Andric
31181ad6265SDimitry Andric#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
31281ad6265SDimitry Andric#  include <algorithm>
31381ad6265SDimitry Andric#  include <typeinfo>
31481ad6265SDimitry Andric#  include <utility>
31581ad6265SDimitry Andric#endif
31681ad6265SDimitry Andric
31781ad6265SDimitry Andric// standard-mandated includes
31881ad6265SDimitry Andric
31981ad6265SDimitry Andric// [iterator.range]
32081ad6265SDimitry Andric#include <__iterator/access.h>
32181ad6265SDimitry Andric#include <__iterator/data.h>
32281ad6265SDimitry Andric#include <__iterator/empty.h>
32381ad6265SDimitry Andric#include <__iterator/reverse_access.h>
32481ad6265SDimitry Andric#include <__iterator/size.h>
32581ad6265SDimitry Andric
32681ad6265SDimitry Andric// [vector.syn]
32781ad6265SDimitry Andric#include <compare>
32881ad6265SDimitry Andric#include <initializer_list>
32981ad6265SDimitry Andric
3300b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3310b57cec5SDimitry Andric#  pragma GCC system_header
3320b57cec5SDimitry Andric#endif
3330b57cec5SDimitry Andric
3340b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS
3350b57cec5SDimitry Andric#include <__undef_macros>
3360b57cec5SDimitry Andric
3370b57cec5SDimitry Andric
3380b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
3390b57cec5SDimitry Andric
3400b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator /* = allocator<_Tp> */>
3410b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector
3420b57cec5SDimitry Andric{
3430b57cec5SDimitry Andricprivate:
3440b57cec5SDimitry Andric    typedef allocator<_Tp>                                  __default_allocator_type;
3450b57cec5SDimitry Andricpublic:
3460b57cec5SDimitry Andric    typedef vector                                          __self;
3470b57cec5SDimitry Andric    typedef _Tp                                             value_type;
3480b57cec5SDimitry Andric    typedef _Allocator                                      allocator_type;
349349cc55cSDimitry Andric    typedef allocator_traits<allocator_type>                __alloc_traits;
350349cc55cSDimitry Andric    typedef value_type&                                     reference;
351349cc55cSDimitry Andric    typedef const value_type&                               const_reference;
3524824e7fdSDimitry Andric    typedef typename __alloc_traits::size_type              size_type;
353349cc55cSDimitry Andric    typedef typename __alloc_traits::difference_type        difference_type;
354349cc55cSDimitry Andric    typedef typename __alloc_traits::pointer                pointer;
355349cc55cSDimitry Andric    typedef typename __alloc_traits::const_pointer          const_pointer;
3560b57cec5SDimitry Andric    typedef __wrap_iter<pointer>                            iterator;
3570b57cec5SDimitry Andric    typedef __wrap_iter<const_pointer>                      const_iterator;
3580b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<iterator>               reverse_iterator;
3590b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<const_iterator>         const_reverse_iterator;
3600b57cec5SDimitry Andric
3610b57cec5SDimitry Andric    static_assert((is_same<typename allocator_type::value_type, value_type>::value),
3620b57cec5SDimitry Andric                  "Allocator::value_type must be same type as value_type");
3630b57cec5SDimitry Andric
36461cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
3650b57cec5SDimitry Andric    vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
3660b57cec5SDimitry Andric    {
36704eeddc0SDimitry Andric        _VSTD::__debug_db_insert_c(this);
3680b57cec5SDimitry Andric    }
36961cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
3700b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
3710b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
3720b57cec5SDimitry Andric#else
3730b57cec5SDimitry Andric        _NOEXCEPT
3740b57cec5SDimitry Andric#endif
375d56accc7SDimitry Andric        : __end_cap_(nullptr, __a)
3760b57cec5SDimitry Andric    {
37704eeddc0SDimitry Andric        _VSTD::__debug_db_insert_c(this);
3780b57cec5SDimitry Andric    }
37961cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit vector(size_type __n);
3800b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
38161cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit vector(size_type __n, const allocator_type& __a);
3820b57cec5SDimitry Andric#endif
38361cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(size_type __n, const value_type& __x);
3844824e7fdSDimitry Andric
3854824e7fdSDimitry Andric    template <class = __enable_if_t<__is_allocator<_Allocator>::value> >
38661cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17
3874824e7fdSDimitry Andric    vector(size_type __n, const value_type& __x, const allocator_type& __a)
388d56accc7SDimitry Andric        : __end_cap_(nullptr, __a)
3894824e7fdSDimitry Andric    {
39004eeddc0SDimitry Andric      _VSTD::__debug_db_insert_c(this);
3914824e7fdSDimitry Andric      if (__n > 0)
3924824e7fdSDimitry Andric      {
3934824e7fdSDimitry Andric          __vallocate(__n);
3944824e7fdSDimitry Andric          __construct_at_end(__n, __x);
3954824e7fdSDimitry Andric      }
3964824e7fdSDimitry Andric    }
3974824e7fdSDimitry Andric
3980b57cec5SDimitry Andric    template <class _InputIterator>
39961cfbce3SDimitry Andric        _LIBCPP_CONSTEXPR_AFTER_CXX17
4000b57cec5SDimitry Andric        vector(_InputIterator __first,
401753f127fSDimitry Andric               typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
4020b57cec5SDimitry Andric                                 is_constructible<
4030b57cec5SDimitry Andric                                    value_type,
4040b57cec5SDimitry Andric                                    typename iterator_traits<_InputIterator>::reference>::value,
4050b57cec5SDimitry Andric                                 _InputIterator>::type __last);
4060b57cec5SDimitry Andric    template <class _InputIterator>
40761cfbce3SDimitry Andric        _LIBCPP_CONSTEXPR_AFTER_CXX17
4080b57cec5SDimitry Andric        vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
409753f127fSDimitry Andric               typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
4100b57cec5SDimitry Andric                                 is_constructible<
4110b57cec5SDimitry Andric                                    value_type,
4120b57cec5SDimitry Andric                                    typename iterator_traits<_InputIterator>::reference>::value>::type* = 0);
4130b57cec5SDimitry Andric    template <class _ForwardIterator>
41461cfbce3SDimitry Andric        _LIBCPP_CONSTEXPR_AFTER_CXX17
4150b57cec5SDimitry Andric        vector(_ForwardIterator __first,
416480093f4SDimitry Andric               typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
4170b57cec5SDimitry Andric                                 is_constructible<
4180b57cec5SDimitry Andric                                    value_type,
4190b57cec5SDimitry Andric                                    typename iterator_traits<_ForwardIterator>::reference>::value,
4200b57cec5SDimitry Andric                                 _ForwardIterator>::type __last);
4210b57cec5SDimitry Andric    template <class _ForwardIterator>
42261cfbce3SDimitry Andric        _LIBCPP_CONSTEXPR_AFTER_CXX17
4230b57cec5SDimitry Andric        vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
424480093f4SDimitry Andric               typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
4250b57cec5SDimitry Andric                                 is_constructible<
4260b57cec5SDimitry Andric                                    value_type,
4270b57cec5SDimitry Andric                                    typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0);
4280b57cec5SDimitry Andric
429*50d7464cSDimitry Andricprivate:
430*50d7464cSDimitry Andric  class __destroy_vector {
431*50d7464cSDimitry Andric    public:
432*50d7464cSDimitry Andric      _LIBCPP_CONSTEXPR __destroy_vector(vector& __vec) : __vec_(__vec) {}
433349cc55cSDimitry Andric
434*50d7464cSDimitry Andric      _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI void operator()() {
435*50d7464cSDimitry Andric          __vec_.__annotate_delete();
436*50d7464cSDimitry Andric          std::__debug_db_erase_c(std::addressof(__vec_));
437*50d7464cSDimitry Andric
438*50d7464cSDimitry Andric          if (__vec_.__begin_ != nullptr) {
439*50d7464cSDimitry Andric            __vec_.__clear();
440*50d7464cSDimitry Andric            __alloc_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.capacity());
441349cc55cSDimitry Andric          }
4420b57cec5SDimitry Andric      }
4430b57cec5SDimitry Andric
444*50d7464cSDimitry Andric    private:
445*50d7464cSDimitry Andric      vector& __vec_;
446*50d7464cSDimitry Andric  };
447*50d7464cSDimitry Andric
448*50d7464cSDimitry Andricpublic:
449*50d7464cSDimitry Andric  _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI ~vector() { __destroy_vector(*this)(); }
450*50d7464cSDimitry Andric
45161cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(const vector& __x);
45261cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(const vector& __x, const __type_identity_t<allocator_type>& __a);
45361cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
4540b57cec5SDimitry Andric    vector& operator=(const vector& __x);
4550b57cec5SDimitry Andric
4560b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
45761cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
4580b57cec5SDimitry Andric    vector(initializer_list<value_type> __il);
4590b57cec5SDimitry Andric
46061cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
4610b57cec5SDimitry Andric    vector(initializer_list<value_type> __il, const allocator_type& __a);
4620b57cec5SDimitry Andric
46361cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
46481ad6265SDimitry Andric    vector& operator=(initializer_list<value_type> __il)
46581ad6265SDimitry Andric        {assign(__il.begin(), __il.end()); return *this;}
46681ad6265SDimitry Andric#endif // !_LIBCPP_CXX03_LANG
46781ad6265SDimitry Andric
46861cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
4690b57cec5SDimitry Andric    vector(vector&& __x)
4700b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
47181ad6265SDimitry Andric        noexcept;
4720b57cec5SDimitry Andric#else
4730b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
4740b57cec5SDimitry Andric#endif
4750b57cec5SDimitry Andric
47661cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
47781ad6265SDimitry Andric    vector(vector&& __x, const __type_identity_t<allocator_type>& __a);
47861cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
4790b57cec5SDimitry Andric    vector& operator=(vector&& __x)
4800b57cec5SDimitry Andric        _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
4810b57cec5SDimitry Andric
4820b57cec5SDimitry Andric    template <class _InputIterator>
48361cfbce3SDimitry Andric        _LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
4840b57cec5SDimitry Andric            is_constructible<
4850b57cec5SDimitry Andric                 value_type,
4860b57cec5SDimitry Andric                 typename iterator_traits<_InputIterator>::reference>::value,
4870b57cec5SDimitry Andric            void
4880b57cec5SDimitry Andric        >::type
4890b57cec5SDimitry Andric        assign(_InputIterator __first, _InputIterator __last);
4900b57cec5SDimitry Andric    template <class _ForwardIterator>
49161cfbce3SDimitry Andric        _LIBCPP_CONSTEXPR_AFTER_CXX17
4920b57cec5SDimitry Andric        typename enable_if
4930b57cec5SDimitry Andric        <
494480093f4SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value &&
4950b57cec5SDimitry Andric            is_constructible<
4960b57cec5SDimitry Andric                 value_type,
4970b57cec5SDimitry Andric                 typename iterator_traits<_ForwardIterator>::reference>::value,
4980b57cec5SDimitry Andric            void
4990b57cec5SDimitry Andric        >::type
5000b57cec5SDimitry Andric        assign(_ForwardIterator __first, _ForwardIterator __last);
5010b57cec5SDimitry Andric
50261cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void assign(size_type __n, const_reference __u);
5030b57cec5SDimitry Andric
5040b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
50561cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5060b57cec5SDimitry Andric    void assign(initializer_list<value_type> __il)
5070b57cec5SDimitry Andric        {assign(__il.begin(), __il.end());}
5080b57cec5SDimitry Andric#endif
5090b57cec5SDimitry Andric
51061cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5110b57cec5SDimitry Andric    allocator_type get_allocator() const _NOEXCEPT
5120b57cec5SDimitry Andric        {return this->__alloc();}
5130b57cec5SDimitry Andric
51461cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY iterator               begin() _NOEXCEPT;
51561cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const_iterator         begin()   const _NOEXCEPT;
51661cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY iterator               end() _NOEXCEPT;
51761cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const_iterator         end()     const _NOEXCEPT;
5180b57cec5SDimitry Andric
51961cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5200b57cec5SDimitry Andric    reverse_iterator       rbegin() _NOEXCEPT
5210b57cec5SDimitry Andric        {return       reverse_iterator(end());}
52261cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5230b57cec5SDimitry Andric    const_reverse_iterator rbegin()  const _NOEXCEPT
5240b57cec5SDimitry Andric        {return const_reverse_iterator(end());}
52561cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5260b57cec5SDimitry Andric    reverse_iterator       rend() _NOEXCEPT
5270b57cec5SDimitry Andric        {return       reverse_iterator(begin());}
52861cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5290b57cec5SDimitry Andric    const_reverse_iterator rend()    const _NOEXCEPT
5300b57cec5SDimitry Andric        {return const_reverse_iterator(begin());}
5310b57cec5SDimitry Andric
53261cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5330b57cec5SDimitry Andric    const_iterator         cbegin()  const _NOEXCEPT
5340b57cec5SDimitry Andric        {return begin();}
53561cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5360b57cec5SDimitry Andric    const_iterator         cend()    const _NOEXCEPT
5370b57cec5SDimitry Andric        {return end();}
53861cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5390b57cec5SDimitry Andric    const_reverse_iterator crbegin() const _NOEXCEPT
5400b57cec5SDimitry Andric        {return rbegin();}
54161cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5420b57cec5SDimitry Andric    const_reverse_iterator crend()   const _NOEXCEPT
5430b57cec5SDimitry Andric        {return rend();}
5440b57cec5SDimitry Andric
54561cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5460b57cec5SDimitry Andric    size_type size() const _NOEXCEPT
5470b57cec5SDimitry Andric        {return static_cast<size_type>(this->__end_ - this->__begin_);}
54861cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5490b57cec5SDimitry Andric    size_type capacity() const _NOEXCEPT
550349cc55cSDimitry Andric        {return static_cast<size_type>(__end_cap() - this->__begin_);}
55161cfbce3SDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5520b57cec5SDimitry Andric    bool empty() const _NOEXCEPT
5530b57cec5SDimitry Andric        {return this->__begin_ == this->__end_;}
55461cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type max_size() const _NOEXCEPT;
55561cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void reserve(size_type __n);
55661cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void shrink_to_fit() _NOEXCEPT;
5570b57cec5SDimitry Andric
55861cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY reference       operator[](size_type __n) _NOEXCEPT;
55961cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const _NOEXCEPT;
56061cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 reference       at(size_type __n);
56161cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference at(size_type __n) const;
5620b57cec5SDimitry Andric
56361cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY reference       front() _NOEXCEPT
5640b57cec5SDimitry Andric    {
565fe6060f1SDimitry Andric        _LIBCPP_ASSERT(!empty(), "front() called on an empty vector");
5660b57cec5SDimitry Andric        return *this->__begin_;
5670b57cec5SDimitry Andric    }
56861cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT
5690b57cec5SDimitry Andric    {
570fe6060f1SDimitry Andric        _LIBCPP_ASSERT(!empty(), "front() called on an empty vector");
5710b57cec5SDimitry Andric        return *this->__begin_;
5720b57cec5SDimitry Andric    }
57361cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY reference       back() _NOEXCEPT
5740b57cec5SDimitry Andric    {
575fe6060f1SDimitry Andric        _LIBCPP_ASSERT(!empty(), "back() called on an empty vector");
5760b57cec5SDimitry Andric        return *(this->__end_ - 1);
5770b57cec5SDimitry Andric    }
57861cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY const_reference back()  const _NOEXCEPT
5790b57cec5SDimitry Andric    {
580fe6060f1SDimitry Andric        _LIBCPP_ASSERT(!empty(), "back() called on an empty vector");
5810b57cec5SDimitry Andric        return *(this->__end_ - 1);
5820b57cec5SDimitry Andric    }
5830b57cec5SDimitry Andric
58461cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5850b57cec5SDimitry Andric    value_type*       data() _NOEXCEPT
586480093f4SDimitry Andric        {return _VSTD::__to_address(this->__begin_);}
58761cfbce3SDimitry Andric
58861cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5890b57cec5SDimitry Andric    const value_type* data() const _NOEXCEPT
590480093f4SDimitry Andric        {return _VSTD::__to_address(this->__begin_);}
5910b57cec5SDimitry Andric
59261cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
5930b57cec5SDimitry Andric
59461cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
5950b57cec5SDimitry Andric
5960b57cec5SDimitry Andric    template <class... _Args>
59761cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5980b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
5990b57cec5SDimitry Andric        reference emplace_back(_Args&&... __args);
6000b57cec5SDimitry Andric#else
6010b57cec5SDimitry Andric        void      emplace_back(_Args&&... __args);
6020b57cec5SDimitry Andric#endif
6030b57cec5SDimitry Andric
60461cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
6050b57cec5SDimitry Andric    void pop_back();
6060b57cec5SDimitry Andric
60761cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator insert(const_iterator __position, const_reference __x);
6080b57cec5SDimitry Andric
60961cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator insert(const_iterator __position, value_type&& __x);
6100b57cec5SDimitry Andric    template <class... _Args>
61161cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator emplace(const_iterator __position, _Args&&... __args);
6120b57cec5SDimitry Andric
61361cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator insert(const_iterator __position, size_type __n, const_reference __x);
6140b57cec5SDimitry Andric    template <class _InputIterator>
61561cfbce3SDimitry Andric        _LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
6160b57cec5SDimitry Andric            is_constructible<
6170b57cec5SDimitry Andric                 value_type,
6180b57cec5SDimitry Andric                 typename iterator_traits<_InputIterator>::reference>::value,
6190b57cec5SDimitry Andric            iterator
6200b57cec5SDimitry Andric        >::type
6210b57cec5SDimitry Andric        insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
6220b57cec5SDimitry Andric    template <class _ForwardIterator>
62361cfbce3SDimitry Andric        _LIBCPP_CONSTEXPR_AFTER_CXX17
6240b57cec5SDimitry Andric        typename enable_if
6250b57cec5SDimitry Andric        <
626480093f4SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value &&
6270b57cec5SDimitry Andric            is_constructible<
6280b57cec5SDimitry Andric                 value_type,
6290b57cec5SDimitry Andric                 typename iterator_traits<_ForwardIterator>::reference>::value,
6300b57cec5SDimitry Andric            iterator
6310b57cec5SDimitry Andric        >::type
6320b57cec5SDimitry Andric        insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
6330b57cec5SDimitry Andric
6340b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
63561cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
6360b57cec5SDimitry Andric    iterator insert(const_iterator __position, initializer_list<value_type> __il)
6370b57cec5SDimitry Andric        {return insert(__position, __il.begin(), __il.end());}
6380b57cec5SDimitry Andric#endif
6390b57cec5SDimitry Andric
64061cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
64161cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator erase(const_iterator __first, const_iterator __last);
6420b57cec5SDimitry Andric
64361cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
6440b57cec5SDimitry Andric    void clear() _NOEXCEPT
6450b57cec5SDimitry Andric    {
6460b57cec5SDimitry Andric        size_type __old_size = size();
647349cc55cSDimitry Andric        __clear();
6480b57cec5SDimitry Andric        __annotate_shrink(__old_size);
64981ad6265SDimitry Andric        std::__debug_db_invalidate_all(this);
6500b57cec5SDimitry Andric    }
6510b57cec5SDimitry Andric
65261cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void resize(size_type __sz);
65361cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void resize(size_type __sz, const_reference __x);
6540b57cec5SDimitry Andric
65561cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void swap(vector&)
6560b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
6570b57cec5SDimitry Andric        _NOEXCEPT;
6580b57cec5SDimitry Andric#else
6590b57cec5SDimitry Andric        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
6600b57cec5SDimitry Andric                    __is_nothrow_swappable<allocator_type>::value);
6610b57cec5SDimitry Andric#endif
6620b57cec5SDimitry Andric
66361cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 bool __invariants() const;
6640b57cec5SDimitry Andric
66581ad6265SDimitry Andric#ifdef _LIBCPP_ENABLE_DEBUG_MODE
6660b57cec5SDimitry Andric
6670b57cec5SDimitry Andric    bool __dereferenceable(const const_iterator* __i) const;
6680b57cec5SDimitry Andric    bool __decrementable(const const_iterator* __i) const;
6690b57cec5SDimitry Andric    bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
6700b57cec5SDimitry Andric    bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
6710b57cec5SDimitry Andric
67281ad6265SDimitry Andric#endif // _LIBCPP_ENABLE_DEBUG_MODE
6730b57cec5SDimitry Andric
6740b57cec5SDimitry Andricprivate:
675d56accc7SDimitry Andric    pointer __begin_ = nullptr;
676d56accc7SDimitry Andric    pointer __end_ = nullptr;
677d56accc7SDimitry Andric    __compressed_pair<pointer, allocator_type> __end_cap_ =
678d56accc7SDimitry Andric        __compressed_pair<pointer, allocator_type>(nullptr, __default_init_tag());
679d56accc7SDimitry Andric
6800b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last);
68181ad6265SDimitry Andric
68281ad6265SDimitry Andric    //  Allocate space for __n objects
68381ad6265SDimitry Andric    //  throws length_error if __n > max_size()
68481ad6265SDimitry Andric    //  throws (probably bad_alloc) if memory run out
68581ad6265SDimitry Andric    //  Precondition:  __begin_ == __end_ == __end_cap() == 0
68681ad6265SDimitry Andric    //  Precondition:  __n > 0
68781ad6265SDimitry Andric    //  Postcondition:  capacity() >= __n
68881ad6265SDimitry Andric    //  Postcondition:  size() == 0
68961cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) {
69081ad6265SDimitry Andric        if (__n > max_size())
69181ad6265SDimitry Andric            __throw_length_error();
69281ad6265SDimitry Andric        auto __allocation = std::__allocate_at_least(__alloc(), __n);
69381ad6265SDimitry Andric        __begin_ = __allocation.ptr;
69481ad6265SDimitry Andric        __end_ = __allocation.ptr;
69581ad6265SDimitry Andric        __end_cap() = __begin_ + __allocation.count;
69681ad6265SDimitry Andric        __annotate_new(0);
69781ad6265SDimitry Andric    }
69881ad6265SDimitry Andric
69961cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void __vdeallocate() _NOEXCEPT;
70061cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
70161cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void __construct_at_end(size_type __n);
70261cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
7030b57cec5SDimitry Andric    void __construct_at_end(size_type __n, const_reference __x);
7040b57cec5SDimitry Andric    template <class _ForwardIterator>
70561cfbce3SDimitry Andric        _LIBCPP_CONSTEXPR_AFTER_CXX17
7060b57cec5SDimitry Andric        typename enable_if
7070b57cec5SDimitry Andric        <
708480093f4SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value,
7090b57cec5SDimitry Andric            void
7100b57cec5SDimitry Andric        >::type
7110b57cec5SDimitry Andric        __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n);
71261cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void __append(size_type __n);
71361cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void __append(size_type __n, const_reference __x);
71461cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
7150b57cec5SDimitry Andric    iterator       __make_iter(pointer __p) _NOEXCEPT;
71661cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
7170b57cec5SDimitry Andric    const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
71861cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
71961cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
72061cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void __move_range(pointer __from_s, pointer __from_e, pointer __to);
72161cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void __move_assign(vector& __c, true_type)
7220b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
72361cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void __move_assign(vector& __c, false_type)
7240b57cec5SDimitry Andric        _NOEXCEPT_(__alloc_traits::is_always_equal::value);
72561cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
7260b57cec5SDimitry Andric    void __destruct_at_end(pointer __new_last) _NOEXCEPT
7270b57cec5SDimitry Andric    {
72861cfbce3SDimitry Andric        if (!__libcpp_is_constant_evaluated())
7290b57cec5SDimitry Andric            __invalidate_iterators_past(__new_last);
7300b57cec5SDimitry Andric        size_type __old_size = size();
731349cc55cSDimitry Andric        __base_destruct_at_end(__new_last);
7320b57cec5SDimitry Andric        __annotate_shrink(__old_size);
7330b57cec5SDimitry Andric    }
7340b57cec5SDimitry Andric
7350b57cec5SDimitry Andric    template <class _Up>
73661cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
7370b57cec5SDimitry Andric    inline void __push_back_slow_path(_Up&& __x);
7380b57cec5SDimitry Andric
7390b57cec5SDimitry Andric    template <class... _Args>
74061cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
7410b57cec5SDimitry Andric    inline void __emplace_back_slow_path(_Args&&... __args);
7420b57cec5SDimitry Andric
7430b57cec5SDimitry Andric    // The following functions are no-ops outside of AddressSanitizer mode.
7440b57cec5SDimitry Andric    // We call annotatations only for the default Allocator because other allocators
7450b57cec5SDimitry Andric    // may not meet the AddressSanitizer alignment constraints.
7460b57cec5SDimitry Andric    // See the documentation for __sanitizer_annotate_contiguous_container for more details.
7470b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
74861cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17
7490b57cec5SDimitry Andric    void __annotate_contiguous_container(const void *__beg, const void *__end,
7500b57cec5SDimitry Andric                                         const void *__old_mid,
7510b57cec5SDimitry Andric                                         const void *__new_mid) const
7520b57cec5SDimitry Andric    {
7530b57cec5SDimitry Andric
75461cfbce3SDimitry Andric      if (!__libcpp_is_constant_evaluated() && __beg && is_same<allocator_type, __default_allocator_type>::value)
7550b57cec5SDimitry Andric        __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
7560b57cec5SDimitry Andric    }
7570b57cec5SDimitry Andric#else
75861cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
7590b57cec5SDimitry Andric    void __annotate_contiguous_container(const void*, const void*, const void*,
760e40139ffSDimitry Andric                                         const void*) const _NOEXCEPT {}
7610b57cec5SDimitry Andric#endif
76261cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
763e40139ffSDimitry Andric    void __annotate_new(size_type __current_size) const _NOEXCEPT {
7640b57cec5SDimitry Andric      __annotate_contiguous_container(data(), data() + capacity(),
7650b57cec5SDimitry Andric                                      data() + capacity(), data() + __current_size);
7660b57cec5SDimitry Andric    }
7670b57cec5SDimitry Andric
76861cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
769e40139ffSDimitry Andric    void __annotate_delete() const _NOEXCEPT {
7700b57cec5SDimitry Andric      __annotate_contiguous_container(data(), data() + capacity(),
7710b57cec5SDimitry Andric                                      data() + size(), data() + capacity());
7720b57cec5SDimitry Andric    }
7730b57cec5SDimitry Andric
77461cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
775e40139ffSDimitry Andric    void __annotate_increase(size_type __n) const _NOEXCEPT
7760b57cec5SDimitry Andric    {
7770b57cec5SDimitry Andric      __annotate_contiguous_container(data(), data() + capacity(),
7780b57cec5SDimitry Andric                                      data() + size(), data() + size() + __n);
7790b57cec5SDimitry Andric    }
7800b57cec5SDimitry Andric
78161cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
782e40139ffSDimitry Andric    void __annotate_shrink(size_type __old_size) const _NOEXCEPT
7830b57cec5SDimitry Andric    {
7840b57cec5SDimitry Andric      __annotate_contiguous_container(data(), data() + capacity(),
7850b57cec5SDimitry Andric                                      data() + __old_size, data() + size());
7860b57cec5SDimitry Andric    }
7870b57cec5SDimitry Andric
788e40139ffSDimitry Andric  struct _ConstructTransaction {
78961cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17
790e40139ffSDimitry Andric    explicit _ConstructTransaction(vector &__v, size_type __n)
791e40139ffSDimitry Andric      : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) {
792e40139ffSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
793e40139ffSDimitry Andric      __v_.__annotate_increase(__n);
794e40139ffSDimitry Andric#endif
795e40139ffSDimitry Andric    }
79661cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 ~_ConstructTransaction() {
797e40139ffSDimitry Andric      __v_.__end_ = __pos_;
798e40139ffSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
799e40139ffSDimitry Andric      if (__pos_ != __new_end_) {
800e40139ffSDimitry Andric        __v_.__annotate_shrink(__new_end_ - __v_.__begin_);
801e40139ffSDimitry Andric      }
802e40139ffSDimitry Andric#endif
803e40139ffSDimitry Andric    }
804e40139ffSDimitry Andric
805e40139ffSDimitry Andric    vector &__v_;
806e40139ffSDimitry Andric    pointer __pos_;
807e40139ffSDimitry Andric    const_pointer const __new_end_;
808e40139ffSDimitry Andric
809e40139ffSDimitry Andric  private:
810e40139ffSDimitry Andric    _ConstructTransaction(_ConstructTransaction const&) = delete;
811e40139ffSDimitry Andric    _ConstructTransaction& operator=(_ConstructTransaction const&) = delete;
812e40139ffSDimitry Andric  };
813e40139ffSDimitry Andric
814e40139ffSDimitry Andric  template <class ..._Args>
81561cfbce3SDimitry Andric  _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
816e40139ffSDimitry Andric  void __construct_one_at_end(_Args&& ...__args) {
817e40139ffSDimitry Andric    _ConstructTransaction __tx(*this, 1);
818480093f4SDimitry Andric    __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__tx.__pos_),
819e40139ffSDimitry Andric        _VSTD::forward<_Args>(__args)...);
820e40139ffSDimitry Andric    ++__tx.__pos_;
821e40139ffSDimitry Andric  }
822349cc55cSDimitry Andric
82361cfbce3SDimitry Andric  _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
824349cc55cSDimitry Andric  allocator_type& __alloc() _NOEXCEPT
825349cc55cSDimitry Andric      {return this->__end_cap_.second();}
82661cfbce3SDimitry Andric  _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
827349cc55cSDimitry Andric  const allocator_type& __alloc() const _NOEXCEPT
828349cc55cSDimitry Andric      {return this->__end_cap_.second();}
82961cfbce3SDimitry Andric  _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
830349cc55cSDimitry Andric  pointer& __end_cap() _NOEXCEPT
831349cc55cSDimitry Andric      {return this->__end_cap_.first();}
83261cfbce3SDimitry Andric  _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
833349cc55cSDimitry Andric  const pointer& __end_cap() const _NOEXCEPT
834349cc55cSDimitry Andric      {return this->__end_cap_.first();}
835349cc55cSDimitry Andric
83661cfbce3SDimitry Andric  _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
837349cc55cSDimitry Andric  void __clear() _NOEXCEPT {__base_destruct_at_end(this->__begin_);}
838349cc55cSDimitry Andric
83961cfbce3SDimitry Andric  _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
840349cc55cSDimitry Andric  void __base_destruct_at_end(pointer __new_last) _NOEXCEPT {
841349cc55cSDimitry Andric    pointer __soon_to_be_end = this->__end_;
842349cc55cSDimitry Andric    while (__new_last != __soon_to_be_end)
843349cc55cSDimitry Andric        __alloc_traits::destroy(__alloc(), _VSTD::__to_address(--__soon_to_be_end));
844349cc55cSDimitry Andric    this->__end_ = __new_last;
845349cc55cSDimitry Andric  }
846349cc55cSDimitry Andric
84761cfbce3SDimitry Andric  _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
848349cc55cSDimitry Andric  void __copy_assign_alloc(const vector& __c)
849349cc55cSDimitry Andric      {__copy_assign_alloc(__c, integral_constant<bool,
850349cc55cSDimitry Andric                    __alloc_traits::propagate_on_container_copy_assignment::value>());}
851349cc55cSDimitry Andric
85261cfbce3SDimitry Andric  _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
853349cc55cSDimitry Andric  void __move_assign_alloc(vector& __c)
854349cc55cSDimitry Andric      _NOEXCEPT_(
855349cc55cSDimitry Andric          !__alloc_traits::propagate_on_container_move_assignment::value ||
856349cc55cSDimitry Andric          is_nothrow_move_assignable<allocator_type>::value)
857349cc55cSDimitry Andric      {__move_assign_alloc(__c, integral_constant<bool,
858349cc55cSDimitry Andric                    __alloc_traits::propagate_on_container_move_assignment::value>());}
859349cc55cSDimitry Andric
860349cc55cSDimitry Andric  _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
861349cc55cSDimitry Andric  void __throw_length_error() const {
862d56accc7SDimitry Andric      _VSTD::__throw_length_error("vector");
863349cc55cSDimitry Andric  }
864349cc55cSDimitry Andric
865349cc55cSDimitry Andric  _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
866349cc55cSDimitry Andric  void __throw_out_of_range() const {
867d56accc7SDimitry Andric      _VSTD::__throw_out_of_range("vector");
868349cc55cSDimitry Andric  }
869349cc55cSDimitry Andric
87061cfbce3SDimitry Andric  _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
871349cc55cSDimitry Andric  void __copy_assign_alloc(const vector& __c, true_type)
872349cc55cSDimitry Andric  {
873349cc55cSDimitry Andric    if (__alloc() != __c.__alloc())
874349cc55cSDimitry Andric    {
875349cc55cSDimitry Andric      __clear();
876349cc55cSDimitry Andric      __alloc_traits::deallocate(__alloc(), this->__begin_, capacity());
877349cc55cSDimitry Andric      this->__begin_ = this->__end_ = __end_cap() = nullptr;
878349cc55cSDimitry Andric    }
879349cc55cSDimitry Andric    __alloc() = __c.__alloc();
880349cc55cSDimitry Andric  }
881349cc55cSDimitry Andric
88261cfbce3SDimitry Andric  _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
883349cc55cSDimitry Andric  void __copy_assign_alloc(const vector&, false_type)
884349cc55cSDimitry Andric  {}
885349cc55cSDimitry Andric
88661cfbce3SDimitry Andric  _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
887349cc55cSDimitry Andric  void __move_assign_alloc(vector& __c, true_type)
888349cc55cSDimitry Andric      _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
889349cc55cSDimitry Andric  {
890349cc55cSDimitry Andric    __alloc() = _VSTD::move(__c.__alloc());
891349cc55cSDimitry Andric  }
892349cc55cSDimitry Andric
89361cfbce3SDimitry Andric  _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
894349cc55cSDimitry Andric  void __move_assign_alloc(vector&, false_type)
895349cc55cSDimitry Andric      _NOEXCEPT
896349cc55cSDimitry Andric  {}
8970b57cec5SDimitry Andric};
8980b57cec5SDimitry Andric
899349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17
9000b57cec5SDimitry Andrictemplate<class _InputIterator,
901fe6060f1SDimitry Andric         class _Alloc = allocator<__iter_value_type<_InputIterator>>,
902349cc55cSDimitry Andric         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
903349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Alloc>::value>
9040b57cec5SDimitry Andric         >
9050b57cec5SDimitry Andricvector(_InputIterator, _InputIterator)
906fe6060f1SDimitry Andric  -> vector<__iter_value_type<_InputIterator>, _Alloc>;
9070b57cec5SDimitry Andric
9080b57cec5SDimitry Andrictemplate<class _InputIterator,
9090b57cec5SDimitry Andric         class _Alloc,
910349cc55cSDimitry Andric         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
911349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Alloc>::value>
9120b57cec5SDimitry Andric         >
9130b57cec5SDimitry Andricvector(_InputIterator, _InputIterator, _Alloc)
914fe6060f1SDimitry Andric  -> vector<__iter_value_type<_InputIterator>, _Alloc>;
9150b57cec5SDimitry Andric#endif
9160b57cec5SDimitry Andric
9170b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
91861cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
9190b57cec5SDimitry Andricvoid
9200b57cec5SDimitry Andricvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
9210b57cec5SDimitry Andric{
9220b57cec5SDimitry Andric    __annotate_delete();
923972a253aSDimitry Andric    using _RevIter = std::reverse_iterator<pointer>;
924972a253aSDimitry Andric    __v.__begin_   = std::__uninitialized_allocator_move_if_noexcept(
925972a253aSDimitry Andric                       __alloc(), _RevIter(__end_), _RevIter(__begin_), _RevIter(__v.__begin_))
926972a253aSDimitry Andric                       .base();
9270b57cec5SDimitry Andric    _VSTD::swap(this->__begin_, __v.__begin_);
9280b57cec5SDimitry Andric    _VSTD::swap(this->__end_, __v.__end_);
9290b57cec5SDimitry Andric    _VSTD::swap(this->__end_cap(), __v.__end_cap());
9300b57cec5SDimitry Andric    __v.__first_ = __v.__begin_;
9310b57cec5SDimitry Andric    __annotate_new(size());
93281ad6265SDimitry Andric    std::__debug_db_invalidate_all(this);
9330b57cec5SDimitry Andric}
9340b57cec5SDimitry Andric
9350b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
93661cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
9370b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::pointer
9380b57cec5SDimitry Andricvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
9390b57cec5SDimitry Andric{
9400b57cec5SDimitry Andric    __annotate_delete();
9410b57cec5SDimitry Andric    pointer __r = __v.__begin_;
942972a253aSDimitry Andric    using _RevIter = std::reverse_iterator<pointer>;
943972a253aSDimitry Andric    __v.__begin_   = std::__uninitialized_allocator_move_if_noexcept(
944972a253aSDimitry Andric                       __alloc(), _RevIter(__p), _RevIter(__begin_), _RevIter(__v.__begin_))
945972a253aSDimitry Andric                       .base();
946972a253aSDimitry Andric    __v.__end_ = std::__uninitialized_allocator_move_if_noexcept(__alloc(), __p, __end_, __v.__end_);
9470b57cec5SDimitry Andric    _VSTD::swap(this->__begin_, __v.__begin_);
9480b57cec5SDimitry Andric    _VSTD::swap(this->__end_, __v.__end_);
9490b57cec5SDimitry Andric    _VSTD::swap(this->__end_cap(), __v.__end_cap());
9500b57cec5SDimitry Andric    __v.__first_ = __v.__begin_;
9510b57cec5SDimitry Andric    __annotate_new(size());
95281ad6265SDimitry Andric    std::__debug_db_invalidate_all(this);
9530b57cec5SDimitry Andric    return __r;
9540b57cec5SDimitry Andric}
9550b57cec5SDimitry Andric
9560b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
95761cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
9580b57cec5SDimitry Andricvoid
9590b57cec5SDimitry Andricvector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT
9600b57cec5SDimitry Andric{
9610b57cec5SDimitry Andric    if (this->__begin_ != nullptr)
9620b57cec5SDimitry Andric    {
9630b57cec5SDimitry Andric        clear();
9640b57cec5SDimitry Andric        __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
9650b57cec5SDimitry Andric        this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
9660b57cec5SDimitry Andric    }
9670b57cec5SDimitry Andric}
9680b57cec5SDimitry Andric
9690b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
97061cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
9710b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::size_type
9720b57cec5SDimitry Andricvector<_Tp, _Allocator>::max_size() const _NOEXCEPT
9730b57cec5SDimitry Andric{
9740b57cec5SDimitry Andric    return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()),
9750b57cec5SDimitry Andric                                 numeric_limits<difference_type>::max());
9760b57cec5SDimitry Andric}
9770b57cec5SDimitry Andric
9780b57cec5SDimitry Andric//  Precondition:  __new_size > capacity()
9790b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
98061cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
9810b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
9820b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::size_type
9830b57cec5SDimitry Andricvector<_Tp, _Allocator>::__recommend(size_type __new_size) const
9840b57cec5SDimitry Andric{
9850b57cec5SDimitry Andric    const size_type __ms = max_size();
9860b57cec5SDimitry Andric    if (__new_size > __ms)
9870b57cec5SDimitry Andric        this->__throw_length_error();
9880b57cec5SDimitry Andric    const size_type __cap = capacity();
9890b57cec5SDimitry Andric    if (__cap >= __ms / 2)
9900b57cec5SDimitry Andric        return __ms;
9910b57cec5SDimitry Andric    return _VSTD::max<size_type>(2 * __cap, __new_size);
9920b57cec5SDimitry Andric}
9930b57cec5SDimitry Andric
9940b57cec5SDimitry Andric//  Default constructs __n objects starting at __end_
9950b57cec5SDimitry Andric//  throws if construction throws
9960b57cec5SDimitry Andric//  Precondition:  __n > 0
9970b57cec5SDimitry Andric//  Precondition:  size() + __n <= capacity()
9980b57cec5SDimitry Andric//  Postcondition:  size() == size() + __n
9990b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
100061cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
10010b57cec5SDimitry Andricvoid
10020b57cec5SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(size_type __n)
10030b57cec5SDimitry Andric{
1004e40139ffSDimitry Andric    _ConstructTransaction __tx(*this, __n);
10055ffd83dbSDimitry Andric    const_pointer __new_end = __tx.__new_end_;
1006349cc55cSDimitry Andric    for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
10075ffd83dbSDimitry Andric        __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos));
1008e40139ffSDimitry Andric    }
10090b57cec5SDimitry Andric}
10100b57cec5SDimitry Andric
10110b57cec5SDimitry Andric//  Copy constructs __n objects starting at __end_ from __x
10120b57cec5SDimitry Andric//  throws if construction throws
10130b57cec5SDimitry Andric//  Precondition:  __n > 0
10140b57cec5SDimitry Andric//  Precondition:  size() + __n <= capacity()
10150b57cec5SDimitry Andric//  Postcondition:  size() == old size() + __n
10160b57cec5SDimitry Andric//  Postcondition:  [i] == __x for all i in [size() - __n, __n)
10170b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
101861cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
10190b57cec5SDimitry Andricinline
10200b57cec5SDimitry Andricvoid
10210b57cec5SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
10220b57cec5SDimitry Andric{
1023e40139ffSDimitry Andric    _ConstructTransaction __tx(*this, __n);
10245ffd83dbSDimitry Andric    const_pointer __new_end = __tx.__new_end_;
1025349cc55cSDimitry Andric    for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
10265ffd83dbSDimitry Andric        __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos), __x);
1027e40139ffSDimitry Andric    }
10280b57cec5SDimitry Andric}
10290b57cec5SDimitry Andric
10300b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
10310b57cec5SDimitry Andrictemplate <class _ForwardIterator>
103261cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
10330b57cec5SDimitry Andrictypename enable_if
10340b57cec5SDimitry Andric<
1035480093f4SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value,
10360b57cec5SDimitry Andric    void
10370b57cec5SDimitry Andric>::type
10380b57cec5SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n)
10390b57cec5SDimitry Andric{
1040e40139ffSDimitry Andric  _ConstructTransaction __tx(*this, __n);
1041972a253aSDimitry Andric  __tx.__pos_ = std::__uninitialized_allocator_copy(__alloc(), __first, __last, __tx.__pos_);
10420b57cec5SDimitry Andric}
10430b57cec5SDimitry Andric
10440b57cec5SDimitry Andric//  Default constructs __n objects starting at __end_
10450b57cec5SDimitry Andric//  throws if construction throws
10460b57cec5SDimitry Andric//  Postcondition:  size() == size() + __n
10470b57cec5SDimitry Andric//  Exception safety: strong.
10480b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
104961cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
10500b57cec5SDimitry Andricvoid
10510b57cec5SDimitry Andricvector<_Tp, _Allocator>::__append(size_type __n)
10520b57cec5SDimitry Andric{
10530b57cec5SDimitry Andric    if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
10540b57cec5SDimitry Andric        this->__construct_at_end(__n);
10550b57cec5SDimitry Andric    else
10560b57cec5SDimitry Andric    {
10570b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
10580b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
10590b57cec5SDimitry Andric        __v.__construct_at_end(__n);
10600b57cec5SDimitry Andric        __swap_out_circular_buffer(__v);
10610b57cec5SDimitry Andric    }
10620b57cec5SDimitry Andric}
10630b57cec5SDimitry Andric
10640b57cec5SDimitry Andric//  Default constructs __n objects starting at __end_
10650b57cec5SDimitry Andric//  throws if construction throws
10660b57cec5SDimitry Andric//  Postcondition:  size() == size() + __n
10670b57cec5SDimitry Andric//  Exception safety: strong.
10680b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
106961cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
10700b57cec5SDimitry Andricvoid
10710b57cec5SDimitry Andricvector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
10720b57cec5SDimitry Andric{
10730b57cec5SDimitry Andric    if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
10740b57cec5SDimitry Andric        this->__construct_at_end(__n, __x);
10750b57cec5SDimitry Andric    else
10760b57cec5SDimitry Andric    {
10770b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
10780b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
10790b57cec5SDimitry Andric        __v.__construct_at_end(__n, __x);
10800b57cec5SDimitry Andric        __swap_out_circular_buffer(__v);
10810b57cec5SDimitry Andric    }
10820b57cec5SDimitry Andric}
10830b57cec5SDimitry Andric
10840b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
108561cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
10860b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n)
10870b57cec5SDimitry Andric{
1088*50d7464cSDimitry Andric    auto __guard = std::__make_transaction(__destroy_vector(*this));
1089*50d7464cSDimitry Andric    std::__debug_db_insert_c(this);
10900b57cec5SDimitry Andric    if (__n > 0)
10910b57cec5SDimitry Andric    {
10920b57cec5SDimitry Andric        __vallocate(__n);
10930b57cec5SDimitry Andric        __construct_at_end(__n);
10940b57cec5SDimitry Andric    }
1095*50d7464cSDimitry Andric    __guard.__complete();
10960b57cec5SDimitry Andric}
10970b57cec5SDimitry Andric
10980b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
10990b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
110061cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
11010b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
1102d56accc7SDimitry Andric    : __end_cap_(nullptr, __a)
11030b57cec5SDimitry Andric{
1104*50d7464cSDimitry Andric    auto __guard = std::__make_transaction(__destroy_vector(*this));
1105*50d7464cSDimitry Andric    std::__debug_db_insert_c(this);
11060b57cec5SDimitry Andric    if (__n > 0)
11070b57cec5SDimitry Andric    {
11080b57cec5SDimitry Andric        __vallocate(__n);
11090b57cec5SDimitry Andric        __construct_at_end(__n);
11100b57cec5SDimitry Andric    }
1111*50d7464cSDimitry Andric    __guard.__complete();
11120b57cec5SDimitry Andric}
11130b57cec5SDimitry Andric#endif
11140b57cec5SDimitry Andric
11150b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
111661cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
11170b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x)
11180b57cec5SDimitry Andric{
1119*50d7464cSDimitry Andric    auto __guard = std::__make_transaction(__destroy_vector(*this));
1120*50d7464cSDimitry Andric    std::__debug_db_insert_c(this);
11210b57cec5SDimitry Andric    if (__n > 0)
11220b57cec5SDimitry Andric    {
11230b57cec5SDimitry Andric        __vallocate(__n);
11240b57cec5SDimitry Andric        __construct_at_end(__n, __x);
11250b57cec5SDimitry Andric    }
1126*50d7464cSDimitry Andric    __guard.__complete();
11270b57cec5SDimitry Andric}
11280b57cec5SDimitry Andric
11290b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
11300b57cec5SDimitry Andrictemplate <class _InputIterator>
113161cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
11320b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_InputIterator __first,
1133753f127fSDimitry Andric       typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
11340b57cec5SDimitry Andric                         is_constructible<
11350b57cec5SDimitry Andric                            value_type,
11360b57cec5SDimitry Andric                            typename iterator_traits<_InputIterator>::reference>::value,
11370b57cec5SDimitry Andric                          _InputIterator>::type __last)
11380b57cec5SDimitry Andric{
1139*50d7464cSDimitry Andric    auto __guard = std::__make_transaction(__destroy_vector(*this));
1140*50d7464cSDimitry Andric    std::__debug_db_insert_c(this);
11410b57cec5SDimitry Andric    for (; __first != __last; ++__first)
114281ad6265SDimitry Andric        emplace_back(*__first);
1143*50d7464cSDimitry Andric    __guard.__complete();
11440b57cec5SDimitry Andric}
11450b57cec5SDimitry Andric
11460b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
11470b57cec5SDimitry Andrictemplate <class _InputIterator>
114861cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
11490b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1150753f127fSDimitry Andric       typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
11510b57cec5SDimitry Andric                         is_constructible<
11520b57cec5SDimitry Andric                            value_type,
11530b57cec5SDimitry Andric                            typename iterator_traits<_InputIterator>::reference>::value>::type*)
1154d56accc7SDimitry Andric    : __end_cap_(nullptr, __a)
11550b57cec5SDimitry Andric{
1156*50d7464cSDimitry Andric    auto __guard = std::__make_transaction(__destroy_vector(*this));
1157*50d7464cSDimitry Andric    std::__debug_db_insert_c(this);
11580b57cec5SDimitry Andric    for (; __first != __last; ++__first)
115981ad6265SDimitry Andric        emplace_back(*__first);
1160*50d7464cSDimitry Andric    __guard.__complete();
11610b57cec5SDimitry Andric}
11620b57cec5SDimitry Andric
11630b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
11640b57cec5SDimitry Andrictemplate <class _ForwardIterator>
116561cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
11660b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_ForwardIterator __first,
1167480093f4SDimitry Andric                                typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
11680b57cec5SDimitry Andric                                is_constructible<
11690b57cec5SDimitry Andric                                   value_type,
11700b57cec5SDimitry Andric                                   typename iterator_traits<_ForwardIterator>::reference>::value,
11710b57cec5SDimitry Andric                                                   _ForwardIterator>::type __last)
11720b57cec5SDimitry Andric{
1173*50d7464cSDimitry Andric    auto __guard = std::__make_transaction(__destroy_vector(*this));
1174*50d7464cSDimitry Andric    std::__debug_db_insert_c(this);
1175*50d7464cSDimitry Andric    size_type __n = static_cast<size_type>(std::distance(__first, __last));
11760b57cec5SDimitry Andric    if (__n > 0)
11770b57cec5SDimitry Andric    {
11780b57cec5SDimitry Andric        __vallocate(__n);
11790b57cec5SDimitry Andric        __construct_at_end(__first, __last, __n);
11800b57cec5SDimitry Andric    }
1181*50d7464cSDimitry Andric    __guard.__complete();
11820b57cec5SDimitry Andric}
11830b57cec5SDimitry Andric
11840b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
11850b57cec5SDimitry Andrictemplate <class _ForwardIterator>
118661cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
11870b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
1188480093f4SDimitry Andric                                typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
11890b57cec5SDimitry Andric                                is_constructible<
11900b57cec5SDimitry Andric                                   value_type,
11910b57cec5SDimitry Andric                                   typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
1192d56accc7SDimitry Andric    : __end_cap_(nullptr, __a)
11930b57cec5SDimitry Andric{
1194*50d7464cSDimitry Andric    auto __guard = std::__make_transaction(__destroy_vector(*this));
1195*50d7464cSDimitry Andric    std::__debug_db_insert_c(this);
1196*50d7464cSDimitry Andric    size_type __n = static_cast<size_type>(std::distance(__first, __last));
11970b57cec5SDimitry Andric    if (__n > 0)
11980b57cec5SDimitry Andric    {
11990b57cec5SDimitry Andric        __vallocate(__n);
12000b57cec5SDimitry Andric        __construct_at_end(__first, __last, __n);
12010b57cec5SDimitry Andric    }
1202*50d7464cSDimitry Andric    __guard.__complete();
12030b57cec5SDimitry Andric}
12040b57cec5SDimitry Andric
12050b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
120661cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
12070b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(const vector& __x)
1208d56accc7SDimitry Andric    : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc()))
12090b57cec5SDimitry Andric{
1210*50d7464cSDimitry Andric    auto __guard = std::__make_transaction(__destroy_vector(*this));
1211*50d7464cSDimitry Andric    std::__debug_db_insert_c(this);
12120b57cec5SDimitry Andric    size_type __n = __x.size();
12130b57cec5SDimitry Andric    if (__n > 0)
12140b57cec5SDimitry Andric    {
12150b57cec5SDimitry Andric        __vallocate(__n);
12160b57cec5SDimitry Andric        __construct_at_end(__x.__begin_, __x.__end_, __n);
12170b57cec5SDimitry Andric    }
1218*50d7464cSDimitry Andric    __guard.__complete();
12190b57cec5SDimitry Andric}
12200b57cec5SDimitry Andric
12210b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
122261cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
122381ad6265SDimitry Andricvector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
1224d56accc7SDimitry Andric    : __end_cap_(nullptr, __a)
12250b57cec5SDimitry Andric{
1226*50d7464cSDimitry Andric    auto __guard = std::__make_transaction(__destroy_vector(*this));
1227*50d7464cSDimitry Andric    std::__debug_db_insert_c(this);
12280b57cec5SDimitry Andric    size_type __n = __x.size();
12290b57cec5SDimitry Andric    if (__n > 0)
12300b57cec5SDimitry Andric    {
12310b57cec5SDimitry Andric        __vallocate(__n);
12320b57cec5SDimitry Andric        __construct_at_end(__x.__begin_, __x.__end_, __n);
12330b57cec5SDimitry Andric    }
1234*50d7464cSDimitry Andric    __guard.__complete();
12350b57cec5SDimitry Andric}
12360b57cec5SDimitry Andric
12370b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
123861cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
12390b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
12400b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(vector&& __x)
12410b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
124281ad6265SDimitry Andric        noexcept
12430b57cec5SDimitry Andric#else
12440b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
12450b57cec5SDimitry Andric#endif
1246d56accc7SDimitry Andric    : __end_cap_(nullptr, _VSTD::move(__x.__alloc()))
12470b57cec5SDimitry Andric{
124804eeddc0SDimitry Andric    _VSTD::__debug_db_insert_c(this);
124981ad6265SDimitry Andric    std::__debug_db_swap(this, std::addressof(__x));
12500b57cec5SDimitry Andric    this->__begin_ = __x.__begin_;
12510b57cec5SDimitry Andric    this->__end_ = __x.__end_;
12520b57cec5SDimitry Andric    this->__end_cap() = __x.__end_cap();
12530b57cec5SDimitry Andric    __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
12540b57cec5SDimitry Andric}
12550b57cec5SDimitry Andric
12560b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
125761cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
12580b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
125981ad6265SDimitry Andricvector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_type>& __a)
1260d56accc7SDimitry Andric    : __end_cap_(nullptr, __a)
12610b57cec5SDimitry Andric{
126204eeddc0SDimitry Andric    _VSTD::__debug_db_insert_c(this);
12630b57cec5SDimitry Andric    if (__a == __x.__alloc())
12640b57cec5SDimitry Andric    {
12650b57cec5SDimitry Andric        this->__begin_ = __x.__begin_;
12660b57cec5SDimitry Andric        this->__end_ = __x.__end_;
12670b57cec5SDimitry Andric        this->__end_cap() = __x.__end_cap();
12680b57cec5SDimitry Andric        __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
126981ad6265SDimitry Andric        std::__debug_db_swap(this, std::addressof(__x));
12700b57cec5SDimitry Andric    }
12710b57cec5SDimitry Andric    else
12720b57cec5SDimitry Andric    {
12730b57cec5SDimitry Andric        typedef move_iterator<iterator> _Ip;
1274*50d7464cSDimitry Andric        auto __guard = std::__make_transaction(__destroy_vector(*this));
12750b57cec5SDimitry Andric        assign(_Ip(__x.begin()), _Ip(__x.end()));
1276*50d7464cSDimitry Andric        __guard.__complete();
12770b57cec5SDimitry Andric    }
12780b57cec5SDimitry Andric}
12790b57cec5SDimitry Andric
128081ad6265SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
128181ad6265SDimitry Andric
12820b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
128361cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
12840b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
12850b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
12860b57cec5SDimitry Andric{
1287*50d7464cSDimitry Andric    auto __guard = std::__make_transaction(__destroy_vector(*this));
1288*50d7464cSDimitry Andric    std::__debug_db_insert_c(this);
12890b57cec5SDimitry Andric    if (__il.size() > 0)
12900b57cec5SDimitry Andric    {
12910b57cec5SDimitry Andric        __vallocate(__il.size());
12920b57cec5SDimitry Andric        __construct_at_end(__il.begin(), __il.end(), __il.size());
12930b57cec5SDimitry Andric    }
1294*50d7464cSDimitry Andric    __guard.__complete();
12950b57cec5SDimitry Andric}
12960b57cec5SDimitry Andric
12970b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
129861cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
12990b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
13000b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1301d56accc7SDimitry Andric    : __end_cap_(nullptr, __a)
13020b57cec5SDimitry Andric{
1303*50d7464cSDimitry Andric    auto __guard = std::__make_transaction(__destroy_vector(*this));
1304*50d7464cSDimitry Andric    std::__debug_db_insert_c(this);
13050b57cec5SDimitry Andric    if (__il.size() > 0)
13060b57cec5SDimitry Andric    {
13070b57cec5SDimitry Andric        __vallocate(__il.size());
13080b57cec5SDimitry Andric        __construct_at_end(__il.begin(), __il.end(), __il.size());
13090b57cec5SDimitry Andric    }
1310*50d7464cSDimitry Andric    __guard.__complete();
13110b57cec5SDimitry Andric}
13120b57cec5SDimitry Andric
131381ad6265SDimitry Andric#endif // _LIBCPP_CXX03_LANG
131481ad6265SDimitry Andric
13150b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
131661cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
13170b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
13180b57cec5SDimitry Andricvector<_Tp, _Allocator>&
13190b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator=(vector&& __x)
13200b57cec5SDimitry Andric    _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
13210b57cec5SDimitry Andric{
13220b57cec5SDimitry Andric    __move_assign(__x, integral_constant<bool,
13230b57cec5SDimitry Andric          __alloc_traits::propagate_on_container_move_assignment::value>());
13240b57cec5SDimitry Andric    return *this;
13250b57cec5SDimitry Andric}
13260b57cec5SDimitry Andric
13270b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
132861cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
13290b57cec5SDimitry Andricvoid
13300b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
13310b57cec5SDimitry Andric    _NOEXCEPT_(__alloc_traits::is_always_equal::value)
13320b57cec5SDimitry Andric{
1333349cc55cSDimitry Andric    if (__alloc() != __c.__alloc())
13340b57cec5SDimitry Andric    {
13350b57cec5SDimitry Andric        typedef move_iterator<iterator> _Ip;
13360b57cec5SDimitry Andric        assign(_Ip(__c.begin()), _Ip(__c.end()));
13370b57cec5SDimitry Andric    }
13380b57cec5SDimitry Andric    else
13390b57cec5SDimitry Andric        __move_assign(__c, true_type());
13400b57cec5SDimitry Andric}
13410b57cec5SDimitry Andric
13420b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
134361cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
13440b57cec5SDimitry Andricvoid
13450b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
13460b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
13470b57cec5SDimitry Andric{
13480b57cec5SDimitry Andric    __vdeallocate();
1349349cc55cSDimitry Andric    __move_assign_alloc(__c); // this can throw
13500b57cec5SDimitry Andric    this->__begin_ = __c.__begin_;
13510b57cec5SDimitry Andric    this->__end_ = __c.__end_;
13520b57cec5SDimitry Andric    this->__end_cap() = __c.__end_cap();
13530b57cec5SDimitry Andric    __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
135481ad6265SDimitry Andric    std::__debug_db_swap(this, std::addressof(__c));
13550b57cec5SDimitry Andric}
13560b57cec5SDimitry Andric
13570b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
135861cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
13590b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
13600b57cec5SDimitry Andricvector<_Tp, _Allocator>&
13610b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator=(const vector& __x)
13620b57cec5SDimitry Andric{
1363349cc55cSDimitry Andric    if (this != _VSTD::addressof(__x))
13640b57cec5SDimitry Andric    {
1365349cc55cSDimitry Andric        __copy_assign_alloc(__x);
13660b57cec5SDimitry Andric        assign(__x.__begin_, __x.__end_);
13670b57cec5SDimitry Andric    }
13680b57cec5SDimitry Andric    return *this;
13690b57cec5SDimitry Andric}
13700b57cec5SDimitry Andric
13710b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
13720b57cec5SDimitry Andrictemplate <class _InputIterator>
137361cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
13740b57cec5SDimitry Andric    is_constructible<
13750b57cec5SDimitry Andric       _Tp,
13760b57cec5SDimitry Andric       typename iterator_traits<_InputIterator>::reference>::value,
13770b57cec5SDimitry Andric    void
13780b57cec5SDimitry Andric>::type
13790b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
13800b57cec5SDimitry Andric{
13810b57cec5SDimitry Andric    clear();
13820b57cec5SDimitry Andric    for (; __first != __last; ++__first)
138381ad6265SDimitry Andric        emplace_back(*__first);
13840b57cec5SDimitry Andric}
13850b57cec5SDimitry Andric
13860b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
13870b57cec5SDimitry Andrictemplate <class _ForwardIterator>
138861cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
13890b57cec5SDimitry Andrictypename enable_if
13900b57cec5SDimitry Andric<
1391480093f4SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value &&
13920b57cec5SDimitry Andric    is_constructible<
13930b57cec5SDimitry Andric       _Tp,
13940b57cec5SDimitry Andric       typename iterator_traits<_ForwardIterator>::reference>::value,
13950b57cec5SDimitry Andric    void
13960b57cec5SDimitry Andric>::type
13970b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
13980b57cec5SDimitry Andric{
13990b57cec5SDimitry Andric    size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last));
14000b57cec5SDimitry Andric    if (__new_size <= capacity())
14010b57cec5SDimitry Andric    {
14020b57cec5SDimitry Andric        _ForwardIterator __mid = __last;
14030b57cec5SDimitry Andric        bool __growing = false;
14040b57cec5SDimitry Andric        if (__new_size > size())
14050b57cec5SDimitry Andric        {
14060b57cec5SDimitry Andric            __growing = true;
14070b57cec5SDimitry Andric            __mid =  __first;
14080b57cec5SDimitry Andric            _VSTD::advance(__mid, size());
14090b57cec5SDimitry Andric        }
14100b57cec5SDimitry Andric        pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
14110b57cec5SDimitry Andric        if (__growing)
14120b57cec5SDimitry Andric            __construct_at_end(__mid, __last, __new_size - size());
14130b57cec5SDimitry Andric        else
14140b57cec5SDimitry Andric            this->__destruct_at_end(__m);
14150b57cec5SDimitry Andric    }
14160b57cec5SDimitry Andric    else
14170b57cec5SDimitry Andric    {
14180b57cec5SDimitry Andric        __vdeallocate();
14190b57cec5SDimitry Andric        __vallocate(__recommend(__new_size));
14200b57cec5SDimitry Andric        __construct_at_end(__first, __last, __new_size);
14210b57cec5SDimitry Andric    }
142281ad6265SDimitry Andric    std::__debug_db_invalidate_all(this);
14230b57cec5SDimitry Andric}
14240b57cec5SDimitry Andric
14250b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
142661cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
14270b57cec5SDimitry Andricvoid
14280b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
14290b57cec5SDimitry Andric{
14300b57cec5SDimitry Andric    if (__n <= capacity())
14310b57cec5SDimitry Andric    {
14320b57cec5SDimitry Andric        size_type __s = size();
14330b57cec5SDimitry Andric        _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
14340b57cec5SDimitry Andric        if (__n > __s)
14350b57cec5SDimitry Andric            __construct_at_end(__n - __s, __u);
14360b57cec5SDimitry Andric        else
14370b57cec5SDimitry Andric            this->__destruct_at_end(this->__begin_ + __n);
14380b57cec5SDimitry Andric    }
14390b57cec5SDimitry Andric    else
14400b57cec5SDimitry Andric    {
14410b57cec5SDimitry Andric        __vdeallocate();
14420b57cec5SDimitry Andric        __vallocate(__recommend(static_cast<size_type>(__n)));
14430b57cec5SDimitry Andric        __construct_at_end(__n, __u);
14440b57cec5SDimitry Andric    }
144581ad6265SDimitry Andric    std::__debug_db_invalidate_all(this);
14460b57cec5SDimitry Andric}
14470b57cec5SDimitry Andric
14480b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
144961cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
14500b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
14510b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
14520b57cec5SDimitry Andricvector<_Tp, _Allocator>::begin() _NOEXCEPT
14530b57cec5SDimitry Andric{
145481ad6265SDimitry Andric    return iterator(this, this->__begin_);
14550b57cec5SDimitry Andric}
14560b57cec5SDimitry Andric
14570b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
145861cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
14590b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
14600b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_iterator
14610b57cec5SDimitry Andricvector<_Tp, _Allocator>::begin() const _NOEXCEPT
14620b57cec5SDimitry Andric{
146381ad6265SDimitry Andric    return const_iterator(this, this->__begin_);
14640b57cec5SDimitry Andric}
14650b57cec5SDimitry Andric
14660b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
146761cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
14680b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
14690b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
14700b57cec5SDimitry Andricvector<_Tp, _Allocator>::end() _NOEXCEPT
14710b57cec5SDimitry Andric{
147281ad6265SDimitry Andric    return iterator(this, this->__end_);
14730b57cec5SDimitry Andric}
14740b57cec5SDimitry Andric
14750b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
147661cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
14770b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
14780b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_iterator
14790b57cec5SDimitry Andricvector<_Tp, _Allocator>::end() const _NOEXCEPT
14800b57cec5SDimitry Andric{
148181ad6265SDimitry Andric    return const_iterator(this, this->__end_);
14820b57cec5SDimitry Andric}
14830b57cec5SDimitry Andric
14840b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
148561cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
14860b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
14870b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference
14880b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT
14890b57cec5SDimitry Andric{
14900b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
14910b57cec5SDimitry Andric    return this->__begin_[__n];
14920b57cec5SDimitry Andric}
14930b57cec5SDimitry Andric
14940b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
149561cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
14960b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
14970b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_reference
14980b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT
14990b57cec5SDimitry Andric{
15000b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
15010b57cec5SDimitry Andric    return this->__begin_[__n];
15020b57cec5SDimitry Andric}
15030b57cec5SDimitry Andric
15040b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
150561cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
15060b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference
15070b57cec5SDimitry Andricvector<_Tp, _Allocator>::at(size_type __n)
15080b57cec5SDimitry Andric{
15090b57cec5SDimitry Andric    if (__n >= size())
15100b57cec5SDimitry Andric        this->__throw_out_of_range();
15110b57cec5SDimitry Andric    return this->__begin_[__n];
15120b57cec5SDimitry Andric}
15130b57cec5SDimitry Andric
15140b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
151561cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
15160b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_reference
15170b57cec5SDimitry Andricvector<_Tp, _Allocator>::at(size_type __n) const
15180b57cec5SDimitry Andric{
15190b57cec5SDimitry Andric    if (__n >= size())
15200b57cec5SDimitry Andric        this->__throw_out_of_range();
15210b57cec5SDimitry Andric    return this->__begin_[__n];
15220b57cec5SDimitry Andric}
15230b57cec5SDimitry Andric
15240b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
152561cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
15260b57cec5SDimitry Andricvoid
15270b57cec5SDimitry Andricvector<_Tp, _Allocator>::reserve(size_type __n)
15280b57cec5SDimitry Andric{
15290b57cec5SDimitry Andric    if (__n > capacity())
15300b57cec5SDimitry Andric    {
1531349cc55cSDimitry Andric        if (__n > max_size())
1532349cc55cSDimitry Andric            this->__throw_length_error();
15330b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
15340b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
15350b57cec5SDimitry Andric        __swap_out_circular_buffer(__v);
15360b57cec5SDimitry Andric    }
15370b57cec5SDimitry Andric}
15380b57cec5SDimitry Andric
15390b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
154061cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
15410b57cec5SDimitry Andricvoid
15420b57cec5SDimitry Andricvector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
15430b57cec5SDimitry Andric{
15440b57cec5SDimitry Andric    if (capacity() > size())
15450b57cec5SDimitry Andric    {
15460b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
15470b57cec5SDimitry Andric        try
15480b57cec5SDimitry Andric        {
15490b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
15500b57cec5SDimitry Andric            allocator_type& __a = this->__alloc();
15510b57cec5SDimitry Andric            __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
15520b57cec5SDimitry Andric            __swap_out_circular_buffer(__v);
15530b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
15540b57cec5SDimitry Andric        }
15550b57cec5SDimitry Andric        catch (...)
15560b57cec5SDimitry Andric        {
15570b57cec5SDimitry Andric        }
15580b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
15590b57cec5SDimitry Andric    }
15600b57cec5SDimitry Andric}
15610b57cec5SDimitry Andric
15620b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
15630b57cec5SDimitry Andrictemplate <class _Up>
156461cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
15650b57cec5SDimitry Andricvoid
15660b57cec5SDimitry Andricvector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
15670b57cec5SDimitry Andric{
15680b57cec5SDimitry Andric    allocator_type& __a = this->__alloc();
15690b57cec5SDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
15700b57cec5SDimitry Andric    // __v.push_back(_VSTD::forward<_Up>(__x));
1571480093f4SDimitry Andric    __alloc_traits::construct(__a, _VSTD::__to_address(__v.__end_), _VSTD::forward<_Up>(__x));
15720b57cec5SDimitry Andric    __v.__end_++;
15730b57cec5SDimitry Andric    __swap_out_circular_buffer(__v);
15740b57cec5SDimitry Andric}
15750b57cec5SDimitry Andric
15760b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
157761cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
15780b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
15790b57cec5SDimitry Andricvoid
15800b57cec5SDimitry Andricvector<_Tp, _Allocator>::push_back(const_reference __x)
15810b57cec5SDimitry Andric{
15820b57cec5SDimitry Andric    if (this->__end_ != this->__end_cap())
15830b57cec5SDimitry Andric    {
1584e40139ffSDimitry Andric        __construct_one_at_end(__x);
15850b57cec5SDimitry Andric    }
15860b57cec5SDimitry Andric    else
15870b57cec5SDimitry Andric        __push_back_slow_path(__x);
15880b57cec5SDimitry Andric}
15890b57cec5SDimitry Andric
15900b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
159161cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
15920b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
15930b57cec5SDimitry Andricvoid
15940b57cec5SDimitry Andricvector<_Tp, _Allocator>::push_back(value_type&& __x)
15950b57cec5SDimitry Andric{
15960b57cec5SDimitry Andric    if (this->__end_ < this->__end_cap())
15970b57cec5SDimitry Andric    {
1598e40139ffSDimitry Andric        __construct_one_at_end(_VSTD::move(__x));
15990b57cec5SDimitry Andric    }
16000b57cec5SDimitry Andric    else
16010b57cec5SDimitry Andric        __push_back_slow_path(_VSTD::move(__x));
16020b57cec5SDimitry Andric}
16030b57cec5SDimitry Andric
16040b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
16050b57cec5SDimitry Andrictemplate <class... _Args>
160661cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
16070b57cec5SDimitry Andricvoid
16080b57cec5SDimitry Andricvector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
16090b57cec5SDimitry Andric{
16100b57cec5SDimitry Andric    allocator_type& __a = this->__alloc();
16110b57cec5SDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
16120b57cec5SDimitry Andric//    __v.emplace_back(_VSTD::forward<_Args>(__args)...);
1613480093f4SDimitry Andric    __alloc_traits::construct(__a, _VSTD::__to_address(__v.__end_), _VSTD::forward<_Args>(__args)...);
16140b57cec5SDimitry Andric    __v.__end_++;
16150b57cec5SDimitry Andric    __swap_out_circular_buffer(__v);
16160b57cec5SDimitry Andric}
16170b57cec5SDimitry Andric
16180b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
16190b57cec5SDimitry Andrictemplate <class... _Args>
162061cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
16210b57cec5SDimitry Andricinline
16220b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
16230b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference
16240b57cec5SDimitry Andric#else
16250b57cec5SDimitry Andricvoid
16260b57cec5SDimitry Andric#endif
16270b57cec5SDimitry Andricvector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
16280b57cec5SDimitry Andric{
16290b57cec5SDimitry Andric    if (this->__end_ < this->__end_cap())
16300b57cec5SDimitry Andric    {
1631e40139ffSDimitry Andric        __construct_one_at_end(_VSTD::forward<_Args>(__args)...);
16320b57cec5SDimitry Andric    }
16330b57cec5SDimitry Andric    else
16340b57cec5SDimitry Andric        __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...);
16350b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
16360b57cec5SDimitry Andric    return this->back();
16370b57cec5SDimitry Andric#endif
16380b57cec5SDimitry Andric}
16390b57cec5SDimitry Andric
16400b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
164161cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
16420b57cec5SDimitry Andricinline
16430b57cec5SDimitry Andricvoid
16440b57cec5SDimitry Andricvector<_Tp, _Allocator>::pop_back()
16450b57cec5SDimitry Andric{
1646fe6060f1SDimitry Andric    _LIBCPP_ASSERT(!empty(), "vector::pop_back called on an empty vector");
16470b57cec5SDimitry Andric    this->__destruct_at_end(this->__end_ - 1);
16480b57cec5SDimitry Andric}
16490b57cec5SDimitry Andric
16500b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
165161cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
16520b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
16530b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
16540b57cec5SDimitry Andricvector<_Tp, _Allocator>::erase(const_iterator __position)
16550b57cec5SDimitry Andric{
165604eeddc0SDimitry Andric    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
165704eeddc0SDimitry Andric                         "vector::erase(iterator) called with an iterator not referring to this vector");
16580b57cec5SDimitry Andric    _LIBCPP_ASSERT(__position != end(),
16590b57cec5SDimitry Andric        "vector::erase(iterator) called with a non-dereferenceable iterator");
16600b57cec5SDimitry Andric    difference_type __ps = __position - cbegin();
16610b57cec5SDimitry Andric    pointer __p = this->__begin_ + __ps;
16620b57cec5SDimitry Andric    this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
166361cfbce3SDimitry Andric    if (!__libcpp_is_constant_evaluated())
16640b57cec5SDimitry Andric        this->__invalidate_iterators_past(__p - 1);
166581ad6265SDimitry Andric    iterator __r = iterator(this, __p);
16660b57cec5SDimitry Andric    return __r;
16670b57cec5SDimitry Andric}
16680b57cec5SDimitry Andric
16690b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
167061cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
16710b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
16720b57cec5SDimitry Andricvector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
16730b57cec5SDimitry Andric{
167404eeddc0SDimitry Andric    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__first)) == this,
167504eeddc0SDimitry Andric                         "vector::erase(iterator, iterator) called with an iterator not referring to this vector");
167604eeddc0SDimitry Andric    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__last)) == this,
167704eeddc0SDimitry Andric                         "vector::erase(iterator, iterator) called with an iterator not referring to this vector");
167804eeddc0SDimitry Andric
16790b57cec5SDimitry Andric    _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
16800b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__first - begin());
16810b57cec5SDimitry Andric    if (__first != __last) {
16820b57cec5SDimitry Andric        this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
168361cfbce3SDimitry Andric        if (!__libcpp_is_constant_evaluated())
16840b57cec5SDimitry Andric            this->__invalidate_iterators_past(__p - 1);
16850b57cec5SDimitry Andric    }
168681ad6265SDimitry Andric    iterator __r = iterator(this, __p);
16870b57cec5SDimitry Andric    return __r;
16880b57cec5SDimitry Andric}
16890b57cec5SDimitry Andric
16900b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
169161cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
16920b57cec5SDimitry Andricvoid
16930b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
16940b57cec5SDimitry Andric{
16950b57cec5SDimitry Andric    pointer __old_last = this->__end_;
16960b57cec5SDimitry Andric    difference_type __n = __old_last - __to;
1697e40139ffSDimitry Andric    {
1698e40139ffSDimitry Andric      pointer __i = __from_s + __n;
1699e40139ffSDimitry Andric      _ConstructTransaction __tx(*this, __from_e - __i);
17005ffd83dbSDimitry Andric      for (pointer __pos = __tx.__pos_; __i < __from_e;
1701349cc55cSDimitry Andric           ++__i, (void) ++__pos, __tx.__pos_ = __pos) {
17020b57cec5SDimitry Andric          __alloc_traits::construct(this->__alloc(),
17035ffd83dbSDimitry Andric                                    _VSTD::__to_address(__pos),
17040b57cec5SDimitry Andric                                    _VSTD::move(*__i));
1705e40139ffSDimitry Andric      }
1706e40139ffSDimitry Andric    }
17070b57cec5SDimitry Andric    _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
17080b57cec5SDimitry Andric}
17090b57cec5SDimitry Andric
17100b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
171161cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
17120b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
17130b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
17140b57cec5SDimitry Andric{
171504eeddc0SDimitry Andric    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
171604eeddc0SDimitry Andric                         "vector::insert(iterator, x) called with an iterator not referring to this vector");
17170b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__position - begin());
171861cfbce3SDimitry Andric    // We can't compare unrelated pointers inside constant expressions
171961cfbce3SDimitry Andric    if (!__libcpp_is_constant_evaluated() && this->__end_ < this->__end_cap())
17200b57cec5SDimitry Andric    {
17210b57cec5SDimitry Andric        if (__p == this->__end_)
17220b57cec5SDimitry Andric        {
1723e40139ffSDimitry Andric            __construct_one_at_end(__x);
17240b57cec5SDimitry Andric        }
17250b57cec5SDimitry Andric        else
17260b57cec5SDimitry Andric        {
17270b57cec5SDimitry Andric            __move_range(__p, this->__end_, __p + 1);
17280b57cec5SDimitry Andric            const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
17290b57cec5SDimitry Andric            if (__p <= __xr && __xr < this->__end_)
17300b57cec5SDimitry Andric                ++__xr;
17310b57cec5SDimitry Andric            *__p = *__xr;
17320b57cec5SDimitry Andric        }
17330b57cec5SDimitry Andric    }
17340b57cec5SDimitry Andric    else
17350b57cec5SDimitry Andric    {
17360b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
17370b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
17380b57cec5SDimitry Andric        __v.push_back(__x);
17390b57cec5SDimitry Andric        __p = __swap_out_circular_buffer(__v, __p);
17400b57cec5SDimitry Andric    }
174181ad6265SDimitry Andric    return iterator(this, __p);
17420b57cec5SDimitry Andric}
17430b57cec5SDimitry Andric
17440b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
174561cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
17460b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
17470b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
17480b57cec5SDimitry Andric{
174904eeddc0SDimitry Andric    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
175004eeddc0SDimitry Andric                         "vector::insert(iterator, x) called with an iterator not referring to this vector");
17510b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__position - begin());
17520b57cec5SDimitry Andric    if (this->__end_ < this->__end_cap())
17530b57cec5SDimitry Andric    {
17540b57cec5SDimitry Andric        if (__p == this->__end_)
17550b57cec5SDimitry Andric        {
1756e40139ffSDimitry Andric            __construct_one_at_end(_VSTD::move(__x));
17570b57cec5SDimitry Andric        }
17580b57cec5SDimitry Andric        else
17590b57cec5SDimitry Andric        {
17600b57cec5SDimitry Andric            __move_range(__p, this->__end_, __p + 1);
17610b57cec5SDimitry Andric            *__p = _VSTD::move(__x);
17620b57cec5SDimitry Andric        }
17630b57cec5SDimitry Andric    }
17640b57cec5SDimitry Andric    else
17650b57cec5SDimitry Andric    {
17660b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
17670b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
17680b57cec5SDimitry Andric        __v.push_back(_VSTD::move(__x));
17690b57cec5SDimitry Andric        __p = __swap_out_circular_buffer(__v, __p);
17700b57cec5SDimitry Andric    }
177181ad6265SDimitry Andric    return iterator(this, __p);
17720b57cec5SDimitry Andric}
17730b57cec5SDimitry Andric
17740b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
17750b57cec5SDimitry Andrictemplate <class... _Args>
177661cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
17770b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
17780b57cec5SDimitry Andricvector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
17790b57cec5SDimitry Andric{
178004eeddc0SDimitry Andric    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
178104eeddc0SDimitry Andric                         "vector::emplace(iterator, x) called with an iterator not referring to this vector");
17820b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__position - begin());
17830b57cec5SDimitry Andric    if (this->__end_ < this->__end_cap())
17840b57cec5SDimitry Andric    {
17850b57cec5SDimitry Andric        if (__p == this->__end_)
17860b57cec5SDimitry Andric        {
1787e40139ffSDimitry Andric            __construct_one_at_end(_VSTD::forward<_Args>(__args)...);
17880b57cec5SDimitry Andric        }
17890b57cec5SDimitry Andric        else
17900b57cec5SDimitry Andric        {
17910b57cec5SDimitry Andric            __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...);
17920b57cec5SDimitry Andric            __move_range(__p, this->__end_, __p + 1);
17930b57cec5SDimitry Andric            *__p = _VSTD::move(__tmp.get());
17940b57cec5SDimitry Andric        }
17950b57cec5SDimitry Andric    }
17960b57cec5SDimitry Andric    else
17970b57cec5SDimitry Andric    {
17980b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
17990b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
18000b57cec5SDimitry Andric        __v.emplace_back(_VSTD::forward<_Args>(__args)...);
18010b57cec5SDimitry Andric        __p = __swap_out_circular_buffer(__v, __p);
18020b57cec5SDimitry Andric    }
180381ad6265SDimitry Andric    return iterator(this, __p);
18040b57cec5SDimitry Andric}
18050b57cec5SDimitry Andric
18060b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
180761cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
18080b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
18090b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
18100b57cec5SDimitry Andric{
181104eeddc0SDimitry Andric    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
181204eeddc0SDimitry Andric                         "vector::insert(iterator, n, x) called with an iterator not referring to this vector");
18130b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__position - begin());
18140b57cec5SDimitry Andric    if (__n > 0)
18150b57cec5SDimitry Andric    {
181661cfbce3SDimitry Andric        // We can't compare unrelated pointers inside constant expressions
181761cfbce3SDimitry Andric        if (!__libcpp_is_constant_evaluated() && __n <= static_cast<size_type>(this->__end_cap() - this->__end_))
18180b57cec5SDimitry Andric        {
18190b57cec5SDimitry Andric            size_type __old_n = __n;
18200b57cec5SDimitry Andric            pointer __old_last = this->__end_;
18210b57cec5SDimitry Andric            if (__n > static_cast<size_type>(this->__end_ - __p))
18220b57cec5SDimitry Andric            {
18230b57cec5SDimitry Andric                size_type __cx = __n - (this->__end_ - __p);
18240b57cec5SDimitry Andric                __construct_at_end(__cx, __x);
18250b57cec5SDimitry Andric                __n -= __cx;
18260b57cec5SDimitry Andric            }
18270b57cec5SDimitry Andric            if (__n > 0)
18280b57cec5SDimitry Andric            {
18290b57cec5SDimitry Andric                __move_range(__p, __old_last, __p + __old_n);
18300b57cec5SDimitry Andric                const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
18310b57cec5SDimitry Andric                if (__p <= __xr && __xr < this->__end_)
18320b57cec5SDimitry Andric                    __xr += __old_n;
18330b57cec5SDimitry Andric                _VSTD::fill_n(__p, __n, *__xr);
18340b57cec5SDimitry Andric            }
18350b57cec5SDimitry Andric        }
18360b57cec5SDimitry Andric        else
18370b57cec5SDimitry Andric        {
18380b57cec5SDimitry Andric            allocator_type& __a = this->__alloc();
18390b57cec5SDimitry Andric            __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
18400b57cec5SDimitry Andric            __v.__construct_at_end(__n, __x);
18410b57cec5SDimitry Andric            __p = __swap_out_circular_buffer(__v, __p);
18420b57cec5SDimitry Andric        }
18430b57cec5SDimitry Andric    }
184481ad6265SDimitry Andric    return iterator(this, __p);
18450b57cec5SDimitry Andric}
18460b57cec5SDimitry Andric
18470b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
18480b57cec5SDimitry Andrictemplate <class _InputIterator>
184961cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
18500b57cec5SDimitry Andric    is_constructible<
18510b57cec5SDimitry Andric       _Tp,
18520b57cec5SDimitry Andric       typename iterator_traits<_InputIterator>::reference>::value,
18530b57cec5SDimitry Andric    typename vector<_Tp, _Allocator>::iterator
18540b57cec5SDimitry Andric>::type
18550b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
18560b57cec5SDimitry Andric{
185704eeddc0SDimitry Andric    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
185804eeddc0SDimitry Andric                         "vector::insert(iterator, range) called with an iterator not referring to this vector");
18590b57cec5SDimitry Andric    difference_type __off = __position - begin();
18600b57cec5SDimitry Andric    pointer __p = this->__begin_ + __off;
18610b57cec5SDimitry Andric    allocator_type& __a = this->__alloc();
18620b57cec5SDimitry Andric    pointer __old_last = this->__end_;
18630b57cec5SDimitry Andric    for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
18640b57cec5SDimitry Andric    {
1865e40139ffSDimitry Andric        __construct_one_at_end(*__first);
18660b57cec5SDimitry Andric    }
18670b57cec5SDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__a);
18680b57cec5SDimitry Andric    if (__first != __last)
18690b57cec5SDimitry Andric    {
18700b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
18710b57cec5SDimitry Andric        try
18720b57cec5SDimitry Andric        {
18730b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
18740b57cec5SDimitry Andric            __v.__construct_at_end(__first, __last);
18750b57cec5SDimitry Andric            difference_type __old_size = __old_last - this->__begin_;
18760b57cec5SDimitry Andric            difference_type __old_p = __p - this->__begin_;
18770b57cec5SDimitry Andric            reserve(__recommend(size() + __v.size()));
18780b57cec5SDimitry Andric            __p = this->__begin_ + __old_p;
18790b57cec5SDimitry Andric            __old_last = this->__begin_ + __old_size;
18800b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
18810b57cec5SDimitry Andric        }
18820b57cec5SDimitry Andric        catch (...)
18830b57cec5SDimitry Andric        {
188481ad6265SDimitry Andric            erase(iterator(this, __old_last), end());
18850b57cec5SDimitry Andric            throw;
18860b57cec5SDimitry Andric        }
18870b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
18880b57cec5SDimitry Andric    }
18890b57cec5SDimitry Andric    __p = _VSTD::rotate(__p, __old_last, this->__end_);
189081ad6265SDimitry Andric    insert(iterator(this, __p), _VSTD::make_move_iterator(__v.begin()),
18915ffd83dbSDimitry Andric                                _VSTD::make_move_iterator(__v.end()));
18920b57cec5SDimitry Andric    return begin() + __off;
18930b57cec5SDimitry Andric}
18940b57cec5SDimitry Andric
18950b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
18960b57cec5SDimitry Andrictemplate <class _ForwardIterator>
189761cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
18980b57cec5SDimitry Andrictypename enable_if
18990b57cec5SDimitry Andric<
1900480093f4SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value &&
19010b57cec5SDimitry Andric    is_constructible<
19020b57cec5SDimitry Andric       _Tp,
19030b57cec5SDimitry Andric       typename iterator_traits<_ForwardIterator>::reference>::value,
19040b57cec5SDimitry Andric    typename vector<_Tp, _Allocator>::iterator
19050b57cec5SDimitry Andric>::type
19060b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
19070b57cec5SDimitry Andric{
190804eeddc0SDimitry Andric    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
190904eeddc0SDimitry Andric                         "vector::insert(iterator, range) called with an iterator not referring to this vector");
19100b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__position - begin());
19110b57cec5SDimitry Andric    difference_type __n = _VSTD::distance(__first, __last);
19120b57cec5SDimitry Andric    if (__n > 0)
19130b57cec5SDimitry Andric    {
19140b57cec5SDimitry Andric        if (__n <= this->__end_cap() - this->__end_)
19150b57cec5SDimitry Andric        {
19160b57cec5SDimitry Andric            size_type __old_n = __n;
19170b57cec5SDimitry Andric            pointer __old_last = this->__end_;
19180b57cec5SDimitry Andric            _ForwardIterator __m = __last;
19190b57cec5SDimitry Andric            difference_type __dx = this->__end_ - __p;
19200b57cec5SDimitry Andric            if (__n > __dx)
19210b57cec5SDimitry Andric            {
19220b57cec5SDimitry Andric                __m = __first;
19230b57cec5SDimitry Andric                difference_type __diff = this->__end_ - __p;
19240b57cec5SDimitry Andric                _VSTD::advance(__m, __diff);
19250b57cec5SDimitry Andric                __construct_at_end(__m, __last, __n - __diff);
19260b57cec5SDimitry Andric                __n = __dx;
19270b57cec5SDimitry Andric            }
19280b57cec5SDimitry Andric            if (__n > 0)
19290b57cec5SDimitry Andric            {
19300b57cec5SDimitry Andric                __move_range(__p, __old_last, __p + __old_n);
19310b57cec5SDimitry Andric                _VSTD::copy(__first, __m, __p);
19320b57cec5SDimitry Andric            }
19330b57cec5SDimitry Andric        }
19340b57cec5SDimitry Andric        else
19350b57cec5SDimitry Andric        {
19360b57cec5SDimitry Andric            allocator_type& __a = this->__alloc();
19370b57cec5SDimitry Andric            __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
19380b57cec5SDimitry Andric            __v.__construct_at_end(__first, __last);
19390b57cec5SDimitry Andric            __p = __swap_out_circular_buffer(__v, __p);
19400b57cec5SDimitry Andric        }
19410b57cec5SDimitry Andric    }
194281ad6265SDimitry Andric    return iterator(this, __p);
19430b57cec5SDimitry Andric}
19440b57cec5SDimitry Andric
19450b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
194661cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
19470b57cec5SDimitry Andricvoid
19480b57cec5SDimitry Andricvector<_Tp, _Allocator>::resize(size_type __sz)
19490b57cec5SDimitry Andric{
19500b57cec5SDimitry Andric    size_type __cs = size();
19510b57cec5SDimitry Andric    if (__cs < __sz)
19520b57cec5SDimitry Andric        this->__append(__sz - __cs);
19530b57cec5SDimitry Andric    else if (__cs > __sz)
19540b57cec5SDimitry Andric        this->__destruct_at_end(this->__begin_ + __sz);
19550b57cec5SDimitry Andric}
19560b57cec5SDimitry Andric
19570b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
195861cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
19590b57cec5SDimitry Andricvoid
19600b57cec5SDimitry Andricvector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
19610b57cec5SDimitry Andric{
19620b57cec5SDimitry Andric    size_type __cs = size();
19630b57cec5SDimitry Andric    if (__cs < __sz)
19640b57cec5SDimitry Andric        this->__append(__sz - __cs, __x);
19650b57cec5SDimitry Andric    else if (__cs > __sz)
19660b57cec5SDimitry Andric        this->__destruct_at_end(this->__begin_ + __sz);
19670b57cec5SDimitry Andric}
19680b57cec5SDimitry Andric
19690b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
197061cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
19710b57cec5SDimitry Andricvoid
19720b57cec5SDimitry Andricvector<_Tp, _Allocator>::swap(vector& __x)
19730b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
19740b57cec5SDimitry Andric    _NOEXCEPT
19750b57cec5SDimitry Andric#else
19760b57cec5SDimitry Andric    _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
19770b57cec5SDimitry Andric                __is_nothrow_swappable<allocator_type>::value)
19780b57cec5SDimitry Andric#endif
19790b57cec5SDimitry Andric{
19800b57cec5SDimitry Andric    _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
19810b57cec5SDimitry Andric                   this->__alloc() == __x.__alloc(),
19820b57cec5SDimitry Andric                   "vector::swap: Either propagate_on_container_swap must be true"
19830b57cec5SDimitry Andric                   " or the allocators must compare equal");
19840b57cec5SDimitry Andric    _VSTD::swap(this->__begin_, __x.__begin_);
19850b57cec5SDimitry Andric    _VSTD::swap(this->__end_, __x.__end_);
19860b57cec5SDimitry Andric    _VSTD::swap(this->__end_cap(), __x.__end_cap());
1987e8d8bef9SDimitry Andric    _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(),
19880b57cec5SDimitry Andric        integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>());
198981ad6265SDimitry Andric    std::__debug_db_swap(this, std::addressof(__x));
19900b57cec5SDimitry Andric}
19910b57cec5SDimitry Andric
19920b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
199361cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
19940b57cec5SDimitry Andricbool
19950b57cec5SDimitry Andricvector<_Tp, _Allocator>::__invariants() const
19960b57cec5SDimitry Andric{
19970b57cec5SDimitry Andric    if (this->__begin_ == nullptr)
19980b57cec5SDimitry Andric    {
19990b57cec5SDimitry Andric        if (this->__end_ != nullptr || this->__end_cap() != nullptr)
20000b57cec5SDimitry Andric            return false;
20010b57cec5SDimitry Andric    }
20020b57cec5SDimitry Andric    else
20030b57cec5SDimitry Andric    {
20040b57cec5SDimitry Andric        if (this->__begin_ > this->__end_)
20050b57cec5SDimitry Andric            return false;
20060b57cec5SDimitry Andric        if (this->__begin_ == this->__end_cap())
20070b57cec5SDimitry Andric            return false;
20080b57cec5SDimitry Andric        if (this->__end_ > this->__end_cap())
20090b57cec5SDimitry Andric            return false;
20100b57cec5SDimitry Andric    }
20110b57cec5SDimitry Andric    return true;
20120b57cec5SDimitry Andric}
20130b57cec5SDimitry Andric
201481ad6265SDimitry Andric#ifdef _LIBCPP_ENABLE_DEBUG_MODE
20150b57cec5SDimitry Andric
20160b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
20170b57cec5SDimitry Andricbool
20180b57cec5SDimitry Andricvector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
20190b57cec5SDimitry Andric{
20200b57cec5SDimitry Andric    return this->__begin_ <= __i->base() && __i->base() < this->__end_;
20210b57cec5SDimitry Andric}
20220b57cec5SDimitry Andric
20230b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
20240b57cec5SDimitry Andricbool
20250b57cec5SDimitry Andricvector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
20260b57cec5SDimitry Andric{
20270b57cec5SDimitry Andric    return this->__begin_ < __i->base() && __i->base() <= this->__end_;
20280b57cec5SDimitry Andric}
20290b57cec5SDimitry Andric
20300b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
20310b57cec5SDimitry Andricbool
20320b57cec5SDimitry Andricvector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
20330b57cec5SDimitry Andric{
20340b57cec5SDimitry Andric    const_pointer __p = __i->base() + __n;
20350b57cec5SDimitry Andric    return this->__begin_ <= __p && __p <= this->__end_;
20360b57cec5SDimitry Andric}
20370b57cec5SDimitry Andric
20380b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
20390b57cec5SDimitry Andricbool
20400b57cec5SDimitry Andricvector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
20410b57cec5SDimitry Andric{
20420b57cec5SDimitry Andric    const_pointer __p = __i->base() + __n;
20430b57cec5SDimitry Andric    return this->__begin_ <= __p && __p < this->__end_;
20440b57cec5SDimitry Andric}
20450b57cec5SDimitry Andric
204681ad6265SDimitry Andric#endif // _LIBCPP_ENABLE_DEBUG_MODE
20470b57cec5SDimitry Andric
20480b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
20490b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
20500b57cec5SDimitry Andricvoid
20510b57cec5SDimitry Andricvector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) {
205281ad6265SDimitry Andric#ifdef _LIBCPP_ENABLE_DEBUG_MODE
20530b57cec5SDimitry Andric  __c_node* __c = __get_db()->__find_c_and_lock(this);
20540b57cec5SDimitry Andric  for (__i_node** __p = __c->end_; __p != __c->beg_; ) {
20550b57cec5SDimitry Andric    --__p;
20560b57cec5SDimitry Andric    const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
20570b57cec5SDimitry Andric    if (__i->base() > __new_last) {
20580b57cec5SDimitry Andric      (*__p)->__c_ = nullptr;
20590b57cec5SDimitry Andric      if (--__c->end_ != __p)
2060e8d8bef9SDimitry Andric        _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
20610b57cec5SDimitry Andric    }
20620b57cec5SDimitry Andric  }
20630b57cec5SDimitry Andric  __get_db()->unlock();
20640b57cec5SDimitry Andric#else
20650b57cec5SDimitry Andric  ((void)__new_last);
20660b57cec5SDimitry Andric#endif
20670b57cec5SDimitry Andric}
20680b57cec5SDimitry Andric
20690b57cec5SDimitry Andric// vector<bool>
20700b57cec5SDimitry Andric
20710b57cec5SDimitry Andrictemplate <class _Allocator> class vector<bool, _Allocator>;
20720b57cec5SDimitry Andric
20730b57cec5SDimitry Andrictemplate <class _Allocator> struct hash<vector<bool, _Allocator> >;
20740b57cec5SDimitry Andric
20750b57cec5SDimitry Andrictemplate <class _Allocator>
20760b57cec5SDimitry Andricstruct __has_storage_type<vector<bool, _Allocator> >
20770b57cec5SDimitry Andric{
20780b57cec5SDimitry Andric    static const bool value = true;
20790b57cec5SDimitry Andric};
20800b57cec5SDimitry Andric
20810b57cec5SDimitry Andrictemplate <class _Allocator>
20820b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator>
20830b57cec5SDimitry Andric{
20840b57cec5SDimitry Andricpublic:
20850b57cec5SDimitry Andric    typedef vector                                   __self;
20860b57cec5SDimitry Andric    typedef bool                                     value_type;
20870b57cec5SDimitry Andric    typedef _Allocator                               allocator_type;
20880b57cec5SDimitry Andric    typedef allocator_traits<allocator_type>         __alloc_traits;
20890b57cec5SDimitry Andric    typedef typename __alloc_traits::size_type       size_type;
20900b57cec5SDimitry Andric    typedef typename __alloc_traits::difference_type difference_type;
20910b57cec5SDimitry Andric    typedef size_type __storage_type;
20920b57cec5SDimitry Andric    typedef __bit_iterator<vector, false>            pointer;
20930b57cec5SDimitry Andric    typedef __bit_iterator<vector, true>             const_pointer;
20940b57cec5SDimitry Andric    typedef pointer                                  iterator;
20950b57cec5SDimitry Andric    typedef const_pointer                            const_iterator;
20960b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<iterator>         reverse_iterator;
20970b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<const_iterator>   const_reverse_iterator;
20980b57cec5SDimitry Andric
20990b57cec5SDimitry Andricprivate:
21000b57cec5SDimitry Andric    typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator;
21010b57cec5SDimitry Andric    typedef allocator_traits<__storage_allocator>    __storage_traits;
21020b57cec5SDimitry Andric    typedef typename __storage_traits::pointer       __storage_pointer;
21030b57cec5SDimitry Andric    typedef typename __storage_traits::const_pointer __const_storage_pointer;
21040b57cec5SDimitry Andric
21050b57cec5SDimitry Andric    __storage_pointer                                      __begin_;
21060b57cec5SDimitry Andric    size_type                                              __size_;
21070b57cec5SDimitry Andric    __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
21080b57cec5SDimitry Andricpublic:
21090b57cec5SDimitry Andric    typedef __bit_reference<vector>                  reference;
211081ad6265SDimitry Andric#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
211181ad6265SDimitry Andric    using const_reference = bool;
211281ad6265SDimitry Andric#else
21130b57cec5SDimitry Andric    typedef __bit_const_reference<vector>            const_reference;
211481ad6265SDimitry Andric#endif
21150b57cec5SDimitry Andricprivate:
211661cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
21170b57cec5SDimitry Andric    size_type& __cap() _NOEXCEPT
21180b57cec5SDimitry Andric        {return __cap_alloc_.first();}
211961cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
21200b57cec5SDimitry Andric    const size_type& __cap() const _NOEXCEPT
21210b57cec5SDimitry Andric        {return __cap_alloc_.first();}
212261cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
21230b57cec5SDimitry Andric    __storage_allocator& __alloc() _NOEXCEPT
21240b57cec5SDimitry Andric        {return __cap_alloc_.second();}
212561cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
21260b57cec5SDimitry Andric    const __storage_allocator& __alloc() const _NOEXCEPT
21270b57cec5SDimitry Andric        {return __cap_alloc_.second();}
21280b57cec5SDimitry Andric
21290b57cec5SDimitry Andric    static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
21300b57cec5SDimitry Andric
213161cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
21320b57cec5SDimitry Andric    static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
21330b57cec5SDimitry Andric        {return __n * __bits_per_word;}
213461cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
21350b57cec5SDimitry Andric    static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
21360b57cec5SDimitry Andric        {return (__n - 1) / __bits_per_word + 1;}
21370b57cec5SDimitry Andric
21380b57cec5SDimitry Andricpublic:
213961cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
21400b57cec5SDimitry Andric    vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
21410b57cec5SDimitry Andric
214261cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit vector(const allocator_type& __a)
21430b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
21440b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
21450b57cec5SDimitry Andric#else
21460b57cec5SDimitry Andric        _NOEXCEPT;
21470b57cec5SDimitry Andric#endif
2148*50d7464cSDimitry Andric
2149*50d7464cSDimitry Andricprivate:
2150*50d7464cSDimitry Andric  class __destroy_vector {
2151*50d7464cSDimitry Andric    public:
2152*50d7464cSDimitry Andric      _LIBCPP_CONSTEXPR __destroy_vector(vector& __vec) : __vec_(__vec) {}
2153*50d7464cSDimitry Andric
2154*50d7464cSDimitry Andric      _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI void operator()() {
2155*50d7464cSDimitry Andric        if (__vec_.__begin_ != nullptr)
2156*50d7464cSDimitry Andric            __storage_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.__cap());
2157*50d7464cSDimitry Andric        std::__debug_db_invalidate_all(this);
2158*50d7464cSDimitry Andric      }
2159*50d7464cSDimitry Andric
2160*50d7464cSDimitry Andric    private:
2161*50d7464cSDimitry Andric      vector& __vec_;
2162*50d7464cSDimitry Andric  };
2163*50d7464cSDimitry Andric
2164*50d7464cSDimitry Andricpublic:
2165*50d7464cSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 ~vector() { __destroy_vector(*this)(); }
2166*50d7464cSDimitry Andric
2167*50d7464cSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit vector(size_type __n);
21680b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
216961cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit vector(size_type __n, const allocator_type& __a);
21700b57cec5SDimitry Andric#endif
217161cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(size_type __n, const value_type& __v);
217261cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(size_type __n, const value_type& __v, const allocator_type& __a);
21730b57cec5SDimitry Andric    template <class _InputIterator>
217461cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(_InputIterator __first, _InputIterator __last,
2175753f127fSDimitry Andric               typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type* = 0);
21760b57cec5SDimitry Andric    template <class _InputIterator>
217761cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2178753f127fSDimitry Andric               typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type* = 0);
21790b57cec5SDimitry Andric    template <class _ForwardIterator>
218061cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(_ForwardIterator __first, _ForwardIterator __last,
2181480093f4SDimitry Andric               typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0);
21820b57cec5SDimitry Andric    template <class _ForwardIterator>
218361cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2184480093f4SDimitry Andric               typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0);
21850b57cec5SDimitry Andric
218661cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(const vector& __v);
218761cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(const vector& __v, const allocator_type& __a);
218861cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 vector& operator=(const vector& __v);
21890b57cec5SDimitry Andric
21900b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
219161cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(initializer_list<value_type> __il);
219261cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(initializer_list<value_type> __il, const allocator_type& __a);
21930b57cec5SDimitry Andric
219461cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
21950b57cec5SDimitry Andric    vector& operator=(initializer_list<value_type> __il)
21960b57cec5SDimitry Andric        {assign(__il.begin(), __il.end()); return *this;}
21970b57cec5SDimitry Andric
21980b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG
21990b57cec5SDimitry Andric
220061cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
220181ad6265SDimitry Andric    vector(vector&& __v)
220281ad6265SDimitry Andric#if _LIBCPP_STD_VER > 14
220381ad6265SDimitry Andric        noexcept;
220481ad6265SDimitry Andric#else
220581ad6265SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
220681ad6265SDimitry Andric#endif
220761cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 vector(vector&& __v, const __type_identity_t<allocator_type>& __a);
220861cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
220981ad6265SDimitry Andric    vector& operator=(vector&& __v)
221081ad6265SDimitry Andric        _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
221181ad6265SDimitry Andric
22120b57cec5SDimitry Andric    template <class _InputIterator>
2213753f127fSDimitry Andric        typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
22140b57cec5SDimitry Andric           void
22150b57cec5SDimitry Andric        >::type
221661cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 assign(_InputIterator __first, _InputIterator __last);
22170b57cec5SDimitry Andric    template <class _ForwardIterator>
22180b57cec5SDimitry Andric        typename enable_if
22190b57cec5SDimitry Andric        <
2220480093f4SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value,
22210b57cec5SDimitry Andric           void
22220b57cec5SDimitry Andric        >::type
222361cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 assign(_ForwardIterator __first, _ForwardIterator __last);
22240b57cec5SDimitry Andric
222561cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void assign(size_type __n, const value_type& __x);
22260b57cec5SDimitry Andric
22270b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
222861cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22290b57cec5SDimitry Andric    void assign(initializer_list<value_type> __il)
22300b57cec5SDimitry Andric        {assign(__il.begin(), __il.end());}
22310b57cec5SDimitry Andric#endif
22320b57cec5SDimitry Andric
223361cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 allocator_type get_allocator() const _NOEXCEPT
22340b57cec5SDimitry Andric        {return allocator_type(this->__alloc());}
22350b57cec5SDimitry Andric
223661cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type max_size() const _NOEXCEPT;
223761cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22380b57cec5SDimitry Andric    size_type capacity() const _NOEXCEPT
22390b57cec5SDimitry Andric        {return __internal_cap_to_external(__cap());}
224061cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22410b57cec5SDimitry Andric    size_type size() const _NOEXCEPT
22420b57cec5SDimitry Andric        {return __size_;}
224361cfbce3SDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22440b57cec5SDimitry Andric    bool empty() const _NOEXCEPT
22450b57cec5SDimitry Andric        {return __size_ == 0;}
224661cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void reserve(size_type __n);
224761cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void shrink_to_fit() _NOEXCEPT;
22480b57cec5SDimitry Andric
224961cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22500b57cec5SDimitry Andric    iterator begin() _NOEXCEPT
22510b57cec5SDimitry Andric        {return __make_iter(0);}
225261cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22530b57cec5SDimitry Andric    const_iterator begin() const _NOEXCEPT
22540b57cec5SDimitry Andric        {return __make_iter(0);}
225561cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22560b57cec5SDimitry Andric    iterator end() _NOEXCEPT
22570b57cec5SDimitry Andric        {return __make_iter(__size_);}
225861cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22590b57cec5SDimitry Andric    const_iterator end()   const _NOEXCEPT
22600b57cec5SDimitry Andric        {return __make_iter(__size_);}
22610b57cec5SDimitry Andric
226261cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22630b57cec5SDimitry Andric    reverse_iterator rbegin() _NOEXCEPT
22640b57cec5SDimitry Andric        {return       reverse_iterator(end());}
226561cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22660b57cec5SDimitry Andric    const_reverse_iterator rbegin() const _NOEXCEPT
22670b57cec5SDimitry Andric        {return const_reverse_iterator(end());}
226861cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22690b57cec5SDimitry Andric    reverse_iterator rend() _NOEXCEPT
22700b57cec5SDimitry Andric        {return       reverse_iterator(begin());}
227161cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22720b57cec5SDimitry Andric    const_reverse_iterator rend()   const _NOEXCEPT
22730b57cec5SDimitry Andric        {return const_reverse_iterator(begin());}
22740b57cec5SDimitry Andric
227561cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22760b57cec5SDimitry Andric    const_iterator         cbegin()  const _NOEXCEPT
22770b57cec5SDimitry Andric        {return __make_iter(0);}
227861cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22790b57cec5SDimitry Andric    const_iterator         cend()    const _NOEXCEPT
22800b57cec5SDimitry Andric        {return __make_iter(__size_);}
228161cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22820b57cec5SDimitry Andric    const_reverse_iterator crbegin() const _NOEXCEPT
22830b57cec5SDimitry Andric        {return rbegin();}
228461cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
22850b57cec5SDimitry Andric    const_reverse_iterator crend()   const _NOEXCEPT
22860b57cec5SDimitry Andric        {return rend();}
22870b57cec5SDimitry Andric
228861cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 reference       operator[](size_type __n)       {return __make_ref(__n);}
228961cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference operator[](size_type __n) const {return __make_ref(__n);}
22900b57cec5SDimitry Andric    reference       at(size_type __n);
22910b57cec5SDimitry Andric    const_reference at(size_type __n) const;
22920b57cec5SDimitry Andric
229361cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 reference       front()       {return __make_ref(0);}
229461cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference front() const {return __make_ref(0);}
229561cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 reference       back()        {return __make_ref(__size_ - 1);}
229661cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference back()  const {return __make_ref(__size_ - 1);}
22970b57cec5SDimitry Andric
229861cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void push_back(const value_type& __x);
22990b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
23000b57cec5SDimitry Andric    template <class... _Args>
23010b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
230261cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 reference emplace_back(_Args&&... __args)
23030b57cec5SDimitry Andric#else
23040b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void      emplace_back(_Args&&... __args)
23050b57cec5SDimitry Andric#endif
23060b57cec5SDimitry Andric    {
23070b57cec5SDimitry Andric        push_back ( value_type ( _VSTD::forward<_Args>(__args)... ));
23080b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
23090b57cec5SDimitry Andric        return this->back();
23100b57cec5SDimitry Andric#endif
23110b57cec5SDimitry Andric    }
23120b57cec5SDimitry Andric#endif
23130b57cec5SDimitry Andric
231461cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void pop_back() {--__size_;}
23150b57cec5SDimitry Andric
23160b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
23170b57cec5SDimitry Andric    template <class... _Args>
231861cfbce3SDimitry Andric   _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator emplace(const_iterator __position, _Args&&... __args)
2319753f127fSDimitry Andric        { return insert ( __position, value_type ( _VSTD::forward<_Args>(__args)... )); }
23200b57cec5SDimitry Andric#endif
23210b57cec5SDimitry Andric
232261cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator insert(const_iterator __position, const value_type& __x);
232361cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator insert(const_iterator __position, size_type __n, const value_type& __x);
23240b57cec5SDimitry Andric    template <class _InputIterator>
2325753f127fSDimitry Andric        typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
23260b57cec5SDimitry Andric            iterator
23270b57cec5SDimitry Andric        >::type
232861cfbce3SDimitry Andric        _LIBCPP_CONSTEXPR_AFTER_CXX17 insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
23290b57cec5SDimitry Andric    template <class _ForwardIterator>
23300b57cec5SDimitry Andric        typename enable_if
23310b57cec5SDimitry Andric        <
2332480093f4SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value,
23330b57cec5SDimitry Andric            iterator
23340b57cec5SDimitry Andric        >::type
233561cfbce3SDimitry Andric        _LIBCPP_CONSTEXPR_AFTER_CXX17 insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
23360b57cec5SDimitry Andric
23370b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
233861cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
23390b57cec5SDimitry Andric    iterator insert(const_iterator __position, initializer_list<value_type> __il)
23400b57cec5SDimitry Andric        {return insert(__position, __il.begin(), __il.end());}
23410b57cec5SDimitry Andric#endif
23420b57cec5SDimitry Andric
234361cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator erase(const_iterator __position);
234461cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator erase(const_iterator __first, const_iterator __last);
23450b57cec5SDimitry Andric
234661cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
23470b57cec5SDimitry Andric    void clear() _NOEXCEPT {__size_ = 0;}
23480b57cec5SDimitry Andric
234961cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void swap(vector&)
23500b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
23510b57cec5SDimitry Andric        _NOEXCEPT;
23520b57cec5SDimitry Andric#else
23530b57cec5SDimitry Andric        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
23540b57cec5SDimitry Andric                    __is_nothrow_swappable<allocator_type>::value);
23550b57cec5SDimitry Andric#endif
235661cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); }
23570b57cec5SDimitry Andric
235861cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void resize(size_type __sz, value_type __x = false);
235961cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void flip() _NOEXCEPT;
23600b57cec5SDimitry Andric
236161cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 bool __invariants() const;
23620b57cec5SDimitry Andric
23630b57cec5SDimitry Andricprivate:
2364d56accc7SDimitry Andric    _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
2365d56accc7SDimitry Andric    void __throw_length_error() const {
2366d56accc7SDimitry Andric        _VSTD::__throw_length_error("vector");
2367d56accc7SDimitry Andric    }
2368d56accc7SDimitry Andric
2369d56accc7SDimitry Andric    _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
2370d56accc7SDimitry Andric    void __throw_out_of_range() const {
2371d56accc7SDimitry Andric        _VSTD::__throw_out_of_range("vector");
2372d56accc7SDimitry Andric    }
2373d56accc7SDimitry Andric
237481ad6265SDimitry Andric    //  Allocate space for __n objects
237581ad6265SDimitry Andric    //  throws length_error if __n > max_size()
237681ad6265SDimitry Andric    //  throws (probably bad_alloc) if memory run out
237781ad6265SDimitry Andric    //  Precondition:  __begin_ == __end_ == __cap() == 0
237881ad6265SDimitry Andric    //  Precondition:  __n > 0
237981ad6265SDimitry Andric    //  Postcondition:  capacity() >= __n
238081ad6265SDimitry Andric    //  Postcondition:  size() == 0
238161cfbce3SDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __vallocate(size_type __n) {
238281ad6265SDimitry Andric        if (__n > max_size())
238381ad6265SDimitry Andric            __throw_length_error();
238481ad6265SDimitry Andric        auto __allocation = std::__allocate_at_least(__alloc(), __external_cap_to_internal(__n));
238581ad6265SDimitry Andric        __begin_ = __allocation.ptr;
238681ad6265SDimitry Andric        __size_ = 0;
238781ad6265SDimitry Andric        __cap() = __allocation.count;
238861cfbce3SDimitry Andric        if (__libcpp_is_constant_evaluated()) {
238961cfbce3SDimitry Andric            for (size_type __i = 0; __i != __cap(); ++__i)
239061cfbce3SDimitry Andric                std::__construct_at(std::__to_address(__begin_) + __i);
239161cfbce3SDimitry Andric        }
239281ad6265SDimitry Andric    }
239381ad6265SDimitry Andric
239461cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void __vdeallocate() _NOEXCEPT;
239561cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
23960b57cec5SDimitry Andric    static size_type __align_it(size_type __new_size) _NOEXCEPT
239781ad6265SDimitry Andric        {return (__new_size + (__bits_per_word-1)) & ~((size_type)__bits_per_word-1);}
239861cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17  size_type __recommend(size_type __new_size) const;
239961cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void __construct_at_end(size_type __n, bool __x);
24000b57cec5SDimitry Andric    template <class _ForwardIterator>
24010b57cec5SDimitry Andric        typename enable_if
24020b57cec5SDimitry Andric        <
2403480093f4SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value,
24040b57cec5SDimitry Andric            void
24050b57cec5SDimitry Andric        >::type
240661cfbce3SDimitry Andric        _LIBCPP_CONSTEXPR_AFTER_CXX17 __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
240761cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void __append(size_type __n, const_reference __x);
240861cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
24090b57cec5SDimitry Andric    reference __make_ref(size_type __pos) _NOEXCEPT
24100b57cec5SDimitry Andric        {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
241161cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
241281ad6265SDimitry Andric    const_reference __make_ref(size_type __pos) const _NOEXCEPT {
241381ad6265SDimitry Andric        return __bit_const_reference<vector>(__begin_ + __pos / __bits_per_word,
241481ad6265SDimitry Andric                                             __storage_type(1) << __pos % __bits_per_word);
241581ad6265SDimitry Andric    }
241661cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
24170b57cec5SDimitry Andric    iterator __make_iter(size_type __pos) _NOEXCEPT
24180b57cec5SDimitry Andric        {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
241961cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
24200b57cec5SDimitry Andric    const_iterator __make_iter(size_type __pos) const _NOEXCEPT
24210b57cec5SDimitry Andric        {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
242261cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
24230b57cec5SDimitry Andric    iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
24240b57cec5SDimitry Andric        {return begin() + (__p - cbegin());}
24250b57cec5SDimitry Andric
242661cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
24270b57cec5SDimitry Andric    void __copy_assign_alloc(const vector& __v)
24280b57cec5SDimitry Andric        {__copy_assign_alloc(__v, integral_constant<bool,
24290b57cec5SDimitry Andric                      __storage_traits::propagate_on_container_copy_assignment::value>());}
243061cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
24310b57cec5SDimitry Andric    void __copy_assign_alloc(const vector& __c, true_type)
24320b57cec5SDimitry Andric        {
24330b57cec5SDimitry Andric            if (__alloc() != __c.__alloc())
24340b57cec5SDimitry Andric                __vdeallocate();
24350b57cec5SDimitry Andric            __alloc() = __c.__alloc();
24360b57cec5SDimitry Andric        }
24370b57cec5SDimitry Andric
243861cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
24390b57cec5SDimitry Andric    void __copy_assign_alloc(const vector&, false_type)
24400b57cec5SDimitry Andric        {}
24410b57cec5SDimitry Andric
244261cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void __move_assign(vector& __c, false_type);
244361cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 void __move_assign(vector& __c, true_type)
24440b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
244561cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
24460b57cec5SDimitry Andric    void __move_assign_alloc(vector& __c)
24470b57cec5SDimitry Andric        _NOEXCEPT_(
24480b57cec5SDimitry Andric            !__storage_traits::propagate_on_container_move_assignment::value ||
24490b57cec5SDimitry Andric            is_nothrow_move_assignable<allocator_type>::value)
24500b57cec5SDimitry Andric        {__move_assign_alloc(__c, integral_constant<bool,
24510b57cec5SDimitry Andric                      __storage_traits::propagate_on_container_move_assignment::value>());}
245261cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
24530b57cec5SDimitry Andric    void __move_assign_alloc(vector& __c, true_type)
24540b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
24550b57cec5SDimitry Andric        {
24560b57cec5SDimitry Andric            __alloc() = _VSTD::move(__c.__alloc());
24570b57cec5SDimitry Andric        }
24580b57cec5SDimitry Andric
245961cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
24600b57cec5SDimitry Andric    void __move_assign_alloc(vector&, false_type)
24610b57cec5SDimitry Andric        _NOEXCEPT
24620b57cec5SDimitry Andric        {}
24630b57cec5SDimitry Andric
246461cfbce3SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX17 size_t __hash_code() const _NOEXCEPT;
24650b57cec5SDimitry Andric
24660b57cec5SDimitry Andric    friend class __bit_reference<vector>;
24670b57cec5SDimitry Andric    friend class __bit_const_reference<vector>;
24680b57cec5SDimitry Andric    friend class __bit_iterator<vector, false>;
24690b57cec5SDimitry Andric    friend class __bit_iterator<vector, true>;
24700b57cec5SDimitry Andric    friend struct __bit_array<vector>;
24710b57cec5SDimitry Andric    friend struct _LIBCPP_TEMPLATE_VIS hash<vector>;
24720b57cec5SDimitry Andric};
24730b57cec5SDimitry Andric
24740b57cec5SDimitry Andrictemplate <class _Allocator>
247561cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 void
24760b57cec5SDimitry Andricvector<bool, _Allocator>::__vdeallocate() _NOEXCEPT
24770b57cec5SDimitry Andric{
24780b57cec5SDimitry Andric    if (this->__begin_ != nullptr)
24790b57cec5SDimitry Andric    {
24800b57cec5SDimitry Andric        __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
248181ad6265SDimitry Andric        std::__debug_db_invalidate_all(this);
24820b57cec5SDimitry Andric        this->__begin_ = nullptr;
24830b57cec5SDimitry Andric        this->__size_ = this->__cap() = 0;
24840b57cec5SDimitry Andric    }
24850b57cec5SDimitry Andric}
24860b57cec5SDimitry Andric
24870b57cec5SDimitry Andrictemplate <class _Allocator>
248861cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
24890b57cec5SDimitry Andrictypename vector<bool, _Allocator>::size_type
24900b57cec5SDimitry Andricvector<bool, _Allocator>::max_size() const _NOEXCEPT
24910b57cec5SDimitry Andric{
24920b57cec5SDimitry Andric    size_type __amax = __storage_traits::max_size(__alloc());
24930b57cec5SDimitry Andric    size_type __nmax = numeric_limits<size_type>::max() / 2;  // end() >= begin(), always
24940b57cec5SDimitry Andric    if (__nmax / __bits_per_word <= __amax)
24950b57cec5SDimitry Andric        return __nmax;
24960b57cec5SDimitry Andric    return __internal_cap_to_external(__amax);
24970b57cec5SDimitry Andric}
24980b57cec5SDimitry Andric
24990b57cec5SDimitry Andric//  Precondition:  __new_size > capacity()
25000b57cec5SDimitry Andrictemplate <class _Allocator>
250161cfbce3SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
25020b57cec5SDimitry Andrictypename vector<bool, _Allocator>::size_type
25030b57cec5SDimitry Andricvector<bool, _Allocator>::__recommend(size_type __new_size) const
25040b57cec5SDimitry Andric{
25050b57cec5SDimitry Andric    const size_type __ms = max_size();
25060b57cec5SDimitry Andric    if (__new_size > __ms)
25070b57cec5SDimitry Andric        this->__throw_length_error();
25080b57cec5SDimitry Andric    const size_type __cap = capacity();
25090b57cec5SDimitry Andric    if (__cap >= __ms / 2)
25100b57cec5SDimitry Andric        return __ms;
25110b57cec5SDimitry Andric    return _VSTD::max(2 * __cap, __align_it(__new_size));
25120b57cec5SDimitry Andric}
25130b57cec5SDimitry Andric
25140b57cec5SDimitry Andric//  Default constructs __n objects starting at __end_
25150b57cec5SDimitry Andric//  Precondition:  __n > 0
25160b57cec5SDimitry Andric//  Precondition:  size() + __n <= capacity()
25170b57cec5SDimitry Andric//  Postcondition:  size() == size() + __n
25180b57cec5SDimitry Andrictemplate <class _Allocator>
251961cfbce3SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
25200b57cec5SDimitry Andricvoid
25210b57cec5SDimitry Andricvector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
25220b57cec5SDimitry Andric{
25230b57cec5SDimitry Andric    size_type __old_size = this->__size_;
25240b57cec5SDimitry Andric    this->__size_ += __n;
25250b57cec5SDimitry Andric    if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word))
25260b57cec5SDimitry Andric    {
25270b57cec5SDimitry Andric        if (this->__size_ <= __bits_per_word)
25280b57cec5SDimitry Andric            this->__begin_[0] = __storage_type(0);
25290b57cec5SDimitry Andric        else
25300b57cec5SDimitry Andric            this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
25310b57cec5SDimitry Andric    }
25320b57cec5SDimitry Andric    _VSTD::fill_n(__make_iter(__old_size), __n, __x);
25330b57cec5SDimitry Andric}
25340b57cec5SDimitry Andric
25350b57cec5SDimitry Andrictemplate <class _Allocator>
25360b57cec5SDimitry Andrictemplate <class _ForwardIterator>
253761cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
25380b57cec5SDimitry Andrictypename enable_if
25390b57cec5SDimitry Andric<
2540480093f4SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value,
25410b57cec5SDimitry Andric    void
25420b57cec5SDimitry Andric>::type
25430b57cec5SDimitry Andricvector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
25440b57cec5SDimitry Andric{
25450b57cec5SDimitry Andric    size_type __old_size = this->__size_;
25460b57cec5SDimitry Andric    this->__size_ += _VSTD::distance(__first, __last);
25470b57cec5SDimitry Andric    if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word))
25480b57cec5SDimitry Andric    {
25490b57cec5SDimitry Andric        if (this->__size_ <= __bits_per_word)
25500b57cec5SDimitry Andric            this->__begin_[0] = __storage_type(0);
25510b57cec5SDimitry Andric        else
25520b57cec5SDimitry Andric            this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
25530b57cec5SDimitry Andric    }
25540b57cec5SDimitry Andric    _VSTD::copy(__first, __last, __make_iter(__old_size));
25550b57cec5SDimitry Andric}
25560b57cec5SDimitry Andric
25570b57cec5SDimitry Andrictemplate <class _Allocator>
255861cfbce3SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
25590b57cec5SDimitry Andricvector<bool, _Allocator>::vector()
25600b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
25610b57cec5SDimitry Andric    : __begin_(nullptr),
25620b57cec5SDimitry Andric      __size_(0),
2563480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
25640b57cec5SDimitry Andric{
25650b57cec5SDimitry Andric}
25660b57cec5SDimitry Andric
25670b57cec5SDimitry Andrictemplate <class _Allocator>
256861cfbce3SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
25690b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const allocator_type& __a)
25700b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
25710b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
25720b57cec5SDimitry Andric#else
25730b57cec5SDimitry Andric        _NOEXCEPT
25740b57cec5SDimitry Andric#endif
25750b57cec5SDimitry Andric    : __begin_(nullptr),
25760b57cec5SDimitry Andric      __size_(0),
25770b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
25780b57cec5SDimitry Andric{
25790b57cec5SDimitry Andric}
25800b57cec5SDimitry Andric
25810b57cec5SDimitry Andrictemplate <class _Allocator>
258261cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
25830b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n)
25840b57cec5SDimitry Andric    : __begin_(nullptr),
25850b57cec5SDimitry Andric      __size_(0),
2586480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
25870b57cec5SDimitry Andric{
25880b57cec5SDimitry Andric    if (__n > 0)
25890b57cec5SDimitry Andric    {
25900b57cec5SDimitry Andric        __vallocate(__n);
25910b57cec5SDimitry Andric        __construct_at_end(__n, false);
25920b57cec5SDimitry Andric    }
25930b57cec5SDimitry Andric}
25940b57cec5SDimitry Andric
25950b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
25960b57cec5SDimitry Andrictemplate <class _Allocator>
259761cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
25980b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
25990b57cec5SDimitry Andric    : __begin_(nullptr),
26000b57cec5SDimitry Andric      __size_(0),
26010b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
26020b57cec5SDimitry Andric{
26030b57cec5SDimitry Andric    if (__n > 0)
26040b57cec5SDimitry Andric    {
26050b57cec5SDimitry Andric        __vallocate(__n);
26060b57cec5SDimitry Andric        __construct_at_end(__n, false);
26070b57cec5SDimitry Andric    }
26080b57cec5SDimitry Andric}
26090b57cec5SDimitry Andric#endif
26100b57cec5SDimitry Andric
26110b57cec5SDimitry Andrictemplate <class _Allocator>
261261cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
26130b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
26140b57cec5SDimitry Andric    : __begin_(nullptr),
26150b57cec5SDimitry Andric      __size_(0),
2616480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
26170b57cec5SDimitry Andric{
26180b57cec5SDimitry Andric    if (__n > 0)
26190b57cec5SDimitry Andric    {
26200b57cec5SDimitry Andric        __vallocate(__n);
26210b57cec5SDimitry Andric        __construct_at_end(__n, __x);
26220b57cec5SDimitry Andric    }
26230b57cec5SDimitry Andric}
26240b57cec5SDimitry Andric
26250b57cec5SDimitry Andrictemplate <class _Allocator>
262661cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
26270b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
26280b57cec5SDimitry Andric    : __begin_(nullptr),
26290b57cec5SDimitry Andric      __size_(0),
26300b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
26310b57cec5SDimitry Andric{
26320b57cec5SDimitry Andric    if (__n > 0)
26330b57cec5SDimitry Andric    {
26340b57cec5SDimitry Andric        __vallocate(__n);
26350b57cec5SDimitry Andric        __construct_at_end(__n, __x);
26360b57cec5SDimitry Andric    }
26370b57cec5SDimitry Andric}
26380b57cec5SDimitry Andric
26390b57cec5SDimitry Andrictemplate <class _Allocator>
26400b57cec5SDimitry Andrictemplate <class _InputIterator>
264161cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
26420b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2643753f127fSDimitry Andric       typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type*)
26440b57cec5SDimitry Andric    : __begin_(nullptr),
26450b57cec5SDimitry Andric      __size_(0),
2646480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
26470b57cec5SDimitry Andric{
26480b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
26490b57cec5SDimitry Andric    try
26500b57cec5SDimitry Andric    {
26510b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
26520b57cec5SDimitry Andric        for (; __first != __last; ++__first)
26530b57cec5SDimitry Andric            push_back(*__first);
26540b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
26550b57cec5SDimitry Andric    }
26560b57cec5SDimitry Andric    catch (...)
26570b57cec5SDimitry Andric    {
26580b57cec5SDimitry Andric        if (__begin_ != nullptr)
26590b57cec5SDimitry Andric            __storage_traits::deallocate(__alloc(), __begin_, __cap());
266081ad6265SDimitry Andric        std::__debug_db_invalidate_all(this);
26610b57cec5SDimitry Andric        throw;
26620b57cec5SDimitry Andric    }
26630b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
26640b57cec5SDimitry Andric}
26650b57cec5SDimitry Andric
26660b57cec5SDimitry Andrictemplate <class _Allocator>
26670b57cec5SDimitry Andrictemplate <class _InputIterator>
266861cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
26690b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2670753f127fSDimitry Andric       typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type*)
26710b57cec5SDimitry Andric    : __begin_(nullptr),
26720b57cec5SDimitry Andric      __size_(0),
26730b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
26740b57cec5SDimitry Andric{
26750b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
26760b57cec5SDimitry Andric    try
26770b57cec5SDimitry Andric    {
26780b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
26790b57cec5SDimitry Andric        for (; __first != __last; ++__first)
26800b57cec5SDimitry Andric            push_back(*__first);
26810b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
26820b57cec5SDimitry Andric    }
26830b57cec5SDimitry Andric    catch (...)
26840b57cec5SDimitry Andric    {
26850b57cec5SDimitry Andric        if (__begin_ != nullptr)
26860b57cec5SDimitry Andric            __storage_traits::deallocate(__alloc(), __begin_, __cap());
268781ad6265SDimitry Andric        std::__debug_db_invalidate_all(this);
26880b57cec5SDimitry Andric        throw;
26890b57cec5SDimitry Andric    }
26900b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
26910b57cec5SDimitry Andric}
26920b57cec5SDimitry Andric
26930b57cec5SDimitry Andrictemplate <class _Allocator>
26940b57cec5SDimitry Andrictemplate <class _ForwardIterator>
269561cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
26960b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2697480093f4SDimitry Andric                                typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*)
26980b57cec5SDimitry Andric    : __begin_(nullptr),
26990b57cec5SDimitry Andric      __size_(0),
2700480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
27010b57cec5SDimitry Andric{
2702*50d7464cSDimitry Andric    auto __guard = std::__make_transaction(__destroy_vector(*this));
2703*50d7464cSDimitry Andric    size_type __n = static_cast<size_type>(std::distance(__first, __last));
27040b57cec5SDimitry Andric    if (__n > 0)
27050b57cec5SDimitry Andric    {
27060b57cec5SDimitry Andric        __vallocate(__n);
27070b57cec5SDimitry Andric        __construct_at_end(__first, __last);
27080b57cec5SDimitry Andric    }
2709*50d7464cSDimitry Andric    __guard.__complete();
27100b57cec5SDimitry Andric}
27110b57cec5SDimitry Andric
27120b57cec5SDimitry Andrictemplate <class _Allocator>
27130b57cec5SDimitry Andrictemplate <class _ForwardIterator>
271461cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
27150b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2716480093f4SDimitry Andric                                typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*)
27170b57cec5SDimitry Andric    : __begin_(nullptr),
27180b57cec5SDimitry Andric      __size_(0),
27190b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
27200b57cec5SDimitry Andric{
2721*50d7464cSDimitry Andric    auto __guard = std::__make_transaction(__destroy_vector(*this));
2722*50d7464cSDimitry Andric    size_type __n = static_cast<size_type>(std::distance(__first, __last));
27230b57cec5SDimitry Andric    if (__n > 0)
27240b57cec5SDimitry Andric    {
27250b57cec5SDimitry Andric        __vallocate(__n);
27260b57cec5SDimitry Andric        __construct_at_end(__first, __last);
27270b57cec5SDimitry Andric    }
2728*50d7464cSDimitry Andric    __guard.__complete();
27290b57cec5SDimitry Andric}
27300b57cec5SDimitry Andric
27310b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
27320b57cec5SDimitry Andric
27330b57cec5SDimitry Andrictemplate <class _Allocator>
273461cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
27350b57cec5SDimitry Andricvector<bool, _Allocator>::vector(initializer_list<value_type> __il)
27360b57cec5SDimitry Andric    : __begin_(nullptr),
27370b57cec5SDimitry Andric      __size_(0),
2738480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
27390b57cec5SDimitry Andric{
27400b57cec5SDimitry Andric    size_type __n = static_cast<size_type>(__il.size());
27410b57cec5SDimitry Andric    if (__n > 0)
27420b57cec5SDimitry Andric    {
27430b57cec5SDimitry Andric        __vallocate(__n);
27440b57cec5SDimitry Andric        __construct_at_end(__il.begin(), __il.end());
27450b57cec5SDimitry Andric    }
27460b57cec5SDimitry Andric}
27470b57cec5SDimitry Andric
27480b57cec5SDimitry Andrictemplate <class _Allocator>
274961cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
27500b57cec5SDimitry Andricvector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
27510b57cec5SDimitry Andric    : __begin_(nullptr),
27520b57cec5SDimitry Andric      __size_(0),
27530b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
27540b57cec5SDimitry Andric{
27550b57cec5SDimitry Andric    size_type __n = static_cast<size_type>(__il.size());
27560b57cec5SDimitry Andric    if (__n > 0)
27570b57cec5SDimitry Andric    {
27580b57cec5SDimitry Andric        __vallocate(__n);
27590b57cec5SDimitry Andric        __construct_at_end(__il.begin(), __il.end());
27600b57cec5SDimitry Andric    }
27610b57cec5SDimitry Andric}
27620b57cec5SDimitry Andric
27630b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
27640b57cec5SDimitry Andric
27650b57cec5SDimitry Andrictemplate <class _Allocator>
276661cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
27670b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const vector& __v)
27680b57cec5SDimitry Andric    : __begin_(nullptr),
27690b57cec5SDimitry Andric      __size_(0),
27700b57cec5SDimitry Andric      __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
27710b57cec5SDimitry Andric{
27720b57cec5SDimitry Andric    if (__v.size() > 0)
27730b57cec5SDimitry Andric    {
27740b57cec5SDimitry Andric        __vallocate(__v.size());
27750b57cec5SDimitry Andric        __construct_at_end(__v.begin(), __v.end());
27760b57cec5SDimitry Andric    }
27770b57cec5SDimitry Andric}
27780b57cec5SDimitry Andric
27790b57cec5SDimitry Andrictemplate <class _Allocator>
278061cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
27810b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
27820b57cec5SDimitry Andric    : __begin_(nullptr),
27830b57cec5SDimitry Andric      __size_(0),
27840b57cec5SDimitry Andric      __cap_alloc_(0, __a)
27850b57cec5SDimitry Andric{
27860b57cec5SDimitry Andric    if (__v.size() > 0)
27870b57cec5SDimitry Andric    {
27880b57cec5SDimitry Andric        __vallocate(__v.size());
27890b57cec5SDimitry Andric        __construct_at_end(__v.begin(), __v.end());
27900b57cec5SDimitry Andric    }
27910b57cec5SDimitry Andric}
27920b57cec5SDimitry Andric
27930b57cec5SDimitry Andrictemplate <class _Allocator>
279461cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
27950b57cec5SDimitry Andricvector<bool, _Allocator>&
27960b57cec5SDimitry Andricvector<bool, _Allocator>::operator=(const vector& __v)
27970b57cec5SDimitry Andric{
2798349cc55cSDimitry Andric    if (this != _VSTD::addressof(__v))
27990b57cec5SDimitry Andric    {
28000b57cec5SDimitry Andric        __copy_assign_alloc(__v);
28010b57cec5SDimitry Andric        if (__v.__size_)
28020b57cec5SDimitry Andric        {
28030b57cec5SDimitry Andric            if (__v.__size_ > capacity())
28040b57cec5SDimitry Andric            {
28050b57cec5SDimitry Andric                __vdeallocate();
28060b57cec5SDimitry Andric                __vallocate(__v.__size_);
28070b57cec5SDimitry Andric            }
28080b57cec5SDimitry Andric            _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
28090b57cec5SDimitry Andric        }
28100b57cec5SDimitry Andric        __size_ = __v.__size_;
28110b57cec5SDimitry Andric    }
28120b57cec5SDimitry Andric    return *this;
28130b57cec5SDimitry Andric}
28140b57cec5SDimitry Andric
28150b57cec5SDimitry Andrictemplate <class _Allocator>
281661cfbce3SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 vector<bool, _Allocator>::vector(vector&& __v)
28170b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
28180b57cec5SDimitry Andric    _NOEXCEPT
28190b57cec5SDimitry Andric#else
28200b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
28210b57cec5SDimitry Andric#endif
28220b57cec5SDimitry Andric    : __begin_(__v.__begin_),
28230b57cec5SDimitry Andric      __size_(__v.__size_),
2824e8d8bef9SDimitry Andric      __cap_alloc_(_VSTD::move(__v.__cap_alloc_)) {
28250b57cec5SDimitry Andric    __v.__begin_ = nullptr;
28260b57cec5SDimitry Andric    __v.__size_ = 0;
28270b57cec5SDimitry Andric    __v.__cap() = 0;
28280b57cec5SDimitry Andric}
28290b57cec5SDimitry Andric
28300b57cec5SDimitry Andrictemplate <class _Allocator>
283161cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
283281ad6265SDimitry Andricvector<bool, _Allocator>::vector(vector&& __v, const __type_identity_t<allocator_type>& __a)
28330b57cec5SDimitry Andric    : __begin_(nullptr),
28340b57cec5SDimitry Andric      __size_(0),
28350b57cec5SDimitry Andric      __cap_alloc_(0, __a)
28360b57cec5SDimitry Andric{
28370b57cec5SDimitry Andric    if (__a == allocator_type(__v.__alloc()))
28380b57cec5SDimitry Andric    {
28390b57cec5SDimitry Andric        this->__begin_ = __v.__begin_;
28400b57cec5SDimitry Andric        this->__size_ = __v.__size_;
28410b57cec5SDimitry Andric        this->__cap() = __v.__cap();
28420b57cec5SDimitry Andric        __v.__begin_ = nullptr;
28430b57cec5SDimitry Andric        __v.__cap() = __v.__size_ = 0;
28440b57cec5SDimitry Andric    }
28450b57cec5SDimitry Andric    else if (__v.size() > 0)
28460b57cec5SDimitry Andric    {
28470b57cec5SDimitry Andric        __vallocate(__v.size());
28480b57cec5SDimitry Andric        __construct_at_end(__v.begin(), __v.end());
28490b57cec5SDimitry Andric    }
28500b57cec5SDimitry Andric}
28510b57cec5SDimitry Andric
28520b57cec5SDimitry Andrictemplate <class _Allocator>
285361cfbce3SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
28540b57cec5SDimitry Andricvector<bool, _Allocator>&
28550b57cec5SDimitry Andricvector<bool, _Allocator>::operator=(vector&& __v)
28560b57cec5SDimitry Andric    _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
28570b57cec5SDimitry Andric{
28580b57cec5SDimitry Andric    __move_assign(__v, integral_constant<bool,
28590b57cec5SDimitry Andric          __storage_traits::propagate_on_container_move_assignment::value>());
28600b57cec5SDimitry Andric    return *this;
28610b57cec5SDimitry Andric}
28620b57cec5SDimitry Andric
28630b57cec5SDimitry Andrictemplate <class _Allocator>
286461cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 void
28650b57cec5SDimitry Andricvector<bool, _Allocator>::__move_assign(vector& __c, false_type)
28660b57cec5SDimitry Andric{
28670b57cec5SDimitry Andric    if (__alloc() != __c.__alloc())
28680b57cec5SDimitry Andric        assign(__c.begin(), __c.end());
28690b57cec5SDimitry Andric    else
28700b57cec5SDimitry Andric        __move_assign(__c, true_type());
28710b57cec5SDimitry Andric}
28720b57cec5SDimitry Andric
28730b57cec5SDimitry Andrictemplate <class _Allocator>
287461cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 void
28750b57cec5SDimitry Andricvector<bool, _Allocator>::__move_assign(vector& __c, true_type)
28760b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
28770b57cec5SDimitry Andric{
28780b57cec5SDimitry Andric    __vdeallocate();
28790b57cec5SDimitry Andric    __move_assign_alloc(__c);
28800b57cec5SDimitry Andric    this->__begin_ = __c.__begin_;
28810b57cec5SDimitry Andric    this->__size_ = __c.__size_;
28820b57cec5SDimitry Andric    this->__cap() = __c.__cap();
28830b57cec5SDimitry Andric    __c.__begin_ = nullptr;
28840b57cec5SDimitry Andric    __c.__cap() = __c.__size_ = 0;
28850b57cec5SDimitry Andric}
28860b57cec5SDimitry Andric
28870b57cec5SDimitry Andrictemplate <class _Allocator>
288861cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 void
28890b57cec5SDimitry Andricvector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
28900b57cec5SDimitry Andric{
28910b57cec5SDimitry Andric    __size_ = 0;
28920b57cec5SDimitry Andric    if (__n > 0)
28930b57cec5SDimitry Andric    {
28940b57cec5SDimitry Andric        size_type __c = capacity();
28950b57cec5SDimitry Andric        if (__n <= __c)
28960b57cec5SDimitry Andric            __size_ = __n;
28970b57cec5SDimitry Andric        else
28980b57cec5SDimitry Andric        {
2899349cc55cSDimitry Andric            vector __v(get_allocator());
29000b57cec5SDimitry Andric            __v.reserve(__recommend(__n));
29010b57cec5SDimitry Andric            __v.__size_ = __n;
29020b57cec5SDimitry Andric            swap(__v);
29030b57cec5SDimitry Andric        }
29040b57cec5SDimitry Andric        _VSTD::fill_n(begin(), __n, __x);
29050b57cec5SDimitry Andric    }
290681ad6265SDimitry Andric    std::__debug_db_invalidate_all(this);
29070b57cec5SDimitry Andric}
29080b57cec5SDimitry Andric
29090b57cec5SDimitry Andrictemplate <class _Allocator>
29100b57cec5SDimitry Andrictemplate <class _InputIterator>
291161cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
29120b57cec5SDimitry Andric   void
29130b57cec5SDimitry Andric>::type
29140b57cec5SDimitry Andricvector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
29150b57cec5SDimitry Andric{
29160b57cec5SDimitry Andric    clear();
29170b57cec5SDimitry Andric    for (; __first != __last; ++__first)
29180b57cec5SDimitry Andric        push_back(*__first);
29190b57cec5SDimitry Andric}
29200b57cec5SDimitry Andric
29210b57cec5SDimitry Andrictemplate <class _Allocator>
29220b57cec5SDimitry Andrictemplate <class _ForwardIterator>
292361cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
29240b57cec5SDimitry Andrictypename enable_if
29250b57cec5SDimitry Andric<
2926480093f4SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value,
29270b57cec5SDimitry Andric   void
29280b57cec5SDimitry Andric>::type
29290b57cec5SDimitry Andricvector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
29300b57cec5SDimitry Andric{
29310b57cec5SDimitry Andric    clear();
29320b57cec5SDimitry Andric    difference_type __ns = _VSTD::distance(__first, __last);
29330b57cec5SDimitry Andric    _LIBCPP_ASSERT(__ns >= 0, "invalid range specified");
29340b57cec5SDimitry Andric    const size_t __n = static_cast<size_type>(__ns);
29350b57cec5SDimitry Andric    if (__n)
29360b57cec5SDimitry Andric    {
29370b57cec5SDimitry Andric        if (__n > capacity())
29380b57cec5SDimitry Andric        {
29390b57cec5SDimitry Andric            __vdeallocate();
29400b57cec5SDimitry Andric            __vallocate(__n);
29410b57cec5SDimitry Andric        }
29420b57cec5SDimitry Andric        __construct_at_end(__first, __last);
29430b57cec5SDimitry Andric    }
29440b57cec5SDimitry Andric}
29450b57cec5SDimitry Andric
29460b57cec5SDimitry Andrictemplate <class _Allocator>
294761cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 void
29480b57cec5SDimitry Andricvector<bool, _Allocator>::reserve(size_type __n)
29490b57cec5SDimitry Andric{
29500b57cec5SDimitry Andric    if (__n > capacity())
29510b57cec5SDimitry Andric    {
2952349cc55cSDimitry Andric        if (__n > max_size())
2953349cc55cSDimitry Andric            this->__throw_length_error();
2954349cc55cSDimitry Andric        vector __v(this->get_allocator());
29550b57cec5SDimitry Andric        __v.__vallocate(__n);
29560b57cec5SDimitry Andric        __v.__construct_at_end(this->begin(), this->end());
29570b57cec5SDimitry Andric        swap(__v);
295881ad6265SDimitry Andric        std::__debug_db_invalidate_all(this);
29590b57cec5SDimitry Andric    }
29600b57cec5SDimitry Andric}
29610b57cec5SDimitry Andric
29620b57cec5SDimitry Andrictemplate <class _Allocator>
296361cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 void
29640b57cec5SDimitry Andricvector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
29650b57cec5SDimitry Andric{
29660b57cec5SDimitry Andric    if (__external_cap_to_internal(size()) > __cap())
29670b57cec5SDimitry Andric    {
29680b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
29690b57cec5SDimitry Andric        try
29700b57cec5SDimitry Andric        {
29710b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
29720b57cec5SDimitry Andric            vector(*this, allocator_type(__alloc())).swap(*this);
29730b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
29740b57cec5SDimitry Andric        }
29750b57cec5SDimitry Andric        catch (...)
29760b57cec5SDimitry Andric        {
29770b57cec5SDimitry Andric        }
29780b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
29790b57cec5SDimitry Andric    }
29800b57cec5SDimitry Andric}
29810b57cec5SDimitry Andric
29820b57cec5SDimitry Andrictemplate <class _Allocator>
29830b57cec5SDimitry Andrictypename vector<bool, _Allocator>::reference
29840b57cec5SDimitry Andricvector<bool, _Allocator>::at(size_type __n)
29850b57cec5SDimitry Andric{
29860b57cec5SDimitry Andric    if (__n >= size())
29870b57cec5SDimitry Andric        this->__throw_out_of_range();
29880b57cec5SDimitry Andric    return (*this)[__n];
29890b57cec5SDimitry Andric}
29900b57cec5SDimitry Andric
29910b57cec5SDimitry Andrictemplate <class _Allocator>
29920b57cec5SDimitry Andrictypename vector<bool, _Allocator>::const_reference
29930b57cec5SDimitry Andricvector<bool, _Allocator>::at(size_type __n) const
29940b57cec5SDimitry Andric{
29950b57cec5SDimitry Andric    if (__n >= size())
29960b57cec5SDimitry Andric        this->__throw_out_of_range();
29970b57cec5SDimitry Andric    return (*this)[__n];
29980b57cec5SDimitry Andric}
29990b57cec5SDimitry Andric
30000b57cec5SDimitry Andrictemplate <class _Allocator>
300161cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 void
30020b57cec5SDimitry Andricvector<bool, _Allocator>::push_back(const value_type& __x)
30030b57cec5SDimitry Andric{
30040b57cec5SDimitry Andric    if (this->__size_ == this->capacity())
30050b57cec5SDimitry Andric        reserve(__recommend(this->__size_ + 1));
30060b57cec5SDimitry Andric    ++this->__size_;
30070b57cec5SDimitry Andric    back() = __x;
30080b57cec5SDimitry Andric}
30090b57cec5SDimitry Andric
30100b57cec5SDimitry Andrictemplate <class _Allocator>
301161cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 typename vector<bool, _Allocator>::iterator
30120b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
30130b57cec5SDimitry Andric{
30140b57cec5SDimitry Andric    iterator __r;
30150b57cec5SDimitry Andric    if (size() < capacity())
30160b57cec5SDimitry Andric    {
30170b57cec5SDimitry Andric        const_iterator __old_end = end();
30180b57cec5SDimitry Andric        ++__size_;
30190b57cec5SDimitry Andric        _VSTD::copy_backward(__position, __old_end, end());
30200b57cec5SDimitry Andric        __r = __const_iterator_cast(__position);
30210b57cec5SDimitry Andric    }
30220b57cec5SDimitry Andric    else
30230b57cec5SDimitry Andric    {
3024349cc55cSDimitry Andric        vector __v(get_allocator());
30250b57cec5SDimitry Andric        __v.reserve(__recommend(__size_ + 1));
30260b57cec5SDimitry Andric        __v.__size_ = __size_ + 1;
30270b57cec5SDimitry Andric        __r = _VSTD::copy(cbegin(), __position, __v.begin());
30280b57cec5SDimitry Andric        _VSTD::copy_backward(__position, cend(), __v.end());
30290b57cec5SDimitry Andric        swap(__v);
30300b57cec5SDimitry Andric    }
30310b57cec5SDimitry Andric    *__r = __x;
30320b57cec5SDimitry Andric    return __r;
30330b57cec5SDimitry Andric}
30340b57cec5SDimitry Andric
30350b57cec5SDimitry Andrictemplate <class _Allocator>
303661cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 typename vector<bool, _Allocator>::iterator
30370b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
30380b57cec5SDimitry Andric{
30390b57cec5SDimitry Andric    iterator __r;
30400b57cec5SDimitry Andric    size_type __c = capacity();
30410b57cec5SDimitry Andric    if (__n <= __c && size() <= __c - __n)
30420b57cec5SDimitry Andric    {
30430b57cec5SDimitry Andric        const_iterator __old_end = end();
30440b57cec5SDimitry Andric        __size_ += __n;
30450b57cec5SDimitry Andric        _VSTD::copy_backward(__position, __old_end, end());
30460b57cec5SDimitry Andric        __r = __const_iterator_cast(__position);
30470b57cec5SDimitry Andric    }
30480b57cec5SDimitry Andric    else
30490b57cec5SDimitry Andric    {
3050349cc55cSDimitry Andric        vector __v(get_allocator());
30510b57cec5SDimitry Andric        __v.reserve(__recommend(__size_ + __n));
30520b57cec5SDimitry Andric        __v.__size_ = __size_ + __n;
30530b57cec5SDimitry Andric        __r = _VSTD::copy(cbegin(), __position, __v.begin());
30540b57cec5SDimitry Andric        _VSTD::copy_backward(__position, cend(), __v.end());
30550b57cec5SDimitry Andric        swap(__v);
30560b57cec5SDimitry Andric    }
30570b57cec5SDimitry Andric    _VSTD::fill_n(__r, __n, __x);
30580b57cec5SDimitry Andric    return __r;
30590b57cec5SDimitry Andric}
30600b57cec5SDimitry Andric
30610b57cec5SDimitry Andrictemplate <class _Allocator>
30620b57cec5SDimitry Andrictemplate <class _InputIterator>
306361cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
30640b57cec5SDimitry Andric    typename vector<bool, _Allocator>::iterator
30650b57cec5SDimitry Andric>::type
30660b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
30670b57cec5SDimitry Andric{
30680b57cec5SDimitry Andric    difference_type __off = __position - begin();
30690b57cec5SDimitry Andric    iterator __p = __const_iterator_cast(__position);
30700b57cec5SDimitry Andric    iterator __old_end = end();
30710b57cec5SDimitry Andric    for (; size() != capacity() && __first != __last; ++__first)
30720b57cec5SDimitry Andric    {
30730b57cec5SDimitry Andric        ++this->__size_;
30740b57cec5SDimitry Andric        back() = *__first;
30750b57cec5SDimitry Andric    }
3076349cc55cSDimitry Andric    vector __v(get_allocator());
30770b57cec5SDimitry Andric    if (__first != __last)
30780b57cec5SDimitry Andric    {
30790b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
30800b57cec5SDimitry Andric        try
30810b57cec5SDimitry Andric        {
30820b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
30830b57cec5SDimitry Andric            __v.assign(__first, __last);
30840b57cec5SDimitry Andric            difference_type __old_size = static_cast<difference_type>(__old_end - begin());
30850b57cec5SDimitry Andric            difference_type __old_p = __p - begin();
30860b57cec5SDimitry Andric            reserve(__recommend(size() + __v.size()));
30870b57cec5SDimitry Andric            __p = begin() + __old_p;
30880b57cec5SDimitry Andric            __old_end = begin() + __old_size;
30890b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
30900b57cec5SDimitry Andric        }
30910b57cec5SDimitry Andric        catch (...)
30920b57cec5SDimitry Andric        {
30930b57cec5SDimitry Andric            erase(__old_end, end());
30940b57cec5SDimitry Andric            throw;
30950b57cec5SDimitry Andric        }
30960b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
30970b57cec5SDimitry Andric    }
30980b57cec5SDimitry Andric    __p = _VSTD::rotate(__p, __old_end, end());
30990b57cec5SDimitry Andric    insert(__p, __v.begin(), __v.end());
31000b57cec5SDimitry Andric    return begin() + __off;
31010b57cec5SDimitry Andric}
31020b57cec5SDimitry Andric
31030b57cec5SDimitry Andrictemplate <class _Allocator>
31040b57cec5SDimitry Andrictemplate <class _ForwardIterator>
310561cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
31060b57cec5SDimitry Andrictypename enable_if
31070b57cec5SDimitry Andric<
3108480093f4SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value,
31090b57cec5SDimitry Andric    typename vector<bool, _Allocator>::iterator
31100b57cec5SDimitry Andric>::type
31110b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
31120b57cec5SDimitry Andric{
31130b57cec5SDimitry Andric    const difference_type __n_signed = _VSTD::distance(__first, __last);
31140b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n_signed >= 0, "invalid range specified");
31150b57cec5SDimitry Andric    const size_type __n = static_cast<size_type>(__n_signed);
31160b57cec5SDimitry Andric    iterator __r;
31170b57cec5SDimitry Andric    size_type __c = capacity();
31180b57cec5SDimitry Andric    if (__n <= __c && size() <= __c - __n)
31190b57cec5SDimitry Andric    {
31200b57cec5SDimitry Andric        const_iterator __old_end = end();
31210b57cec5SDimitry Andric        __size_ += __n;
31220b57cec5SDimitry Andric        _VSTD::copy_backward(__position, __old_end, end());
31230b57cec5SDimitry Andric        __r = __const_iterator_cast(__position);
31240b57cec5SDimitry Andric    }
31250b57cec5SDimitry Andric    else
31260b57cec5SDimitry Andric    {
3127349cc55cSDimitry Andric        vector __v(get_allocator());
31280b57cec5SDimitry Andric        __v.reserve(__recommend(__size_ + __n));
31290b57cec5SDimitry Andric        __v.__size_ = __size_ + __n;
31300b57cec5SDimitry Andric        __r = _VSTD::copy(cbegin(), __position, __v.begin());
31310b57cec5SDimitry Andric        _VSTD::copy_backward(__position, cend(), __v.end());
31320b57cec5SDimitry Andric        swap(__v);
31330b57cec5SDimitry Andric    }
31340b57cec5SDimitry Andric    _VSTD::copy(__first, __last, __r);
31350b57cec5SDimitry Andric    return __r;
31360b57cec5SDimitry Andric}
31370b57cec5SDimitry Andric
31380b57cec5SDimitry Andrictemplate <class _Allocator>
313961cfbce3SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
31400b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator
31410b57cec5SDimitry Andricvector<bool, _Allocator>::erase(const_iterator __position)
31420b57cec5SDimitry Andric{
31430b57cec5SDimitry Andric    iterator __r = __const_iterator_cast(__position);
31440b57cec5SDimitry Andric    _VSTD::copy(__position + 1, this->cend(), __r);
31450b57cec5SDimitry Andric    --__size_;
31460b57cec5SDimitry Andric    return __r;
31470b57cec5SDimitry Andric}
31480b57cec5SDimitry Andric
31490b57cec5SDimitry Andrictemplate <class _Allocator>
315061cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
31510b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator
31520b57cec5SDimitry Andricvector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
31530b57cec5SDimitry Andric{
31540b57cec5SDimitry Andric    iterator __r = __const_iterator_cast(__first);
31550b57cec5SDimitry Andric    difference_type __d = __last - __first;
31560b57cec5SDimitry Andric    _VSTD::copy(__last, this->cend(), __r);
31570b57cec5SDimitry Andric    __size_ -= __d;
31580b57cec5SDimitry Andric    return __r;
31590b57cec5SDimitry Andric}
31600b57cec5SDimitry Andric
31610b57cec5SDimitry Andrictemplate <class _Allocator>
316261cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 void
31630b57cec5SDimitry Andricvector<bool, _Allocator>::swap(vector& __x)
31640b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
31650b57cec5SDimitry Andric    _NOEXCEPT
31660b57cec5SDimitry Andric#else
31670b57cec5SDimitry Andric    _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
31680b57cec5SDimitry Andric                __is_nothrow_swappable<allocator_type>::value)
31690b57cec5SDimitry Andric#endif
31700b57cec5SDimitry Andric{
31710b57cec5SDimitry Andric    _VSTD::swap(this->__begin_, __x.__begin_);
31720b57cec5SDimitry Andric    _VSTD::swap(this->__size_, __x.__size_);
31730b57cec5SDimitry Andric    _VSTD::swap(this->__cap(), __x.__cap());
3174e8d8bef9SDimitry Andric    _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(),
31750b57cec5SDimitry Andric        integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
31760b57cec5SDimitry Andric}
31770b57cec5SDimitry Andric
31780b57cec5SDimitry Andrictemplate <class _Allocator>
317961cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 void
31800b57cec5SDimitry Andricvector<bool, _Allocator>::resize(size_type __sz, value_type __x)
31810b57cec5SDimitry Andric{
31820b57cec5SDimitry Andric    size_type __cs = size();
31830b57cec5SDimitry Andric    if (__cs < __sz)
31840b57cec5SDimitry Andric    {
31850b57cec5SDimitry Andric        iterator __r;
31860b57cec5SDimitry Andric        size_type __c = capacity();
31870b57cec5SDimitry Andric        size_type __n = __sz - __cs;
31880b57cec5SDimitry Andric        if (__n <= __c && __cs <= __c - __n)
31890b57cec5SDimitry Andric        {
31900b57cec5SDimitry Andric            __r = end();
31910b57cec5SDimitry Andric            __size_ += __n;
31920b57cec5SDimitry Andric        }
31930b57cec5SDimitry Andric        else
31940b57cec5SDimitry Andric        {
3195349cc55cSDimitry Andric            vector __v(get_allocator());
31960b57cec5SDimitry Andric            __v.reserve(__recommend(__size_ + __n));
31970b57cec5SDimitry Andric            __v.__size_ = __size_ + __n;
31980b57cec5SDimitry Andric            __r = _VSTD::copy(cbegin(), cend(), __v.begin());
31990b57cec5SDimitry Andric            swap(__v);
32000b57cec5SDimitry Andric        }
32010b57cec5SDimitry Andric        _VSTD::fill_n(__r, __n, __x);
32020b57cec5SDimitry Andric    }
32030b57cec5SDimitry Andric    else
32040b57cec5SDimitry Andric        __size_ = __sz;
32050b57cec5SDimitry Andric}
32060b57cec5SDimitry Andric
32070b57cec5SDimitry Andrictemplate <class _Allocator>
320861cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 void
32090b57cec5SDimitry Andricvector<bool, _Allocator>::flip() _NOEXCEPT
32100b57cec5SDimitry Andric{
32110b57cec5SDimitry Andric    // do middle whole words
32120b57cec5SDimitry Andric    size_type __n = __size_;
32130b57cec5SDimitry Andric    __storage_pointer __p = __begin_;
32140b57cec5SDimitry Andric    for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
32150b57cec5SDimitry Andric        *__p = ~*__p;
32160b57cec5SDimitry Andric    // do last partial word
32170b57cec5SDimitry Andric    if (__n > 0)
32180b57cec5SDimitry Andric    {
32190b57cec5SDimitry Andric        __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
32200b57cec5SDimitry Andric        __storage_type __b = *__p & __m;
32210b57cec5SDimitry Andric        *__p &= ~__m;
32220b57cec5SDimitry Andric        *__p |= ~__b & __m;
32230b57cec5SDimitry Andric    }
32240b57cec5SDimitry Andric}
32250b57cec5SDimitry Andric
32260b57cec5SDimitry Andrictemplate <class _Allocator>
322761cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
32280b57cec5SDimitry Andricvector<bool, _Allocator>::__invariants() const
32290b57cec5SDimitry Andric{
32300b57cec5SDimitry Andric    if (this->__begin_ == nullptr)
32310b57cec5SDimitry Andric    {
32320b57cec5SDimitry Andric        if (this->__size_ != 0 || this->__cap() != 0)
32330b57cec5SDimitry Andric            return false;
32340b57cec5SDimitry Andric    }
32350b57cec5SDimitry Andric    else
32360b57cec5SDimitry Andric    {
32370b57cec5SDimitry Andric        if (this->__cap() == 0)
32380b57cec5SDimitry Andric            return false;
32390b57cec5SDimitry Andric        if (this->__size_ > this->capacity())
32400b57cec5SDimitry Andric            return false;
32410b57cec5SDimitry Andric    }
32420b57cec5SDimitry Andric    return true;
32430b57cec5SDimitry Andric}
32440b57cec5SDimitry Andric
32450b57cec5SDimitry Andrictemplate <class _Allocator>
324661cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 size_t
32470b57cec5SDimitry Andricvector<bool, _Allocator>::__hash_code() const _NOEXCEPT
32480b57cec5SDimitry Andric{
32490b57cec5SDimitry Andric    size_t __h = 0;
32500b57cec5SDimitry Andric    // do middle whole words
32510b57cec5SDimitry Andric    size_type __n = __size_;
32520b57cec5SDimitry Andric    __storage_pointer __p = __begin_;
32530b57cec5SDimitry Andric    for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
32540b57cec5SDimitry Andric        __h ^= *__p;
32550b57cec5SDimitry Andric    // do last partial word
32560b57cec5SDimitry Andric    if (__n > 0)
32570b57cec5SDimitry Andric    {
32580b57cec5SDimitry Andric        const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
32590b57cec5SDimitry Andric        __h ^= *__p & __m;
32600b57cec5SDimitry Andric    }
32610b57cec5SDimitry Andric    return __h;
32620b57cec5SDimitry Andric}
32630b57cec5SDimitry Andric
32640b57cec5SDimitry Andrictemplate <class _Allocator>
32650b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
326681ad6265SDimitry Andric    : public __unary_function<vector<bool, _Allocator>, size_t>
32670b57cec5SDimitry Andric{
326861cfbce3SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
32690b57cec5SDimitry Andric    size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
32700b57cec5SDimitry Andric        {return __vec.__hash_code();}
32710b57cec5SDimitry Andric};
32720b57cec5SDimitry Andric
32730b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
327461cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
32750b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
32760b57cec5SDimitry Andricbool
32770b57cec5SDimitry Andricoperator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
32780b57cec5SDimitry Andric{
32790b57cec5SDimitry Andric    const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
32800b57cec5SDimitry Andric    return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
32810b57cec5SDimitry Andric}
32820b57cec5SDimitry Andric
32830b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
328461cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
32850b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
32860b57cec5SDimitry Andricbool
32870b57cec5SDimitry Andricoperator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
32880b57cec5SDimitry Andric{
32890b57cec5SDimitry Andric    return !(__x == __y);
32900b57cec5SDimitry Andric}
32910b57cec5SDimitry Andric
32920b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
329361cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
32940b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
32950b57cec5SDimitry Andricbool
32960b57cec5SDimitry Andricoperator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
32970b57cec5SDimitry Andric{
32980b57cec5SDimitry Andric    return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
32990b57cec5SDimitry Andric}
33000b57cec5SDimitry Andric
33010b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
330261cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
33030b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
33040b57cec5SDimitry Andricbool
33050b57cec5SDimitry Andricoperator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
33060b57cec5SDimitry Andric{
33070b57cec5SDimitry Andric    return __y < __x;
33080b57cec5SDimitry Andric}
33090b57cec5SDimitry Andric
33100b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
331161cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
33120b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
33130b57cec5SDimitry Andricbool
33140b57cec5SDimitry Andricoperator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
33150b57cec5SDimitry Andric{
33160b57cec5SDimitry Andric    return !(__x < __y);
33170b57cec5SDimitry Andric}
33180b57cec5SDimitry Andric
33190b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
332061cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
33210b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
33220b57cec5SDimitry Andricbool
33230b57cec5SDimitry Andricoperator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
33240b57cec5SDimitry Andric{
33250b57cec5SDimitry Andric    return !(__y < __x);
33260b57cec5SDimitry Andric}
33270b57cec5SDimitry Andric
33280b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
332961cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
33300b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
33310b57cec5SDimitry Andricvoid
33320b57cec5SDimitry Andricswap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
33330b57cec5SDimitry Andric    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
33340b57cec5SDimitry Andric{
33350b57cec5SDimitry Andric    __x.swap(__y);
33360b57cec5SDimitry Andric}
33370b57cec5SDimitry Andric
33380b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17
33390b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Up>
334061cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
33415ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type
33425ffd83dbSDimitry Andricerase(vector<_Tp, _Allocator>& __c, const _Up& __v) {
33435ffd83dbSDimitry Andric  auto __old_size = __c.size();
33445ffd83dbSDimitry Andric  __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end());
33455ffd83dbSDimitry Andric  return __old_size - __c.size();
33465ffd83dbSDimitry Andric}
33470b57cec5SDimitry Andric
33480b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Predicate>
334961cfbce3SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17
33505ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type
33515ffd83dbSDimitry Andricerase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) {
33525ffd83dbSDimitry Andric  auto __old_size = __c.size();
33535ffd83dbSDimitry Andric  __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end());
33545ffd83dbSDimitry Andric  return __old_size - __c.size();
33555ffd83dbSDimitry Andric}
335681ad6265SDimitry Andric
335781ad6265SDimitry Andrictemplate <>
335881ad6265SDimitry Andricinline constexpr bool __format::__enable_insertable<std::vector<char>> = true;
335981ad6265SDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
336081ad6265SDimitry Andrictemplate <>
336181ad6265SDimitry Andricinline constexpr bool __format::__enable_insertable<std::vector<wchar_t>> = true;
33620b57cec5SDimitry Andric#endif
33630b57cec5SDimitry Andric
336481ad6265SDimitry Andric#endif // _LIBCPP_STD_VER > 17
336581ad6265SDimitry Andric
33660b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
33670b57cec5SDimitry Andric
33680b57cec5SDimitry Andric_LIBCPP_POP_MACROS
33690b57cec5SDimitry Andric
33700b57cec5SDimitry Andric#endif // _LIBCPP_VECTOR
3371