xref: /freebsd/contrib/llvm-project/libcxx/include/vector (revision 972a253a57b6f144b0e4a3e2080a2a0076ec55a0)
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>
294*972a253aSDimitry Andric#include <__memory/pointer_traits.h>
295*972a253aSDimitry 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>
3000b57cec5SDimitry Andric#include <climits>
30169ade1e0SDimitry Andric#include <cstdlib>
302fe6060f1SDimitry Andric#include <cstring>
303fe6060f1SDimitry Andric#include <iosfwd> // for forward declaration of vector
304fe6060f1SDimitry Andric#include <limits>
3050b57cec5SDimitry Andric#include <memory>
3060b57cec5SDimitry Andric#include <stdexcept>
307fe6060f1SDimitry Andric#include <type_traits>
3080b57cec5SDimitry Andric#include <version>
3090b57cec5SDimitry Andric
31081ad6265SDimitry Andric#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES
31181ad6265SDimitry Andric#  include <algorithm>
31281ad6265SDimitry Andric#  include <typeinfo>
31381ad6265SDimitry Andric#  include <utility>
31481ad6265SDimitry Andric#endif
31581ad6265SDimitry Andric
31681ad6265SDimitry Andric// standard-mandated includes
31781ad6265SDimitry Andric
31881ad6265SDimitry Andric// [iterator.range]
31981ad6265SDimitry Andric#include <__iterator/access.h>
32081ad6265SDimitry Andric#include <__iterator/data.h>
32181ad6265SDimitry Andric#include <__iterator/empty.h>
32281ad6265SDimitry Andric#include <__iterator/reverse_access.h>
32381ad6265SDimitry Andric#include <__iterator/size.h>
32481ad6265SDimitry Andric
32581ad6265SDimitry Andric// [vector.syn]
32681ad6265SDimitry Andric#include <compare>
32781ad6265SDimitry Andric#include <initializer_list>
32881ad6265SDimitry Andric
3290b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3300b57cec5SDimitry Andric#  pragma GCC system_header
3310b57cec5SDimitry Andric#endif
3320b57cec5SDimitry Andric
3330b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS
3340b57cec5SDimitry Andric#include <__undef_macros>
3350b57cec5SDimitry Andric
3360b57cec5SDimitry Andric
3370b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
3380b57cec5SDimitry Andric
3390b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator /* = allocator<_Tp> */>
3400b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector
3410b57cec5SDimitry Andric{
3420b57cec5SDimitry Andricprivate:
3430b57cec5SDimitry Andric    typedef allocator<_Tp>                                  __default_allocator_type;
3440b57cec5SDimitry Andricpublic:
3450b57cec5SDimitry Andric    typedef vector                                          __self;
3460b57cec5SDimitry Andric    typedef _Tp                                             value_type;
3470b57cec5SDimitry Andric    typedef _Allocator                                      allocator_type;
348349cc55cSDimitry Andric    typedef allocator_traits<allocator_type>                __alloc_traits;
349349cc55cSDimitry Andric    typedef value_type&                                     reference;
350349cc55cSDimitry Andric    typedef const value_type&                               const_reference;
3514824e7fdSDimitry Andric    typedef typename __alloc_traits::size_type              size_type;
352349cc55cSDimitry Andric    typedef typename __alloc_traits::difference_type        difference_type;
353349cc55cSDimitry Andric    typedef typename __alloc_traits::pointer                pointer;
354349cc55cSDimitry Andric    typedef typename __alloc_traits::const_pointer          const_pointer;
3550b57cec5SDimitry Andric    typedef __wrap_iter<pointer>                            iterator;
3560b57cec5SDimitry Andric    typedef __wrap_iter<const_pointer>                      const_iterator;
3570b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<iterator>               reverse_iterator;
3580b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<const_iterator>         const_reverse_iterator;
3590b57cec5SDimitry Andric
3600b57cec5SDimitry Andric    static_assert((is_same<typename allocator_type::value_type, value_type>::value),
3610b57cec5SDimitry Andric                  "Allocator::value_type must be same type as value_type");
3620b57cec5SDimitry Andric
3630b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3640b57cec5SDimitry Andric    vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
3650b57cec5SDimitry Andric    {
36604eeddc0SDimitry Andric        _VSTD::__debug_db_insert_c(this);
3670b57cec5SDimitry Andric    }
3680b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
3690b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
3700b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
3710b57cec5SDimitry Andric#else
3720b57cec5SDimitry Andric        _NOEXCEPT
3730b57cec5SDimitry Andric#endif
374d56accc7SDimitry Andric        : __end_cap_(nullptr, __a)
3750b57cec5SDimitry Andric    {
37604eeddc0SDimitry Andric        _VSTD::__debug_db_insert_c(this);
3770b57cec5SDimitry Andric    }
3780b57cec5SDimitry Andric    explicit vector(size_type __n);
3790b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
3800b57cec5SDimitry Andric    explicit vector(size_type __n, const allocator_type& __a);
3810b57cec5SDimitry Andric#endif
3820b57cec5SDimitry Andric    vector(size_type __n, const value_type& __x);
3834824e7fdSDimitry Andric
3844824e7fdSDimitry Andric    template <class = __enable_if_t<__is_allocator<_Allocator>::value> >
3854824e7fdSDimitry Andric    vector(size_type __n, const value_type& __x, const allocator_type& __a)
386d56accc7SDimitry Andric        : __end_cap_(nullptr, __a)
3874824e7fdSDimitry Andric    {
38804eeddc0SDimitry Andric      _VSTD::__debug_db_insert_c(this);
3894824e7fdSDimitry Andric      if (__n > 0)
3904824e7fdSDimitry Andric      {
3914824e7fdSDimitry Andric          __vallocate(__n);
3924824e7fdSDimitry Andric          __construct_at_end(__n, __x);
3934824e7fdSDimitry Andric      }
3944824e7fdSDimitry Andric    }
3954824e7fdSDimitry Andric
3960b57cec5SDimitry Andric    template <class _InputIterator>
3970b57cec5SDimitry Andric        vector(_InputIterator __first,
398753f127fSDimitry Andric               typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
3990b57cec5SDimitry Andric                                 is_constructible<
4000b57cec5SDimitry Andric                                    value_type,
4010b57cec5SDimitry Andric                                    typename iterator_traits<_InputIterator>::reference>::value,
4020b57cec5SDimitry Andric                                 _InputIterator>::type __last);
4030b57cec5SDimitry Andric    template <class _InputIterator>
4040b57cec5SDimitry Andric        vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
405753f127fSDimitry Andric               typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
4060b57cec5SDimitry Andric                                 is_constructible<
4070b57cec5SDimitry Andric                                    value_type,
4080b57cec5SDimitry Andric                                    typename iterator_traits<_InputIterator>::reference>::value>::type* = 0);
4090b57cec5SDimitry Andric    template <class _ForwardIterator>
4100b57cec5SDimitry Andric        vector(_ForwardIterator __first,
411480093f4SDimitry Andric               typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
4120b57cec5SDimitry Andric                                 is_constructible<
4130b57cec5SDimitry Andric                                    value_type,
4140b57cec5SDimitry Andric                                    typename iterator_traits<_ForwardIterator>::reference>::value,
4150b57cec5SDimitry Andric                                 _ForwardIterator>::type __last);
4160b57cec5SDimitry Andric    template <class _ForwardIterator>
4170b57cec5SDimitry Andric        vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
418480093f4SDimitry Andric               typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
4190b57cec5SDimitry Andric                                 is_constructible<
4200b57cec5SDimitry Andric                                    value_type,
4210b57cec5SDimitry Andric                                    typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0);
4220b57cec5SDimitry Andric
4230b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4240b57cec5SDimitry Andric    ~vector()
4250b57cec5SDimitry Andric    {
4260b57cec5SDimitry Andric      __annotate_delete();
42781ad6265SDimitry Andric      std::__debug_db_erase_c(this);
428349cc55cSDimitry Andric
429349cc55cSDimitry Andric      if (this->__begin_ != nullptr)
430349cc55cSDimitry Andric      {
431349cc55cSDimitry Andric        __clear();
432349cc55cSDimitry Andric        __alloc_traits::deallocate(__alloc(), this->__begin_, capacity());
433349cc55cSDimitry Andric      }
4340b57cec5SDimitry Andric    }
4350b57cec5SDimitry Andric
4360b57cec5SDimitry Andric    vector(const vector& __x);
43781ad6265SDimitry Andric    vector(const vector& __x, const __type_identity_t<allocator_type>& __a);
4380b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4390b57cec5SDimitry Andric    vector& operator=(const vector& __x);
4400b57cec5SDimitry Andric
4410b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
4420b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4430b57cec5SDimitry Andric    vector(initializer_list<value_type> __il);
4440b57cec5SDimitry Andric
4450b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4460b57cec5SDimitry Andric    vector(initializer_list<value_type> __il, const allocator_type& __a);
4470b57cec5SDimitry Andric
4480b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
44981ad6265SDimitry Andric    vector& operator=(initializer_list<value_type> __il)
45081ad6265SDimitry Andric        {assign(__il.begin(), __il.end()); return *this;}
45181ad6265SDimitry Andric#endif // !_LIBCPP_CXX03_LANG
45281ad6265SDimitry Andric
45381ad6265SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4540b57cec5SDimitry Andric    vector(vector&& __x)
4550b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
45681ad6265SDimitry Andric        noexcept;
4570b57cec5SDimitry Andric#else
4580b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
4590b57cec5SDimitry Andric#endif
4600b57cec5SDimitry Andric
4610b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
46281ad6265SDimitry Andric    vector(vector&& __x, const __type_identity_t<allocator_type>& __a);
4630b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4640b57cec5SDimitry Andric    vector& operator=(vector&& __x)
4650b57cec5SDimitry Andric        _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
4660b57cec5SDimitry Andric
4670b57cec5SDimitry Andric    template <class _InputIterator>
468753f127fSDimitry Andric        typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
4690b57cec5SDimitry Andric            is_constructible<
4700b57cec5SDimitry Andric                 value_type,
4710b57cec5SDimitry Andric                 typename iterator_traits<_InputIterator>::reference>::value,
4720b57cec5SDimitry Andric            void
4730b57cec5SDimitry Andric        >::type
4740b57cec5SDimitry Andric        assign(_InputIterator __first, _InputIterator __last);
4750b57cec5SDimitry Andric    template <class _ForwardIterator>
4760b57cec5SDimitry Andric        typename enable_if
4770b57cec5SDimitry Andric        <
478480093f4SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value &&
4790b57cec5SDimitry Andric            is_constructible<
4800b57cec5SDimitry Andric                 value_type,
4810b57cec5SDimitry Andric                 typename iterator_traits<_ForwardIterator>::reference>::value,
4820b57cec5SDimitry Andric            void
4830b57cec5SDimitry Andric        >::type
4840b57cec5SDimitry Andric        assign(_ForwardIterator __first, _ForwardIterator __last);
4850b57cec5SDimitry Andric
4860b57cec5SDimitry Andric    void assign(size_type __n, const_reference __u);
4870b57cec5SDimitry Andric
4880b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
4890b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4900b57cec5SDimitry Andric    void assign(initializer_list<value_type> __il)
4910b57cec5SDimitry Andric        {assign(__il.begin(), __il.end());}
4920b57cec5SDimitry Andric#endif
4930b57cec5SDimitry Andric
4940b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4950b57cec5SDimitry Andric    allocator_type get_allocator() const _NOEXCEPT
4960b57cec5SDimitry Andric        {return this->__alloc();}
4970b57cec5SDimitry Andric
4980b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY iterator               begin() _NOEXCEPT;
4990b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const_iterator         begin()   const _NOEXCEPT;
5000b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY iterator               end() _NOEXCEPT;
5010b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const_iterator         end()     const _NOEXCEPT;
5020b57cec5SDimitry Andric
5030b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5040b57cec5SDimitry Andric    reverse_iterator       rbegin() _NOEXCEPT
5050b57cec5SDimitry Andric        {return       reverse_iterator(end());}
5060b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5070b57cec5SDimitry Andric    const_reverse_iterator rbegin()  const _NOEXCEPT
5080b57cec5SDimitry Andric        {return const_reverse_iterator(end());}
5090b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5100b57cec5SDimitry Andric    reverse_iterator       rend() _NOEXCEPT
5110b57cec5SDimitry Andric        {return       reverse_iterator(begin());}
5120b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5130b57cec5SDimitry Andric    const_reverse_iterator rend()    const _NOEXCEPT
5140b57cec5SDimitry Andric        {return const_reverse_iterator(begin());}
5150b57cec5SDimitry Andric
5160b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5170b57cec5SDimitry Andric    const_iterator         cbegin()  const _NOEXCEPT
5180b57cec5SDimitry Andric        {return begin();}
5190b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5200b57cec5SDimitry Andric    const_iterator         cend()    const _NOEXCEPT
5210b57cec5SDimitry Andric        {return end();}
5220b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5230b57cec5SDimitry Andric    const_reverse_iterator crbegin() const _NOEXCEPT
5240b57cec5SDimitry Andric        {return rbegin();}
5250b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5260b57cec5SDimitry Andric    const_reverse_iterator crend()   const _NOEXCEPT
5270b57cec5SDimitry Andric        {return rend();}
5280b57cec5SDimitry Andric
5290b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5300b57cec5SDimitry Andric    size_type size() const _NOEXCEPT
5310b57cec5SDimitry Andric        {return static_cast<size_type>(this->__end_ - this->__begin_);}
5320b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5330b57cec5SDimitry Andric    size_type capacity() const _NOEXCEPT
534349cc55cSDimitry Andric        {return static_cast<size_type>(__end_cap() - this->__begin_);}
5350b57cec5SDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5360b57cec5SDimitry Andric    bool empty() const _NOEXCEPT
5370b57cec5SDimitry Andric        {return this->__begin_ == this->__end_;}
5380b57cec5SDimitry Andric    size_type max_size() const _NOEXCEPT;
5390b57cec5SDimitry Andric    void reserve(size_type __n);
5400b57cec5SDimitry Andric    void shrink_to_fit() _NOEXCEPT;
5410b57cec5SDimitry Andric
5420b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY reference       operator[](size_type __n) _NOEXCEPT;
5430b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const _NOEXCEPT;
5440b57cec5SDimitry Andric    reference       at(size_type __n);
5450b57cec5SDimitry Andric    const_reference at(size_type __n) const;
5460b57cec5SDimitry Andric
5470b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY reference       front() _NOEXCEPT
5480b57cec5SDimitry Andric    {
549fe6060f1SDimitry Andric        _LIBCPP_ASSERT(!empty(), "front() called on an empty vector");
5500b57cec5SDimitry Andric        return *this->__begin_;
5510b57cec5SDimitry Andric    }
5520b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT
5530b57cec5SDimitry Andric    {
554fe6060f1SDimitry Andric        _LIBCPP_ASSERT(!empty(), "front() called on an empty vector");
5550b57cec5SDimitry Andric        return *this->__begin_;
5560b57cec5SDimitry Andric    }
5570b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY reference       back() _NOEXCEPT
5580b57cec5SDimitry Andric    {
559fe6060f1SDimitry Andric        _LIBCPP_ASSERT(!empty(), "back() called on an empty vector");
5600b57cec5SDimitry Andric        return *(this->__end_ - 1);
5610b57cec5SDimitry Andric    }
5620b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const_reference back()  const _NOEXCEPT
5630b57cec5SDimitry Andric    {
564fe6060f1SDimitry Andric        _LIBCPP_ASSERT(!empty(), "back() called on an empty vector");
5650b57cec5SDimitry Andric        return *(this->__end_ - 1);
5660b57cec5SDimitry Andric    }
5670b57cec5SDimitry Andric
5680b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5690b57cec5SDimitry Andric    value_type*       data() _NOEXCEPT
570480093f4SDimitry Andric        {return _VSTD::__to_address(this->__begin_);}
5710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5720b57cec5SDimitry Andric    const value_type* data() const _NOEXCEPT
573480093f4SDimitry Andric        {return _VSTD::__to_address(this->__begin_);}
5740b57cec5SDimitry Andric
5750b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
5760b57cec5SDimitry Andric
5770b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
5780b57cec5SDimitry Andric
5790b57cec5SDimitry Andric    template <class... _Args>
5800b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5810b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
5820b57cec5SDimitry Andric        reference emplace_back(_Args&&... __args);
5830b57cec5SDimitry Andric#else
5840b57cec5SDimitry Andric        void      emplace_back(_Args&&... __args);
5850b57cec5SDimitry Andric#endif
5860b57cec5SDimitry Andric
5870b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5880b57cec5SDimitry Andric    void pop_back();
5890b57cec5SDimitry Andric
5900b57cec5SDimitry Andric    iterator insert(const_iterator __position, const_reference __x);
5910b57cec5SDimitry Andric
5920b57cec5SDimitry Andric    iterator insert(const_iterator __position, value_type&& __x);
5930b57cec5SDimitry Andric    template <class... _Args>
5940b57cec5SDimitry Andric    iterator emplace(const_iterator __position, _Args&&... __args);
5950b57cec5SDimitry Andric
5960b57cec5SDimitry Andric    iterator insert(const_iterator __position, size_type __n, const_reference __x);
5970b57cec5SDimitry Andric    template <class _InputIterator>
598753f127fSDimitry Andric        typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
5990b57cec5SDimitry Andric            is_constructible<
6000b57cec5SDimitry Andric                 value_type,
6010b57cec5SDimitry Andric                 typename iterator_traits<_InputIterator>::reference>::value,
6020b57cec5SDimitry Andric            iterator
6030b57cec5SDimitry Andric        >::type
6040b57cec5SDimitry Andric        insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
6050b57cec5SDimitry Andric    template <class _ForwardIterator>
6060b57cec5SDimitry Andric        typename enable_if
6070b57cec5SDimitry Andric        <
608480093f4SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value &&
6090b57cec5SDimitry Andric            is_constructible<
6100b57cec5SDimitry Andric                 value_type,
6110b57cec5SDimitry Andric                 typename iterator_traits<_ForwardIterator>::reference>::value,
6120b57cec5SDimitry Andric            iterator
6130b57cec5SDimitry Andric        >::type
6140b57cec5SDimitry Andric        insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
6150b57cec5SDimitry Andric
6160b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
6170b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6180b57cec5SDimitry Andric    iterator insert(const_iterator __position, initializer_list<value_type> __il)
6190b57cec5SDimitry Andric        {return insert(__position, __il.begin(), __il.end());}
6200b57cec5SDimitry Andric#endif
6210b57cec5SDimitry Andric
6220b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
6230b57cec5SDimitry Andric    iterator erase(const_iterator __first, const_iterator __last);
6240b57cec5SDimitry Andric
6250b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6260b57cec5SDimitry Andric    void clear() _NOEXCEPT
6270b57cec5SDimitry Andric    {
6280b57cec5SDimitry Andric        size_type __old_size = size();
629349cc55cSDimitry Andric        __clear();
6300b57cec5SDimitry Andric        __annotate_shrink(__old_size);
63181ad6265SDimitry Andric        std::__debug_db_invalidate_all(this);
6320b57cec5SDimitry Andric    }
6330b57cec5SDimitry Andric
6340b57cec5SDimitry Andric    void resize(size_type __sz);
6350b57cec5SDimitry Andric    void resize(size_type __sz, const_reference __x);
6360b57cec5SDimitry Andric
6370b57cec5SDimitry Andric    void swap(vector&)
6380b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
6390b57cec5SDimitry Andric        _NOEXCEPT;
6400b57cec5SDimitry Andric#else
6410b57cec5SDimitry Andric        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
6420b57cec5SDimitry Andric                    __is_nothrow_swappable<allocator_type>::value);
6430b57cec5SDimitry Andric#endif
6440b57cec5SDimitry Andric
6450b57cec5SDimitry Andric    bool __invariants() const;
6460b57cec5SDimitry Andric
64781ad6265SDimitry Andric#ifdef _LIBCPP_ENABLE_DEBUG_MODE
6480b57cec5SDimitry Andric
6490b57cec5SDimitry Andric    bool __dereferenceable(const const_iterator* __i) const;
6500b57cec5SDimitry Andric    bool __decrementable(const const_iterator* __i) const;
6510b57cec5SDimitry Andric    bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
6520b57cec5SDimitry Andric    bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
6530b57cec5SDimitry Andric
65481ad6265SDimitry Andric#endif // _LIBCPP_ENABLE_DEBUG_MODE
6550b57cec5SDimitry Andric
6560b57cec5SDimitry Andricprivate:
657d56accc7SDimitry Andric    pointer __begin_ = nullptr;
658d56accc7SDimitry Andric    pointer __end_ = nullptr;
659d56accc7SDimitry Andric    __compressed_pair<pointer, allocator_type> __end_cap_ =
660d56accc7SDimitry Andric        __compressed_pair<pointer, allocator_type>(nullptr, __default_init_tag());
661d56accc7SDimitry Andric
6620b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last);
66381ad6265SDimitry Andric
66481ad6265SDimitry Andric
66581ad6265SDimitry Andric    //  Allocate space for __n objects
66681ad6265SDimitry Andric    //  throws length_error if __n > max_size()
66781ad6265SDimitry Andric    //  throws (probably bad_alloc) if memory run out
66881ad6265SDimitry Andric    //  Precondition:  __begin_ == __end_ == __end_cap() == 0
66981ad6265SDimitry Andric    //  Precondition:  __n > 0
67081ad6265SDimitry Andric    //  Postcondition:  capacity() >= __n
67181ad6265SDimitry Andric    //  Postcondition:  size() == 0
67281ad6265SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) {
67381ad6265SDimitry Andric        if (__n > max_size())
67481ad6265SDimitry Andric            __throw_length_error();
67581ad6265SDimitry Andric        auto __allocation = std::__allocate_at_least(__alloc(), __n);
67681ad6265SDimitry Andric        __begin_ = __allocation.ptr;
67781ad6265SDimitry Andric        __end_ = __allocation.ptr;
67881ad6265SDimitry Andric        __end_cap() = __begin_ + __allocation.count;
67981ad6265SDimitry Andric        __annotate_new(0);
68081ad6265SDimitry Andric    }
68181ad6265SDimitry Andric
6820b57cec5SDimitry Andric    void __vdeallocate() _NOEXCEPT;
6830b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
6840b57cec5SDimitry Andric    void __construct_at_end(size_type __n);
6850b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6860b57cec5SDimitry Andric    void __construct_at_end(size_type __n, const_reference __x);
6870b57cec5SDimitry Andric    template <class _ForwardIterator>
6880b57cec5SDimitry Andric        typename enable_if
6890b57cec5SDimitry Andric        <
690480093f4SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value,
6910b57cec5SDimitry Andric            void
6920b57cec5SDimitry Andric        >::type
6930b57cec5SDimitry Andric        __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n);
6940b57cec5SDimitry Andric    void __append(size_type __n);
6950b57cec5SDimitry Andric    void __append(size_type __n, const_reference __x);
6960b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6970b57cec5SDimitry Andric    iterator       __make_iter(pointer __p) _NOEXCEPT;
6980b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6990b57cec5SDimitry Andric    const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
7000b57cec5SDimitry Andric    void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
7010b57cec5SDimitry Andric    pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
7020b57cec5SDimitry Andric    void __move_range(pointer __from_s, pointer __from_e, pointer __to);
7030b57cec5SDimitry Andric    void __move_assign(vector& __c, true_type)
7040b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
7050b57cec5SDimitry Andric    void __move_assign(vector& __c, false_type)
7060b57cec5SDimitry Andric        _NOEXCEPT_(__alloc_traits::is_always_equal::value);
7070b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7080b57cec5SDimitry Andric    void __destruct_at_end(pointer __new_last) _NOEXCEPT
7090b57cec5SDimitry Andric    {
7100b57cec5SDimitry Andric        __invalidate_iterators_past(__new_last);
7110b57cec5SDimitry Andric        size_type __old_size = size();
712349cc55cSDimitry Andric        __base_destruct_at_end(__new_last);
7130b57cec5SDimitry Andric        __annotate_shrink(__old_size);
7140b57cec5SDimitry Andric    }
7150b57cec5SDimitry Andric
7160b57cec5SDimitry Andric    template <class _Up>
7170b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7180b57cec5SDimitry Andric    inline void __push_back_slow_path(_Up&& __x);
7190b57cec5SDimitry Andric
7200b57cec5SDimitry Andric    template <class... _Args>
7210b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7220b57cec5SDimitry Andric    inline void __emplace_back_slow_path(_Args&&... __args);
7230b57cec5SDimitry Andric
7240b57cec5SDimitry Andric    // The following functions are no-ops outside of AddressSanitizer mode.
7250b57cec5SDimitry Andric    // We call annotatations only for the default Allocator because other allocators
7260b57cec5SDimitry Andric    // may not meet the AddressSanitizer alignment constraints.
7270b57cec5SDimitry Andric    // See the documentation for __sanitizer_annotate_contiguous_container for more details.
7280b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
7290b57cec5SDimitry Andric    void __annotate_contiguous_container(const void *__beg, const void *__end,
7300b57cec5SDimitry Andric                                         const void *__old_mid,
7310b57cec5SDimitry Andric                                         const void *__new_mid) const
7320b57cec5SDimitry Andric    {
7330b57cec5SDimitry Andric
7340b57cec5SDimitry Andric      if (__beg && is_same<allocator_type, __default_allocator_type>::value)
7350b57cec5SDimitry Andric        __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
7360b57cec5SDimitry Andric    }
7370b57cec5SDimitry Andric#else
7380b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7390b57cec5SDimitry Andric    void __annotate_contiguous_container(const void*, const void*, const void*,
740e40139ffSDimitry Andric                                         const void*) const _NOEXCEPT {}
7410b57cec5SDimitry Andric#endif
7420b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
743e40139ffSDimitry Andric    void __annotate_new(size_type __current_size) const _NOEXCEPT {
7440b57cec5SDimitry Andric      __annotate_contiguous_container(data(), data() + capacity(),
7450b57cec5SDimitry Andric                                      data() + capacity(), data() + __current_size);
7460b57cec5SDimitry Andric    }
7470b57cec5SDimitry Andric
7480b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
749e40139ffSDimitry Andric    void __annotate_delete() const _NOEXCEPT {
7500b57cec5SDimitry Andric      __annotate_contiguous_container(data(), data() + capacity(),
7510b57cec5SDimitry Andric                                      data() + size(), data() + capacity());
7520b57cec5SDimitry Andric    }
7530b57cec5SDimitry Andric
7540b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
755e40139ffSDimitry Andric    void __annotate_increase(size_type __n) const _NOEXCEPT
7560b57cec5SDimitry Andric    {
7570b57cec5SDimitry Andric      __annotate_contiguous_container(data(), data() + capacity(),
7580b57cec5SDimitry Andric                                      data() + size(), data() + size() + __n);
7590b57cec5SDimitry Andric    }
7600b57cec5SDimitry Andric
7610b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
762e40139ffSDimitry Andric    void __annotate_shrink(size_type __old_size) const _NOEXCEPT
7630b57cec5SDimitry Andric    {
7640b57cec5SDimitry Andric      __annotate_contiguous_container(data(), data() + capacity(),
7650b57cec5SDimitry Andric                                      data() + __old_size, data() + size());
7660b57cec5SDimitry Andric    }
7670b57cec5SDimitry Andric
768e40139ffSDimitry Andric  struct _ConstructTransaction {
769e40139ffSDimitry Andric    explicit _ConstructTransaction(vector &__v, size_type __n)
770e40139ffSDimitry Andric      : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) {
771e40139ffSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
772e40139ffSDimitry Andric      __v_.__annotate_increase(__n);
773e40139ffSDimitry Andric#endif
774e40139ffSDimitry Andric    }
775e40139ffSDimitry Andric    ~_ConstructTransaction() {
776e40139ffSDimitry Andric      __v_.__end_ = __pos_;
777e40139ffSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
778e40139ffSDimitry Andric      if (__pos_ != __new_end_) {
779e40139ffSDimitry Andric        __v_.__annotate_shrink(__new_end_ - __v_.__begin_);
780e40139ffSDimitry Andric      }
781e40139ffSDimitry Andric#endif
782e40139ffSDimitry Andric    }
783e40139ffSDimitry Andric
784e40139ffSDimitry Andric    vector &__v_;
785e40139ffSDimitry Andric    pointer __pos_;
786e40139ffSDimitry Andric    const_pointer const __new_end_;
787e40139ffSDimitry Andric
788e40139ffSDimitry Andric  private:
789e40139ffSDimitry Andric    _ConstructTransaction(_ConstructTransaction const&) = delete;
790e40139ffSDimitry Andric    _ConstructTransaction& operator=(_ConstructTransaction const&) = delete;
791e40139ffSDimitry Andric  };
792e40139ffSDimitry Andric
793e40139ffSDimitry Andric  template <class ..._Args>
794e40139ffSDimitry Andric  _LIBCPP_INLINE_VISIBILITY
795e40139ffSDimitry Andric  void __construct_one_at_end(_Args&& ...__args) {
796e40139ffSDimitry Andric    _ConstructTransaction __tx(*this, 1);
797480093f4SDimitry Andric    __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__tx.__pos_),
798e40139ffSDimitry Andric        _VSTD::forward<_Args>(__args)...);
799e40139ffSDimitry Andric    ++__tx.__pos_;
800e40139ffSDimitry Andric  }
801349cc55cSDimitry Andric
802349cc55cSDimitry Andric  _LIBCPP_INLINE_VISIBILITY
803349cc55cSDimitry Andric  allocator_type& __alloc() _NOEXCEPT
804349cc55cSDimitry Andric      {return this->__end_cap_.second();}
805349cc55cSDimitry Andric  _LIBCPP_INLINE_VISIBILITY
806349cc55cSDimitry Andric  const allocator_type& __alloc() const _NOEXCEPT
807349cc55cSDimitry Andric      {return this->__end_cap_.second();}
808349cc55cSDimitry Andric  _LIBCPP_INLINE_VISIBILITY
809349cc55cSDimitry Andric  pointer& __end_cap() _NOEXCEPT
810349cc55cSDimitry Andric      {return this->__end_cap_.first();}
811349cc55cSDimitry Andric  _LIBCPP_INLINE_VISIBILITY
812349cc55cSDimitry Andric  const pointer& __end_cap() const _NOEXCEPT
813349cc55cSDimitry Andric      {return this->__end_cap_.first();}
814349cc55cSDimitry Andric
815349cc55cSDimitry Andric  _LIBCPP_INLINE_VISIBILITY
816349cc55cSDimitry Andric  void __clear() _NOEXCEPT {__base_destruct_at_end(this->__begin_);}
817349cc55cSDimitry Andric
818349cc55cSDimitry Andric  _LIBCPP_INLINE_VISIBILITY
819349cc55cSDimitry Andric  void __base_destruct_at_end(pointer __new_last) _NOEXCEPT {
820349cc55cSDimitry Andric    pointer __soon_to_be_end = this->__end_;
821349cc55cSDimitry Andric    while (__new_last != __soon_to_be_end)
822349cc55cSDimitry Andric        __alloc_traits::destroy(__alloc(), _VSTD::__to_address(--__soon_to_be_end));
823349cc55cSDimitry Andric    this->__end_ = __new_last;
824349cc55cSDimitry Andric  }
825349cc55cSDimitry Andric
826349cc55cSDimitry Andric  _LIBCPP_INLINE_VISIBILITY
827349cc55cSDimitry Andric  void __copy_assign_alloc(const vector& __c)
828349cc55cSDimitry Andric      {__copy_assign_alloc(__c, integral_constant<bool,
829349cc55cSDimitry Andric                    __alloc_traits::propagate_on_container_copy_assignment::value>());}
830349cc55cSDimitry Andric
831349cc55cSDimitry Andric  _LIBCPP_INLINE_VISIBILITY
832349cc55cSDimitry Andric  void __move_assign_alloc(vector& __c)
833349cc55cSDimitry Andric      _NOEXCEPT_(
834349cc55cSDimitry Andric          !__alloc_traits::propagate_on_container_move_assignment::value ||
835349cc55cSDimitry Andric          is_nothrow_move_assignable<allocator_type>::value)
836349cc55cSDimitry Andric      {__move_assign_alloc(__c, integral_constant<bool,
837349cc55cSDimitry Andric                    __alloc_traits::propagate_on_container_move_assignment::value>());}
838349cc55cSDimitry Andric
839349cc55cSDimitry Andric  _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
840349cc55cSDimitry Andric  void __throw_length_error() const {
841d56accc7SDimitry Andric      _VSTD::__throw_length_error("vector");
842349cc55cSDimitry Andric  }
843349cc55cSDimitry Andric
844349cc55cSDimitry Andric  _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
845349cc55cSDimitry Andric  void __throw_out_of_range() const {
846d56accc7SDimitry Andric      _VSTD::__throw_out_of_range("vector");
847349cc55cSDimitry Andric  }
848349cc55cSDimitry Andric
849349cc55cSDimitry Andric  _LIBCPP_INLINE_VISIBILITY
850349cc55cSDimitry Andric  void __copy_assign_alloc(const vector& __c, true_type)
851349cc55cSDimitry Andric  {
852349cc55cSDimitry Andric    if (__alloc() != __c.__alloc())
853349cc55cSDimitry Andric    {
854349cc55cSDimitry Andric      __clear();
855349cc55cSDimitry Andric      __alloc_traits::deallocate(__alloc(), this->__begin_, capacity());
856349cc55cSDimitry Andric      this->__begin_ = this->__end_ = __end_cap() = nullptr;
857349cc55cSDimitry Andric    }
858349cc55cSDimitry Andric    __alloc() = __c.__alloc();
859349cc55cSDimitry Andric  }
860349cc55cSDimitry Andric
861349cc55cSDimitry Andric  _LIBCPP_INLINE_VISIBILITY
862349cc55cSDimitry Andric  void __copy_assign_alloc(const vector&, false_type)
863349cc55cSDimitry Andric  {}
864349cc55cSDimitry Andric
865349cc55cSDimitry Andric  _LIBCPP_INLINE_VISIBILITY
866349cc55cSDimitry Andric  void __move_assign_alloc(vector& __c, true_type)
867349cc55cSDimitry Andric      _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
868349cc55cSDimitry Andric  {
869349cc55cSDimitry Andric    __alloc() = _VSTD::move(__c.__alloc());
870349cc55cSDimitry Andric  }
871349cc55cSDimitry Andric
872349cc55cSDimitry Andric  _LIBCPP_INLINE_VISIBILITY
873349cc55cSDimitry Andric  void __move_assign_alloc(vector&, false_type)
874349cc55cSDimitry Andric      _NOEXCEPT
875349cc55cSDimitry Andric  {}
8760b57cec5SDimitry Andric};
8770b57cec5SDimitry Andric
878349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17
8790b57cec5SDimitry Andrictemplate<class _InputIterator,
880fe6060f1SDimitry Andric         class _Alloc = allocator<__iter_value_type<_InputIterator>>,
881349cc55cSDimitry Andric         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
882349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Alloc>::value>
8830b57cec5SDimitry Andric         >
8840b57cec5SDimitry Andricvector(_InputIterator, _InputIterator)
885fe6060f1SDimitry Andric  -> vector<__iter_value_type<_InputIterator>, _Alloc>;
8860b57cec5SDimitry Andric
8870b57cec5SDimitry Andrictemplate<class _InputIterator,
8880b57cec5SDimitry Andric         class _Alloc,
889349cc55cSDimitry Andric         class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>,
890349cc55cSDimitry Andric         class = enable_if_t<__is_allocator<_Alloc>::value>
8910b57cec5SDimitry Andric         >
8920b57cec5SDimitry Andricvector(_InputIterator, _InputIterator, _Alloc)
893fe6060f1SDimitry Andric  -> vector<__iter_value_type<_InputIterator>, _Alloc>;
8940b57cec5SDimitry Andric#endif
8950b57cec5SDimitry Andric
8960b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
8970b57cec5SDimitry Andricvoid
8980b57cec5SDimitry Andricvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
8990b57cec5SDimitry Andric{
9000b57cec5SDimitry Andric    __annotate_delete();
901*972a253aSDimitry Andric    using _RevIter = std::reverse_iterator<pointer>;
902*972a253aSDimitry Andric    __v.__begin_   = std::__uninitialized_allocator_move_if_noexcept(
903*972a253aSDimitry Andric                       __alloc(), _RevIter(__end_), _RevIter(__begin_), _RevIter(__v.__begin_))
904*972a253aSDimitry Andric                       .base();
9050b57cec5SDimitry Andric    _VSTD::swap(this->__begin_, __v.__begin_);
9060b57cec5SDimitry Andric    _VSTD::swap(this->__end_, __v.__end_);
9070b57cec5SDimitry Andric    _VSTD::swap(this->__end_cap(), __v.__end_cap());
9080b57cec5SDimitry Andric    __v.__first_ = __v.__begin_;
9090b57cec5SDimitry Andric    __annotate_new(size());
91081ad6265SDimitry Andric    std::__debug_db_invalidate_all(this);
9110b57cec5SDimitry Andric}
9120b57cec5SDimitry Andric
9130b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
9140b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::pointer
9150b57cec5SDimitry Andricvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
9160b57cec5SDimitry Andric{
9170b57cec5SDimitry Andric    __annotate_delete();
9180b57cec5SDimitry Andric    pointer __r = __v.__begin_;
919*972a253aSDimitry Andric    using _RevIter = std::reverse_iterator<pointer>;
920*972a253aSDimitry Andric    __v.__begin_   = std::__uninitialized_allocator_move_if_noexcept(
921*972a253aSDimitry Andric                       __alloc(), _RevIter(__p), _RevIter(__begin_), _RevIter(__v.__begin_))
922*972a253aSDimitry Andric                       .base();
923*972a253aSDimitry Andric    __v.__end_ = std::__uninitialized_allocator_move_if_noexcept(__alloc(), __p, __end_, __v.__end_);
9240b57cec5SDimitry Andric    _VSTD::swap(this->__begin_, __v.__begin_);
9250b57cec5SDimitry Andric    _VSTD::swap(this->__end_, __v.__end_);
9260b57cec5SDimitry Andric    _VSTD::swap(this->__end_cap(), __v.__end_cap());
9270b57cec5SDimitry Andric    __v.__first_ = __v.__begin_;
9280b57cec5SDimitry Andric    __annotate_new(size());
92981ad6265SDimitry Andric    std::__debug_db_invalidate_all(this);
9300b57cec5SDimitry Andric    return __r;
9310b57cec5SDimitry Andric}
9320b57cec5SDimitry Andric
9330b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
9340b57cec5SDimitry Andricvoid
9350b57cec5SDimitry Andricvector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT
9360b57cec5SDimitry Andric{
9370b57cec5SDimitry Andric    if (this->__begin_ != nullptr)
9380b57cec5SDimitry Andric    {
9390b57cec5SDimitry Andric        clear();
9400b57cec5SDimitry Andric        __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
9410b57cec5SDimitry Andric        this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
9420b57cec5SDimitry Andric    }
9430b57cec5SDimitry Andric}
9440b57cec5SDimitry Andric
9450b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
9460b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::size_type
9470b57cec5SDimitry Andricvector<_Tp, _Allocator>::max_size() const _NOEXCEPT
9480b57cec5SDimitry Andric{
9490b57cec5SDimitry Andric    return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()),
9500b57cec5SDimitry Andric                                 numeric_limits<difference_type>::max());
9510b57cec5SDimitry Andric}
9520b57cec5SDimitry Andric
9530b57cec5SDimitry Andric//  Precondition:  __new_size > capacity()
9540b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
9550b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
9560b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::size_type
9570b57cec5SDimitry Andricvector<_Tp, _Allocator>::__recommend(size_type __new_size) const
9580b57cec5SDimitry Andric{
9590b57cec5SDimitry Andric    const size_type __ms = max_size();
9600b57cec5SDimitry Andric    if (__new_size > __ms)
9610b57cec5SDimitry Andric        this->__throw_length_error();
9620b57cec5SDimitry Andric    const size_type __cap = capacity();
9630b57cec5SDimitry Andric    if (__cap >= __ms / 2)
9640b57cec5SDimitry Andric        return __ms;
9650b57cec5SDimitry Andric    return _VSTD::max<size_type>(2 * __cap, __new_size);
9660b57cec5SDimitry Andric}
9670b57cec5SDimitry Andric
9680b57cec5SDimitry Andric//  Default constructs __n objects starting at __end_
9690b57cec5SDimitry Andric//  throws if construction throws
9700b57cec5SDimitry Andric//  Precondition:  __n > 0
9710b57cec5SDimitry Andric//  Precondition:  size() + __n <= capacity()
9720b57cec5SDimitry Andric//  Postcondition:  size() == size() + __n
9730b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
9740b57cec5SDimitry Andricvoid
9750b57cec5SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(size_type __n)
9760b57cec5SDimitry Andric{
977e40139ffSDimitry Andric    _ConstructTransaction __tx(*this, __n);
9785ffd83dbSDimitry Andric    const_pointer __new_end = __tx.__new_end_;
979349cc55cSDimitry Andric    for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
9805ffd83dbSDimitry Andric        __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos));
981e40139ffSDimitry Andric    }
9820b57cec5SDimitry Andric}
9830b57cec5SDimitry Andric
9840b57cec5SDimitry Andric//  Copy constructs __n objects starting at __end_ from __x
9850b57cec5SDimitry Andric//  throws if construction throws
9860b57cec5SDimitry Andric//  Precondition:  __n > 0
9870b57cec5SDimitry Andric//  Precondition:  size() + __n <= capacity()
9880b57cec5SDimitry Andric//  Postcondition:  size() == old size() + __n
9890b57cec5SDimitry Andric//  Postcondition:  [i] == __x for all i in [size() - __n, __n)
9900b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
9910b57cec5SDimitry Andricinline
9920b57cec5SDimitry Andricvoid
9930b57cec5SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
9940b57cec5SDimitry Andric{
995e40139ffSDimitry Andric    _ConstructTransaction __tx(*this, __n);
9965ffd83dbSDimitry Andric    const_pointer __new_end = __tx.__new_end_;
997349cc55cSDimitry Andric    for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
9985ffd83dbSDimitry Andric        __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos), __x);
999e40139ffSDimitry Andric    }
10000b57cec5SDimitry Andric}
10010b57cec5SDimitry Andric
10020b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
10030b57cec5SDimitry Andrictemplate <class _ForwardIterator>
10040b57cec5SDimitry Andrictypename enable_if
10050b57cec5SDimitry Andric<
1006480093f4SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value,
10070b57cec5SDimitry Andric    void
10080b57cec5SDimitry Andric>::type
10090b57cec5SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n)
10100b57cec5SDimitry Andric{
1011e40139ffSDimitry Andric  _ConstructTransaction __tx(*this, __n);
1012*972a253aSDimitry Andric  __tx.__pos_ = std::__uninitialized_allocator_copy(__alloc(), __first, __last, __tx.__pos_);
10130b57cec5SDimitry Andric}
10140b57cec5SDimitry Andric
10150b57cec5SDimitry Andric//  Default constructs __n objects starting at __end_
10160b57cec5SDimitry Andric//  throws if construction throws
10170b57cec5SDimitry Andric//  Postcondition:  size() == size() + __n
10180b57cec5SDimitry Andric//  Exception safety: strong.
10190b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
10200b57cec5SDimitry Andricvoid
10210b57cec5SDimitry Andricvector<_Tp, _Allocator>::__append(size_type __n)
10220b57cec5SDimitry Andric{
10230b57cec5SDimitry Andric    if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
10240b57cec5SDimitry Andric        this->__construct_at_end(__n);
10250b57cec5SDimitry Andric    else
10260b57cec5SDimitry Andric    {
10270b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
10280b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
10290b57cec5SDimitry Andric        __v.__construct_at_end(__n);
10300b57cec5SDimitry Andric        __swap_out_circular_buffer(__v);
10310b57cec5SDimitry Andric    }
10320b57cec5SDimitry Andric}
10330b57cec5SDimitry Andric
10340b57cec5SDimitry Andric//  Default constructs __n objects starting at __end_
10350b57cec5SDimitry Andric//  throws if construction throws
10360b57cec5SDimitry Andric//  Postcondition:  size() == size() + __n
10370b57cec5SDimitry Andric//  Exception safety: strong.
10380b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
10390b57cec5SDimitry Andricvoid
10400b57cec5SDimitry Andricvector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
10410b57cec5SDimitry Andric{
10420b57cec5SDimitry Andric    if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
10430b57cec5SDimitry Andric        this->__construct_at_end(__n, __x);
10440b57cec5SDimitry Andric    else
10450b57cec5SDimitry Andric    {
10460b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
10470b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
10480b57cec5SDimitry Andric        __v.__construct_at_end(__n, __x);
10490b57cec5SDimitry Andric        __swap_out_circular_buffer(__v);
10500b57cec5SDimitry Andric    }
10510b57cec5SDimitry Andric}
10520b57cec5SDimitry Andric
10530b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
10540b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n)
10550b57cec5SDimitry Andric{
105604eeddc0SDimitry Andric    _VSTD::__debug_db_insert_c(this);
10570b57cec5SDimitry Andric    if (__n > 0)
10580b57cec5SDimitry Andric    {
10590b57cec5SDimitry Andric        __vallocate(__n);
10600b57cec5SDimitry Andric        __construct_at_end(__n);
10610b57cec5SDimitry Andric    }
10620b57cec5SDimitry Andric}
10630b57cec5SDimitry Andric
10640b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
10650b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
10660b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
1067d56accc7SDimitry Andric    : __end_cap_(nullptr, __a)
10680b57cec5SDimitry Andric{
106904eeddc0SDimitry Andric    _VSTD::__debug_db_insert_c(this);
10700b57cec5SDimitry Andric    if (__n > 0)
10710b57cec5SDimitry Andric    {
10720b57cec5SDimitry Andric        __vallocate(__n);
10730b57cec5SDimitry Andric        __construct_at_end(__n);
10740b57cec5SDimitry Andric    }
10750b57cec5SDimitry Andric}
10760b57cec5SDimitry Andric#endif
10770b57cec5SDimitry Andric
10780b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
10790b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x)
10800b57cec5SDimitry Andric{
108104eeddc0SDimitry Andric    _VSTD::__debug_db_insert_c(this);
10820b57cec5SDimitry Andric    if (__n > 0)
10830b57cec5SDimitry Andric    {
10840b57cec5SDimitry Andric        __vallocate(__n);
10850b57cec5SDimitry Andric        __construct_at_end(__n, __x);
10860b57cec5SDimitry Andric    }
10870b57cec5SDimitry Andric}
10880b57cec5SDimitry Andric
10890b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
10900b57cec5SDimitry Andrictemplate <class _InputIterator>
10910b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_InputIterator __first,
1092753f127fSDimitry Andric       typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
10930b57cec5SDimitry Andric                         is_constructible<
10940b57cec5SDimitry Andric                            value_type,
10950b57cec5SDimitry Andric                            typename iterator_traits<_InputIterator>::reference>::value,
10960b57cec5SDimitry Andric                          _InputIterator>::type __last)
10970b57cec5SDimitry Andric{
109804eeddc0SDimitry Andric    _VSTD::__debug_db_insert_c(this);
10990b57cec5SDimitry Andric    for (; __first != __last; ++__first)
110081ad6265SDimitry Andric        emplace_back(*__first);
11010b57cec5SDimitry Andric}
11020b57cec5SDimitry Andric
11030b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
11040b57cec5SDimitry Andrictemplate <class _InputIterator>
11050b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1106753f127fSDimitry Andric       typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
11070b57cec5SDimitry Andric                         is_constructible<
11080b57cec5SDimitry Andric                            value_type,
11090b57cec5SDimitry Andric                            typename iterator_traits<_InputIterator>::reference>::value>::type*)
1110d56accc7SDimitry Andric    : __end_cap_(nullptr, __a)
11110b57cec5SDimitry Andric{
111204eeddc0SDimitry Andric    _VSTD::__debug_db_insert_c(this);
11130b57cec5SDimitry Andric    for (; __first != __last; ++__first)
111481ad6265SDimitry Andric        emplace_back(*__first);
11150b57cec5SDimitry Andric}
11160b57cec5SDimitry Andric
11170b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
11180b57cec5SDimitry Andrictemplate <class _ForwardIterator>
11190b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_ForwardIterator __first,
1120480093f4SDimitry Andric                                typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
11210b57cec5SDimitry Andric                                is_constructible<
11220b57cec5SDimitry Andric                                   value_type,
11230b57cec5SDimitry Andric                                   typename iterator_traits<_ForwardIterator>::reference>::value,
11240b57cec5SDimitry Andric                                                   _ForwardIterator>::type __last)
11250b57cec5SDimitry Andric{
112604eeddc0SDimitry Andric    _VSTD::__debug_db_insert_c(this);
11270b57cec5SDimitry Andric    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
11280b57cec5SDimitry Andric    if (__n > 0)
11290b57cec5SDimitry Andric    {
11300b57cec5SDimitry Andric        __vallocate(__n);
11310b57cec5SDimitry Andric        __construct_at_end(__first, __last, __n);
11320b57cec5SDimitry Andric    }
11330b57cec5SDimitry Andric}
11340b57cec5SDimitry Andric
11350b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
11360b57cec5SDimitry Andrictemplate <class _ForwardIterator>
11370b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
1138480093f4SDimitry Andric                                typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
11390b57cec5SDimitry Andric                                is_constructible<
11400b57cec5SDimitry Andric                                   value_type,
11410b57cec5SDimitry Andric                                   typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
1142d56accc7SDimitry Andric    : __end_cap_(nullptr, __a)
11430b57cec5SDimitry Andric{
114404eeddc0SDimitry Andric    _VSTD::__debug_db_insert_c(this);
11450b57cec5SDimitry Andric    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
11460b57cec5SDimitry Andric    if (__n > 0)
11470b57cec5SDimitry Andric    {
11480b57cec5SDimitry Andric        __vallocate(__n);
11490b57cec5SDimitry Andric        __construct_at_end(__first, __last, __n);
11500b57cec5SDimitry Andric    }
11510b57cec5SDimitry Andric}
11520b57cec5SDimitry Andric
11530b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
11540b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(const vector& __x)
1155d56accc7SDimitry Andric    : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc()))
11560b57cec5SDimitry Andric{
115704eeddc0SDimitry Andric    _VSTD::__debug_db_insert_c(this);
11580b57cec5SDimitry Andric    size_type __n = __x.size();
11590b57cec5SDimitry Andric    if (__n > 0)
11600b57cec5SDimitry Andric    {
11610b57cec5SDimitry Andric        __vallocate(__n);
11620b57cec5SDimitry Andric        __construct_at_end(__x.__begin_, __x.__end_, __n);
11630b57cec5SDimitry Andric    }
11640b57cec5SDimitry Andric}
11650b57cec5SDimitry Andric
11660b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
116781ad6265SDimitry Andricvector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
1168d56accc7SDimitry Andric    : __end_cap_(nullptr, __a)
11690b57cec5SDimitry Andric{
117004eeddc0SDimitry Andric    _VSTD::__debug_db_insert_c(this);
11710b57cec5SDimitry Andric    size_type __n = __x.size();
11720b57cec5SDimitry Andric    if (__n > 0)
11730b57cec5SDimitry Andric    {
11740b57cec5SDimitry Andric        __vallocate(__n);
11750b57cec5SDimitry Andric        __construct_at_end(__x.__begin_, __x.__end_, __n);
11760b57cec5SDimitry Andric    }
11770b57cec5SDimitry Andric}
11780b57cec5SDimitry Andric
11790b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
11800b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
11810b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(vector&& __x)
11820b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
118381ad6265SDimitry Andric        noexcept
11840b57cec5SDimitry Andric#else
11850b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
11860b57cec5SDimitry Andric#endif
1187d56accc7SDimitry Andric    : __end_cap_(nullptr, _VSTD::move(__x.__alloc()))
11880b57cec5SDimitry Andric{
118904eeddc0SDimitry Andric    _VSTD::__debug_db_insert_c(this);
119081ad6265SDimitry Andric    std::__debug_db_swap(this, std::addressof(__x));
11910b57cec5SDimitry Andric    this->__begin_ = __x.__begin_;
11920b57cec5SDimitry Andric    this->__end_ = __x.__end_;
11930b57cec5SDimitry Andric    this->__end_cap() = __x.__end_cap();
11940b57cec5SDimitry Andric    __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
11950b57cec5SDimitry Andric}
11960b57cec5SDimitry Andric
11970b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
11980b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
119981ad6265SDimitry Andricvector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_type>& __a)
1200d56accc7SDimitry Andric    : __end_cap_(nullptr, __a)
12010b57cec5SDimitry Andric{
120204eeddc0SDimitry Andric    _VSTD::__debug_db_insert_c(this);
12030b57cec5SDimitry Andric    if (__a == __x.__alloc())
12040b57cec5SDimitry Andric    {
12050b57cec5SDimitry Andric        this->__begin_ = __x.__begin_;
12060b57cec5SDimitry Andric        this->__end_ = __x.__end_;
12070b57cec5SDimitry Andric        this->__end_cap() = __x.__end_cap();
12080b57cec5SDimitry Andric        __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
120981ad6265SDimitry Andric        std::__debug_db_swap(this, std::addressof(__x));
12100b57cec5SDimitry Andric    }
12110b57cec5SDimitry Andric    else
12120b57cec5SDimitry Andric    {
12130b57cec5SDimitry Andric        typedef move_iterator<iterator> _Ip;
12140b57cec5SDimitry Andric        assign(_Ip(__x.begin()), _Ip(__x.end()));
12150b57cec5SDimitry Andric    }
12160b57cec5SDimitry Andric}
12170b57cec5SDimitry Andric
121881ad6265SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
121981ad6265SDimitry Andric
12200b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
12210b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
12220b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
12230b57cec5SDimitry Andric{
122404eeddc0SDimitry Andric    _VSTD::__debug_db_insert_c(this);
12250b57cec5SDimitry Andric    if (__il.size() > 0)
12260b57cec5SDimitry Andric    {
12270b57cec5SDimitry Andric        __vallocate(__il.size());
12280b57cec5SDimitry Andric        __construct_at_end(__il.begin(), __il.end(), __il.size());
12290b57cec5SDimitry Andric    }
12300b57cec5SDimitry Andric}
12310b57cec5SDimitry Andric
12320b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
12330b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
12340b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1235d56accc7SDimitry Andric    : __end_cap_(nullptr, __a)
12360b57cec5SDimitry Andric{
123704eeddc0SDimitry Andric    _VSTD::__debug_db_insert_c(this);
12380b57cec5SDimitry Andric    if (__il.size() > 0)
12390b57cec5SDimitry Andric    {
12400b57cec5SDimitry Andric        __vallocate(__il.size());
12410b57cec5SDimitry Andric        __construct_at_end(__il.begin(), __il.end(), __il.size());
12420b57cec5SDimitry Andric    }
12430b57cec5SDimitry Andric}
12440b57cec5SDimitry Andric
124581ad6265SDimitry Andric#endif // _LIBCPP_CXX03_LANG
124681ad6265SDimitry Andric
12470b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
12480b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
12490b57cec5SDimitry Andricvector<_Tp, _Allocator>&
12500b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator=(vector&& __x)
12510b57cec5SDimitry Andric    _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
12520b57cec5SDimitry Andric{
12530b57cec5SDimitry Andric    __move_assign(__x, integral_constant<bool,
12540b57cec5SDimitry Andric          __alloc_traits::propagate_on_container_move_assignment::value>());
12550b57cec5SDimitry Andric    return *this;
12560b57cec5SDimitry Andric}
12570b57cec5SDimitry Andric
12580b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
12590b57cec5SDimitry Andricvoid
12600b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
12610b57cec5SDimitry Andric    _NOEXCEPT_(__alloc_traits::is_always_equal::value)
12620b57cec5SDimitry Andric{
1263349cc55cSDimitry Andric    if (__alloc() != __c.__alloc())
12640b57cec5SDimitry Andric    {
12650b57cec5SDimitry Andric        typedef move_iterator<iterator> _Ip;
12660b57cec5SDimitry Andric        assign(_Ip(__c.begin()), _Ip(__c.end()));
12670b57cec5SDimitry Andric    }
12680b57cec5SDimitry Andric    else
12690b57cec5SDimitry Andric        __move_assign(__c, true_type());
12700b57cec5SDimitry Andric}
12710b57cec5SDimitry Andric
12720b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
12730b57cec5SDimitry Andricvoid
12740b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
12750b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
12760b57cec5SDimitry Andric{
12770b57cec5SDimitry Andric    __vdeallocate();
1278349cc55cSDimitry Andric    __move_assign_alloc(__c); // this can throw
12790b57cec5SDimitry Andric    this->__begin_ = __c.__begin_;
12800b57cec5SDimitry Andric    this->__end_ = __c.__end_;
12810b57cec5SDimitry Andric    this->__end_cap() = __c.__end_cap();
12820b57cec5SDimitry Andric    __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
128381ad6265SDimitry Andric    std::__debug_db_swap(this, std::addressof(__c));
12840b57cec5SDimitry Andric}
12850b57cec5SDimitry Andric
12860b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
12870b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
12880b57cec5SDimitry Andricvector<_Tp, _Allocator>&
12890b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator=(const vector& __x)
12900b57cec5SDimitry Andric{
1291349cc55cSDimitry Andric    if (this != _VSTD::addressof(__x))
12920b57cec5SDimitry Andric    {
1293349cc55cSDimitry Andric        __copy_assign_alloc(__x);
12940b57cec5SDimitry Andric        assign(__x.__begin_, __x.__end_);
12950b57cec5SDimitry Andric    }
12960b57cec5SDimitry Andric    return *this;
12970b57cec5SDimitry Andric}
12980b57cec5SDimitry Andric
12990b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
13000b57cec5SDimitry Andrictemplate <class _InputIterator>
1301753f127fSDimitry Andrictypename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
13020b57cec5SDimitry Andric    is_constructible<
13030b57cec5SDimitry Andric       _Tp,
13040b57cec5SDimitry Andric       typename iterator_traits<_InputIterator>::reference>::value,
13050b57cec5SDimitry Andric    void
13060b57cec5SDimitry Andric>::type
13070b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
13080b57cec5SDimitry Andric{
13090b57cec5SDimitry Andric    clear();
13100b57cec5SDimitry Andric    for (; __first != __last; ++__first)
131181ad6265SDimitry Andric        emplace_back(*__first);
13120b57cec5SDimitry Andric}
13130b57cec5SDimitry Andric
13140b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
13150b57cec5SDimitry Andrictemplate <class _ForwardIterator>
13160b57cec5SDimitry Andrictypename enable_if
13170b57cec5SDimitry Andric<
1318480093f4SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value &&
13190b57cec5SDimitry Andric    is_constructible<
13200b57cec5SDimitry Andric       _Tp,
13210b57cec5SDimitry Andric       typename iterator_traits<_ForwardIterator>::reference>::value,
13220b57cec5SDimitry Andric    void
13230b57cec5SDimitry Andric>::type
13240b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
13250b57cec5SDimitry Andric{
13260b57cec5SDimitry Andric    size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last));
13270b57cec5SDimitry Andric    if (__new_size <= capacity())
13280b57cec5SDimitry Andric    {
13290b57cec5SDimitry Andric        _ForwardIterator __mid = __last;
13300b57cec5SDimitry Andric        bool __growing = false;
13310b57cec5SDimitry Andric        if (__new_size > size())
13320b57cec5SDimitry Andric        {
13330b57cec5SDimitry Andric            __growing = true;
13340b57cec5SDimitry Andric            __mid =  __first;
13350b57cec5SDimitry Andric            _VSTD::advance(__mid, size());
13360b57cec5SDimitry Andric        }
13370b57cec5SDimitry Andric        pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
13380b57cec5SDimitry Andric        if (__growing)
13390b57cec5SDimitry Andric            __construct_at_end(__mid, __last, __new_size - size());
13400b57cec5SDimitry Andric        else
13410b57cec5SDimitry Andric            this->__destruct_at_end(__m);
13420b57cec5SDimitry Andric    }
13430b57cec5SDimitry Andric    else
13440b57cec5SDimitry Andric    {
13450b57cec5SDimitry Andric        __vdeallocate();
13460b57cec5SDimitry Andric        __vallocate(__recommend(__new_size));
13470b57cec5SDimitry Andric        __construct_at_end(__first, __last, __new_size);
13480b57cec5SDimitry Andric    }
134981ad6265SDimitry Andric    std::__debug_db_invalidate_all(this);
13500b57cec5SDimitry Andric}
13510b57cec5SDimitry Andric
13520b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
13530b57cec5SDimitry Andricvoid
13540b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
13550b57cec5SDimitry Andric{
13560b57cec5SDimitry Andric    if (__n <= capacity())
13570b57cec5SDimitry Andric    {
13580b57cec5SDimitry Andric        size_type __s = size();
13590b57cec5SDimitry Andric        _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
13600b57cec5SDimitry Andric        if (__n > __s)
13610b57cec5SDimitry Andric            __construct_at_end(__n - __s, __u);
13620b57cec5SDimitry Andric        else
13630b57cec5SDimitry Andric            this->__destruct_at_end(this->__begin_ + __n);
13640b57cec5SDimitry Andric    }
13650b57cec5SDimitry Andric    else
13660b57cec5SDimitry Andric    {
13670b57cec5SDimitry Andric        __vdeallocate();
13680b57cec5SDimitry Andric        __vallocate(__recommend(static_cast<size_type>(__n)));
13690b57cec5SDimitry Andric        __construct_at_end(__n, __u);
13700b57cec5SDimitry Andric    }
137181ad6265SDimitry Andric    std::__debug_db_invalidate_all(this);
13720b57cec5SDimitry Andric}
13730b57cec5SDimitry Andric
13740b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
13750b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
13760b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
13770b57cec5SDimitry Andricvector<_Tp, _Allocator>::begin() _NOEXCEPT
13780b57cec5SDimitry Andric{
137981ad6265SDimitry Andric    return iterator(this, this->__begin_);
13800b57cec5SDimitry Andric}
13810b57cec5SDimitry Andric
13820b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
13830b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
13840b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_iterator
13850b57cec5SDimitry Andricvector<_Tp, _Allocator>::begin() const _NOEXCEPT
13860b57cec5SDimitry Andric{
138781ad6265SDimitry Andric    return const_iterator(this, this->__begin_);
13880b57cec5SDimitry Andric}
13890b57cec5SDimitry Andric
13900b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
13910b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
13920b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
13930b57cec5SDimitry Andricvector<_Tp, _Allocator>::end() _NOEXCEPT
13940b57cec5SDimitry Andric{
139581ad6265SDimitry Andric    return iterator(this, this->__end_);
13960b57cec5SDimitry Andric}
13970b57cec5SDimitry Andric
13980b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
13990b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
14000b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_iterator
14010b57cec5SDimitry Andricvector<_Tp, _Allocator>::end() const _NOEXCEPT
14020b57cec5SDimitry Andric{
140381ad6265SDimitry Andric    return const_iterator(this, this->__end_);
14040b57cec5SDimitry Andric}
14050b57cec5SDimitry Andric
14060b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
14070b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
14080b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference
14090b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT
14100b57cec5SDimitry Andric{
14110b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
14120b57cec5SDimitry Andric    return this->__begin_[__n];
14130b57cec5SDimitry Andric}
14140b57cec5SDimitry Andric
14150b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
14160b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
14170b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_reference
14180b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT
14190b57cec5SDimitry Andric{
14200b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
14210b57cec5SDimitry Andric    return this->__begin_[__n];
14220b57cec5SDimitry Andric}
14230b57cec5SDimitry Andric
14240b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
14250b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference
14260b57cec5SDimitry Andricvector<_Tp, _Allocator>::at(size_type __n)
14270b57cec5SDimitry Andric{
14280b57cec5SDimitry Andric    if (__n >= size())
14290b57cec5SDimitry Andric        this->__throw_out_of_range();
14300b57cec5SDimitry Andric    return this->__begin_[__n];
14310b57cec5SDimitry Andric}
14320b57cec5SDimitry Andric
14330b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
14340b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_reference
14350b57cec5SDimitry Andricvector<_Tp, _Allocator>::at(size_type __n) const
14360b57cec5SDimitry Andric{
14370b57cec5SDimitry Andric    if (__n >= size())
14380b57cec5SDimitry Andric        this->__throw_out_of_range();
14390b57cec5SDimitry Andric    return this->__begin_[__n];
14400b57cec5SDimitry Andric}
14410b57cec5SDimitry Andric
14420b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
14430b57cec5SDimitry Andricvoid
14440b57cec5SDimitry Andricvector<_Tp, _Allocator>::reserve(size_type __n)
14450b57cec5SDimitry Andric{
14460b57cec5SDimitry Andric    if (__n > capacity())
14470b57cec5SDimitry Andric    {
1448349cc55cSDimitry Andric        if (__n > max_size())
1449349cc55cSDimitry Andric            this->__throw_length_error();
14500b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
14510b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
14520b57cec5SDimitry Andric        __swap_out_circular_buffer(__v);
14530b57cec5SDimitry Andric    }
14540b57cec5SDimitry Andric}
14550b57cec5SDimitry Andric
14560b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
14570b57cec5SDimitry Andricvoid
14580b57cec5SDimitry Andricvector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
14590b57cec5SDimitry Andric{
14600b57cec5SDimitry Andric    if (capacity() > size())
14610b57cec5SDimitry Andric    {
14620b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
14630b57cec5SDimitry Andric        try
14640b57cec5SDimitry Andric        {
14650b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
14660b57cec5SDimitry Andric            allocator_type& __a = this->__alloc();
14670b57cec5SDimitry Andric            __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
14680b57cec5SDimitry Andric            __swap_out_circular_buffer(__v);
14690b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
14700b57cec5SDimitry Andric        }
14710b57cec5SDimitry Andric        catch (...)
14720b57cec5SDimitry Andric        {
14730b57cec5SDimitry Andric        }
14740b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
14750b57cec5SDimitry Andric    }
14760b57cec5SDimitry Andric}
14770b57cec5SDimitry Andric
14780b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
14790b57cec5SDimitry Andrictemplate <class _Up>
14800b57cec5SDimitry Andricvoid
14810b57cec5SDimitry Andricvector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
14820b57cec5SDimitry Andric{
14830b57cec5SDimitry Andric    allocator_type& __a = this->__alloc();
14840b57cec5SDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
14850b57cec5SDimitry Andric    // __v.push_back(_VSTD::forward<_Up>(__x));
1486480093f4SDimitry Andric    __alloc_traits::construct(__a, _VSTD::__to_address(__v.__end_), _VSTD::forward<_Up>(__x));
14870b57cec5SDimitry Andric    __v.__end_++;
14880b57cec5SDimitry Andric    __swap_out_circular_buffer(__v);
14890b57cec5SDimitry Andric}
14900b57cec5SDimitry Andric
14910b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
14920b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
14930b57cec5SDimitry Andricvoid
14940b57cec5SDimitry Andricvector<_Tp, _Allocator>::push_back(const_reference __x)
14950b57cec5SDimitry Andric{
14960b57cec5SDimitry Andric    if (this->__end_ != this->__end_cap())
14970b57cec5SDimitry Andric    {
1498e40139ffSDimitry Andric        __construct_one_at_end(__x);
14990b57cec5SDimitry Andric    }
15000b57cec5SDimitry Andric    else
15010b57cec5SDimitry Andric        __push_back_slow_path(__x);
15020b57cec5SDimitry Andric}
15030b57cec5SDimitry Andric
15040b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
15050b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
15060b57cec5SDimitry Andricvoid
15070b57cec5SDimitry Andricvector<_Tp, _Allocator>::push_back(value_type&& __x)
15080b57cec5SDimitry Andric{
15090b57cec5SDimitry Andric    if (this->__end_ < this->__end_cap())
15100b57cec5SDimitry Andric    {
1511e40139ffSDimitry Andric        __construct_one_at_end(_VSTD::move(__x));
15120b57cec5SDimitry Andric    }
15130b57cec5SDimitry Andric    else
15140b57cec5SDimitry Andric        __push_back_slow_path(_VSTD::move(__x));
15150b57cec5SDimitry Andric}
15160b57cec5SDimitry Andric
15170b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
15180b57cec5SDimitry Andrictemplate <class... _Args>
15190b57cec5SDimitry Andricvoid
15200b57cec5SDimitry Andricvector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
15210b57cec5SDimitry Andric{
15220b57cec5SDimitry Andric    allocator_type& __a = this->__alloc();
15230b57cec5SDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
15240b57cec5SDimitry Andric//    __v.emplace_back(_VSTD::forward<_Args>(__args)...);
1525480093f4SDimitry Andric    __alloc_traits::construct(__a, _VSTD::__to_address(__v.__end_), _VSTD::forward<_Args>(__args)...);
15260b57cec5SDimitry Andric    __v.__end_++;
15270b57cec5SDimitry Andric    __swap_out_circular_buffer(__v);
15280b57cec5SDimitry Andric}
15290b57cec5SDimitry Andric
15300b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
15310b57cec5SDimitry Andrictemplate <class... _Args>
15320b57cec5SDimitry Andricinline
15330b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
15340b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference
15350b57cec5SDimitry Andric#else
15360b57cec5SDimitry Andricvoid
15370b57cec5SDimitry Andric#endif
15380b57cec5SDimitry Andricvector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
15390b57cec5SDimitry Andric{
15400b57cec5SDimitry Andric    if (this->__end_ < this->__end_cap())
15410b57cec5SDimitry Andric    {
1542e40139ffSDimitry Andric        __construct_one_at_end(_VSTD::forward<_Args>(__args)...);
15430b57cec5SDimitry Andric    }
15440b57cec5SDimitry Andric    else
15450b57cec5SDimitry Andric        __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...);
15460b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
15470b57cec5SDimitry Andric    return this->back();
15480b57cec5SDimitry Andric#endif
15490b57cec5SDimitry Andric}
15500b57cec5SDimitry Andric
15510b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
15520b57cec5SDimitry Andricinline
15530b57cec5SDimitry Andricvoid
15540b57cec5SDimitry Andricvector<_Tp, _Allocator>::pop_back()
15550b57cec5SDimitry Andric{
1556fe6060f1SDimitry Andric    _LIBCPP_ASSERT(!empty(), "vector::pop_back called on an empty vector");
15570b57cec5SDimitry Andric    this->__destruct_at_end(this->__end_ - 1);
15580b57cec5SDimitry Andric}
15590b57cec5SDimitry Andric
15600b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
15610b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
15620b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
15630b57cec5SDimitry Andricvector<_Tp, _Allocator>::erase(const_iterator __position)
15640b57cec5SDimitry Andric{
156504eeddc0SDimitry Andric    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
156604eeddc0SDimitry Andric                         "vector::erase(iterator) called with an iterator not referring to this vector");
15670b57cec5SDimitry Andric    _LIBCPP_ASSERT(__position != end(),
15680b57cec5SDimitry Andric        "vector::erase(iterator) called with a non-dereferenceable iterator");
15690b57cec5SDimitry Andric    difference_type __ps = __position - cbegin();
15700b57cec5SDimitry Andric    pointer __p = this->__begin_ + __ps;
15710b57cec5SDimitry Andric    this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
15720b57cec5SDimitry Andric    this->__invalidate_iterators_past(__p-1);
157381ad6265SDimitry Andric    iterator __r = iterator(this, __p);
15740b57cec5SDimitry Andric    return __r;
15750b57cec5SDimitry Andric}
15760b57cec5SDimitry Andric
15770b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
15780b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
15790b57cec5SDimitry Andricvector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
15800b57cec5SDimitry Andric{
158104eeddc0SDimitry Andric    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__first)) == this,
158204eeddc0SDimitry Andric                         "vector::erase(iterator, iterator) called with an iterator not referring to this vector");
158304eeddc0SDimitry Andric    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__last)) == this,
158404eeddc0SDimitry Andric                         "vector::erase(iterator, iterator) called with an iterator not referring to this vector");
158504eeddc0SDimitry Andric
15860b57cec5SDimitry Andric    _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
15870b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__first - begin());
15880b57cec5SDimitry Andric    if (__first != __last) {
15890b57cec5SDimitry Andric        this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
15900b57cec5SDimitry Andric        this->__invalidate_iterators_past(__p - 1);
15910b57cec5SDimitry Andric    }
159281ad6265SDimitry Andric    iterator __r = iterator(this, __p);
15930b57cec5SDimitry Andric    return __r;
15940b57cec5SDimitry Andric}
15950b57cec5SDimitry Andric
15960b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
15970b57cec5SDimitry Andricvoid
15980b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
15990b57cec5SDimitry Andric{
16000b57cec5SDimitry Andric    pointer __old_last = this->__end_;
16010b57cec5SDimitry Andric    difference_type __n = __old_last - __to;
1602e40139ffSDimitry Andric    {
1603e40139ffSDimitry Andric      pointer __i = __from_s + __n;
1604e40139ffSDimitry Andric      _ConstructTransaction __tx(*this, __from_e - __i);
16055ffd83dbSDimitry Andric      for (pointer __pos = __tx.__pos_; __i < __from_e;
1606349cc55cSDimitry Andric           ++__i, (void) ++__pos, __tx.__pos_ = __pos) {
16070b57cec5SDimitry Andric          __alloc_traits::construct(this->__alloc(),
16085ffd83dbSDimitry Andric                                    _VSTD::__to_address(__pos),
16090b57cec5SDimitry Andric                                    _VSTD::move(*__i));
1610e40139ffSDimitry Andric      }
1611e40139ffSDimitry Andric    }
16120b57cec5SDimitry Andric    _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
16130b57cec5SDimitry Andric}
16140b57cec5SDimitry Andric
16150b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
16160b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
16170b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
16180b57cec5SDimitry Andric{
161904eeddc0SDimitry Andric    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
162004eeddc0SDimitry Andric                         "vector::insert(iterator, x) called with an iterator not referring to this vector");
16210b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__position - begin());
16220b57cec5SDimitry Andric    if (this->__end_ < this->__end_cap())
16230b57cec5SDimitry Andric    {
16240b57cec5SDimitry Andric        if (__p == this->__end_)
16250b57cec5SDimitry Andric        {
1626e40139ffSDimitry Andric            __construct_one_at_end(__x);
16270b57cec5SDimitry Andric        }
16280b57cec5SDimitry Andric        else
16290b57cec5SDimitry Andric        {
16300b57cec5SDimitry Andric            __move_range(__p, this->__end_, __p + 1);
16310b57cec5SDimitry Andric            const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
16320b57cec5SDimitry Andric            if (__p <= __xr && __xr < this->__end_)
16330b57cec5SDimitry Andric                ++__xr;
16340b57cec5SDimitry Andric            *__p = *__xr;
16350b57cec5SDimitry Andric        }
16360b57cec5SDimitry Andric    }
16370b57cec5SDimitry Andric    else
16380b57cec5SDimitry Andric    {
16390b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
16400b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
16410b57cec5SDimitry Andric        __v.push_back(__x);
16420b57cec5SDimitry Andric        __p = __swap_out_circular_buffer(__v, __p);
16430b57cec5SDimitry Andric    }
164481ad6265SDimitry Andric    return iterator(this, __p);
16450b57cec5SDimitry Andric}
16460b57cec5SDimitry Andric
16470b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
16480b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
16490b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
16500b57cec5SDimitry Andric{
165104eeddc0SDimitry Andric    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
165204eeddc0SDimitry Andric                         "vector::insert(iterator, x) called with an iterator not referring to this vector");
16530b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__position - begin());
16540b57cec5SDimitry Andric    if (this->__end_ < this->__end_cap())
16550b57cec5SDimitry Andric    {
16560b57cec5SDimitry Andric        if (__p == this->__end_)
16570b57cec5SDimitry Andric        {
1658e40139ffSDimitry Andric            __construct_one_at_end(_VSTD::move(__x));
16590b57cec5SDimitry Andric        }
16600b57cec5SDimitry Andric        else
16610b57cec5SDimitry Andric        {
16620b57cec5SDimitry Andric            __move_range(__p, this->__end_, __p + 1);
16630b57cec5SDimitry Andric            *__p = _VSTD::move(__x);
16640b57cec5SDimitry Andric        }
16650b57cec5SDimitry Andric    }
16660b57cec5SDimitry Andric    else
16670b57cec5SDimitry Andric    {
16680b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
16690b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
16700b57cec5SDimitry Andric        __v.push_back(_VSTD::move(__x));
16710b57cec5SDimitry Andric        __p = __swap_out_circular_buffer(__v, __p);
16720b57cec5SDimitry Andric    }
167381ad6265SDimitry Andric    return iterator(this, __p);
16740b57cec5SDimitry Andric}
16750b57cec5SDimitry Andric
16760b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
16770b57cec5SDimitry Andrictemplate <class... _Args>
16780b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
16790b57cec5SDimitry Andricvector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
16800b57cec5SDimitry Andric{
168104eeddc0SDimitry Andric    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
168204eeddc0SDimitry Andric                         "vector::emplace(iterator, x) called with an iterator not referring to this vector");
16830b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__position - begin());
16840b57cec5SDimitry Andric    if (this->__end_ < this->__end_cap())
16850b57cec5SDimitry Andric    {
16860b57cec5SDimitry Andric        if (__p == this->__end_)
16870b57cec5SDimitry Andric        {
1688e40139ffSDimitry Andric            __construct_one_at_end(_VSTD::forward<_Args>(__args)...);
16890b57cec5SDimitry Andric        }
16900b57cec5SDimitry Andric        else
16910b57cec5SDimitry Andric        {
16920b57cec5SDimitry Andric            __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...);
16930b57cec5SDimitry Andric            __move_range(__p, this->__end_, __p + 1);
16940b57cec5SDimitry Andric            *__p = _VSTD::move(__tmp.get());
16950b57cec5SDimitry Andric        }
16960b57cec5SDimitry Andric    }
16970b57cec5SDimitry Andric    else
16980b57cec5SDimitry Andric    {
16990b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
17000b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
17010b57cec5SDimitry Andric        __v.emplace_back(_VSTD::forward<_Args>(__args)...);
17020b57cec5SDimitry Andric        __p = __swap_out_circular_buffer(__v, __p);
17030b57cec5SDimitry Andric    }
170481ad6265SDimitry Andric    return iterator(this, __p);
17050b57cec5SDimitry Andric}
17060b57cec5SDimitry Andric
17070b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
17080b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
17090b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
17100b57cec5SDimitry Andric{
171104eeddc0SDimitry Andric    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
171204eeddc0SDimitry Andric                         "vector::insert(iterator, n, x) called with an iterator not referring to this vector");
17130b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__position - begin());
17140b57cec5SDimitry Andric    if (__n > 0)
17150b57cec5SDimitry Andric    {
17160b57cec5SDimitry Andric        if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
17170b57cec5SDimitry Andric        {
17180b57cec5SDimitry Andric            size_type __old_n = __n;
17190b57cec5SDimitry Andric            pointer __old_last = this->__end_;
17200b57cec5SDimitry Andric            if (__n > static_cast<size_type>(this->__end_ - __p))
17210b57cec5SDimitry Andric            {
17220b57cec5SDimitry Andric                size_type __cx = __n - (this->__end_ - __p);
17230b57cec5SDimitry Andric                __construct_at_end(__cx, __x);
17240b57cec5SDimitry Andric                __n -= __cx;
17250b57cec5SDimitry Andric            }
17260b57cec5SDimitry Andric            if (__n > 0)
17270b57cec5SDimitry Andric            {
17280b57cec5SDimitry Andric                __move_range(__p, __old_last, __p + __old_n);
17290b57cec5SDimitry Andric                const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
17300b57cec5SDimitry Andric                if (__p <= __xr && __xr < this->__end_)
17310b57cec5SDimitry Andric                    __xr += __old_n;
17320b57cec5SDimitry Andric                _VSTD::fill_n(__p, __n, *__xr);
17330b57cec5SDimitry Andric            }
17340b57cec5SDimitry Andric        }
17350b57cec5SDimitry Andric        else
17360b57cec5SDimitry Andric        {
17370b57cec5SDimitry Andric            allocator_type& __a = this->__alloc();
17380b57cec5SDimitry Andric            __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
17390b57cec5SDimitry Andric            __v.__construct_at_end(__n, __x);
17400b57cec5SDimitry Andric            __p = __swap_out_circular_buffer(__v, __p);
17410b57cec5SDimitry Andric        }
17420b57cec5SDimitry Andric    }
174381ad6265SDimitry Andric    return iterator(this, __p);
17440b57cec5SDimitry Andric}
17450b57cec5SDimitry Andric
17460b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
17470b57cec5SDimitry Andrictemplate <class _InputIterator>
1748753f127fSDimitry Andrictypename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
17490b57cec5SDimitry Andric    is_constructible<
17500b57cec5SDimitry Andric       _Tp,
17510b57cec5SDimitry Andric       typename iterator_traits<_InputIterator>::reference>::value,
17520b57cec5SDimitry Andric    typename vector<_Tp, _Allocator>::iterator
17530b57cec5SDimitry Andric>::type
17540b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
17550b57cec5SDimitry Andric{
175604eeddc0SDimitry Andric    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
175704eeddc0SDimitry Andric                         "vector::insert(iterator, range) called with an iterator not referring to this vector");
17580b57cec5SDimitry Andric    difference_type __off = __position - begin();
17590b57cec5SDimitry Andric    pointer __p = this->__begin_ + __off;
17600b57cec5SDimitry Andric    allocator_type& __a = this->__alloc();
17610b57cec5SDimitry Andric    pointer __old_last = this->__end_;
17620b57cec5SDimitry Andric    for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
17630b57cec5SDimitry Andric    {
1764e40139ffSDimitry Andric        __construct_one_at_end(*__first);
17650b57cec5SDimitry Andric    }
17660b57cec5SDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__a);
17670b57cec5SDimitry Andric    if (__first != __last)
17680b57cec5SDimitry Andric    {
17690b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
17700b57cec5SDimitry Andric        try
17710b57cec5SDimitry Andric        {
17720b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
17730b57cec5SDimitry Andric            __v.__construct_at_end(__first, __last);
17740b57cec5SDimitry Andric            difference_type __old_size = __old_last - this->__begin_;
17750b57cec5SDimitry Andric            difference_type __old_p = __p - this->__begin_;
17760b57cec5SDimitry Andric            reserve(__recommend(size() + __v.size()));
17770b57cec5SDimitry Andric            __p = this->__begin_ + __old_p;
17780b57cec5SDimitry Andric            __old_last = this->__begin_ + __old_size;
17790b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
17800b57cec5SDimitry Andric        }
17810b57cec5SDimitry Andric        catch (...)
17820b57cec5SDimitry Andric        {
178381ad6265SDimitry Andric            erase(iterator(this, __old_last), end());
17840b57cec5SDimitry Andric            throw;
17850b57cec5SDimitry Andric        }
17860b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
17870b57cec5SDimitry Andric    }
17880b57cec5SDimitry Andric    __p = _VSTD::rotate(__p, __old_last, this->__end_);
178981ad6265SDimitry Andric    insert(iterator(this, __p), _VSTD::make_move_iterator(__v.begin()),
17905ffd83dbSDimitry Andric                                _VSTD::make_move_iterator(__v.end()));
17910b57cec5SDimitry Andric    return begin() + __off;
17920b57cec5SDimitry Andric}
17930b57cec5SDimitry Andric
17940b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
17950b57cec5SDimitry Andrictemplate <class _ForwardIterator>
17960b57cec5SDimitry Andrictypename enable_if
17970b57cec5SDimitry Andric<
1798480093f4SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value &&
17990b57cec5SDimitry Andric    is_constructible<
18000b57cec5SDimitry Andric       _Tp,
18010b57cec5SDimitry Andric       typename iterator_traits<_ForwardIterator>::reference>::value,
18020b57cec5SDimitry Andric    typename vector<_Tp, _Allocator>::iterator
18030b57cec5SDimitry Andric>::type
18040b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
18050b57cec5SDimitry Andric{
180604eeddc0SDimitry Andric    _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this,
180704eeddc0SDimitry Andric                         "vector::insert(iterator, range) called with an iterator not referring to this vector");
18080b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__position - begin());
18090b57cec5SDimitry Andric    difference_type __n = _VSTD::distance(__first, __last);
18100b57cec5SDimitry Andric    if (__n > 0)
18110b57cec5SDimitry Andric    {
18120b57cec5SDimitry Andric        if (__n <= this->__end_cap() - this->__end_)
18130b57cec5SDimitry Andric        {
18140b57cec5SDimitry Andric            size_type __old_n = __n;
18150b57cec5SDimitry Andric            pointer __old_last = this->__end_;
18160b57cec5SDimitry Andric            _ForwardIterator __m = __last;
18170b57cec5SDimitry Andric            difference_type __dx = this->__end_ - __p;
18180b57cec5SDimitry Andric            if (__n > __dx)
18190b57cec5SDimitry Andric            {
18200b57cec5SDimitry Andric                __m = __first;
18210b57cec5SDimitry Andric                difference_type __diff = this->__end_ - __p;
18220b57cec5SDimitry Andric                _VSTD::advance(__m, __diff);
18230b57cec5SDimitry Andric                __construct_at_end(__m, __last, __n - __diff);
18240b57cec5SDimitry Andric                __n = __dx;
18250b57cec5SDimitry Andric            }
18260b57cec5SDimitry Andric            if (__n > 0)
18270b57cec5SDimitry Andric            {
18280b57cec5SDimitry Andric                __move_range(__p, __old_last, __p + __old_n);
18290b57cec5SDimitry Andric                _VSTD::copy(__first, __m, __p);
18300b57cec5SDimitry Andric            }
18310b57cec5SDimitry Andric        }
18320b57cec5SDimitry Andric        else
18330b57cec5SDimitry Andric        {
18340b57cec5SDimitry Andric            allocator_type& __a = this->__alloc();
18350b57cec5SDimitry Andric            __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
18360b57cec5SDimitry Andric            __v.__construct_at_end(__first, __last);
18370b57cec5SDimitry Andric            __p = __swap_out_circular_buffer(__v, __p);
18380b57cec5SDimitry Andric        }
18390b57cec5SDimitry Andric    }
184081ad6265SDimitry Andric    return iterator(this, __p);
18410b57cec5SDimitry Andric}
18420b57cec5SDimitry Andric
18430b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
18440b57cec5SDimitry Andricvoid
18450b57cec5SDimitry Andricvector<_Tp, _Allocator>::resize(size_type __sz)
18460b57cec5SDimitry Andric{
18470b57cec5SDimitry Andric    size_type __cs = size();
18480b57cec5SDimitry Andric    if (__cs < __sz)
18490b57cec5SDimitry Andric        this->__append(__sz - __cs);
18500b57cec5SDimitry Andric    else if (__cs > __sz)
18510b57cec5SDimitry Andric        this->__destruct_at_end(this->__begin_ + __sz);
18520b57cec5SDimitry Andric}
18530b57cec5SDimitry Andric
18540b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
18550b57cec5SDimitry Andricvoid
18560b57cec5SDimitry Andricvector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
18570b57cec5SDimitry Andric{
18580b57cec5SDimitry Andric    size_type __cs = size();
18590b57cec5SDimitry Andric    if (__cs < __sz)
18600b57cec5SDimitry Andric        this->__append(__sz - __cs, __x);
18610b57cec5SDimitry Andric    else if (__cs > __sz)
18620b57cec5SDimitry Andric        this->__destruct_at_end(this->__begin_ + __sz);
18630b57cec5SDimitry Andric}
18640b57cec5SDimitry Andric
18650b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
18660b57cec5SDimitry Andricvoid
18670b57cec5SDimitry Andricvector<_Tp, _Allocator>::swap(vector& __x)
18680b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
18690b57cec5SDimitry Andric    _NOEXCEPT
18700b57cec5SDimitry Andric#else
18710b57cec5SDimitry Andric    _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
18720b57cec5SDimitry Andric                __is_nothrow_swappable<allocator_type>::value)
18730b57cec5SDimitry Andric#endif
18740b57cec5SDimitry Andric{
18750b57cec5SDimitry Andric    _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
18760b57cec5SDimitry Andric                   this->__alloc() == __x.__alloc(),
18770b57cec5SDimitry Andric                   "vector::swap: Either propagate_on_container_swap must be true"
18780b57cec5SDimitry Andric                   " or the allocators must compare equal");
18790b57cec5SDimitry Andric    _VSTD::swap(this->__begin_, __x.__begin_);
18800b57cec5SDimitry Andric    _VSTD::swap(this->__end_, __x.__end_);
18810b57cec5SDimitry Andric    _VSTD::swap(this->__end_cap(), __x.__end_cap());
1882e8d8bef9SDimitry Andric    _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(),
18830b57cec5SDimitry Andric        integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>());
188481ad6265SDimitry Andric    std::__debug_db_swap(this, std::addressof(__x));
18850b57cec5SDimitry Andric}
18860b57cec5SDimitry Andric
18870b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
18880b57cec5SDimitry Andricbool
18890b57cec5SDimitry Andricvector<_Tp, _Allocator>::__invariants() const
18900b57cec5SDimitry Andric{
18910b57cec5SDimitry Andric    if (this->__begin_ == nullptr)
18920b57cec5SDimitry Andric    {
18930b57cec5SDimitry Andric        if (this->__end_ != nullptr || this->__end_cap() != nullptr)
18940b57cec5SDimitry Andric            return false;
18950b57cec5SDimitry Andric    }
18960b57cec5SDimitry Andric    else
18970b57cec5SDimitry Andric    {
18980b57cec5SDimitry Andric        if (this->__begin_ > this->__end_)
18990b57cec5SDimitry Andric            return false;
19000b57cec5SDimitry Andric        if (this->__begin_ == this->__end_cap())
19010b57cec5SDimitry Andric            return false;
19020b57cec5SDimitry Andric        if (this->__end_ > this->__end_cap())
19030b57cec5SDimitry Andric            return false;
19040b57cec5SDimitry Andric    }
19050b57cec5SDimitry Andric    return true;
19060b57cec5SDimitry Andric}
19070b57cec5SDimitry Andric
190881ad6265SDimitry Andric#ifdef _LIBCPP_ENABLE_DEBUG_MODE
19090b57cec5SDimitry Andric
19100b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
19110b57cec5SDimitry Andricbool
19120b57cec5SDimitry Andricvector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
19130b57cec5SDimitry Andric{
19140b57cec5SDimitry Andric    return this->__begin_ <= __i->base() && __i->base() < this->__end_;
19150b57cec5SDimitry Andric}
19160b57cec5SDimitry Andric
19170b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
19180b57cec5SDimitry Andricbool
19190b57cec5SDimitry Andricvector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
19200b57cec5SDimitry Andric{
19210b57cec5SDimitry Andric    return this->__begin_ < __i->base() && __i->base() <= this->__end_;
19220b57cec5SDimitry Andric}
19230b57cec5SDimitry Andric
19240b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
19250b57cec5SDimitry Andricbool
19260b57cec5SDimitry Andricvector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
19270b57cec5SDimitry Andric{
19280b57cec5SDimitry Andric    const_pointer __p = __i->base() + __n;
19290b57cec5SDimitry Andric    return this->__begin_ <= __p && __p <= this->__end_;
19300b57cec5SDimitry Andric}
19310b57cec5SDimitry Andric
19320b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
19330b57cec5SDimitry Andricbool
19340b57cec5SDimitry Andricvector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
19350b57cec5SDimitry Andric{
19360b57cec5SDimitry Andric    const_pointer __p = __i->base() + __n;
19370b57cec5SDimitry Andric    return this->__begin_ <= __p && __p < this->__end_;
19380b57cec5SDimitry Andric}
19390b57cec5SDimitry Andric
194081ad6265SDimitry Andric#endif // _LIBCPP_ENABLE_DEBUG_MODE
19410b57cec5SDimitry Andric
19420b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
19430b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
19440b57cec5SDimitry Andricvoid
19450b57cec5SDimitry Andricvector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) {
194681ad6265SDimitry Andric#ifdef _LIBCPP_ENABLE_DEBUG_MODE
19470b57cec5SDimitry Andric  __c_node* __c = __get_db()->__find_c_and_lock(this);
19480b57cec5SDimitry Andric  for (__i_node** __p = __c->end_; __p != __c->beg_; ) {
19490b57cec5SDimitry Andric    --__p;
19500b57cec5SDimitry Andric    const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
19510b57cec5SDimitry Andric    if (__i->base() > __new_last) {
19520b57cec5SDimitry Andric      (*__p)->__c_ = nullptr;
19530b57cec5SDimitry Andric      if (--__c->end_ != __p)
1954e8d8bef9SDimitry Andric        _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
19550b57cec5SDimitry Andric    }
19560b57cec5SDimitry Andric  }
19570b57cec5SDimitry Andric  __get_db()->unlock();
19580b57cec5SDimitry Andric#else
19590b57cec5SDimitry Andric  ((void)__new_last);
19600b57cec5SDimitry Andric#endif
19610b57cec5SDimitry Andric}
19620b57cec5SDimitry Andric
19630b57cec5SDimitry Andric// vector<bool>
19640b57cec5SDimitry Andric
19650b57cec5SDimitry Andrictemplate <class _Allocator> class vector<bool, _Allocator>;
19660b57cec5SDimitry Andric
19670b57cec5SDimitry Andrictemplate <class _Allocator> struct hash<vector<bool, _Allocator> >;
19680b57cec5SDimitry Andric
19690b57cec5SDimitry Andrictemplate <class _Allocator>
19700b57cec5SDimitry Andricstruct __has_storage_type<vector<bool, _Allocator> >
19710b57cec5SDimitry Andric{
19720b57cec5SDimitry Andric    static const bool value = true;
19730b57cec5SDimitry Andric};
19740b57cec5SDimitry Andric
19750b57cec5SDimitry Andrictemplate <class _Allocator>
19760b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator>
19770b57cec5SDimitry Andric{
19780b57cec5SDimitry Andricpublic:
19790b57cec5SDimitry Andric    typedef vector                                   __self;
19800b57cec5SDimitry Andric    typedef bool                                     value_type;
19810b57cec5SDimitry Andric    typedef _Allocator                               allocator_type;
19820b57cec5SDimitry Andric    typedef allocator_traits<allocator_type>         __alloc_traits;
19830b57cec5SDimitry Andric    typedef typename __alloc_traits::size_type       size_type;
19840b57cec5SDimitry Andric    typedef typename __alloc_traits::difference_type difference_type;
19850b57cec5SDimitry Andric    typedef size_type __storage_type;
19860b57cec5SDimitry Andric    typedef __bit_iterator<vector, false>            pointer;
19870b57cec5SDimitry Andric    typedef __bit_iterator<vector, true>             const_pointer;
19880b57cec5SDimitry Andric    typedef pointer                                  iterator;
19890b57cec5SDimitry Andric    typedef const_pointer                            const_iterator;
19900b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<iterator>         reverse_iterator;
19910b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<const_iterator>   const_reverse_iterator;
19920b57cec5SDimitry Andric
19930b57cec5SDimitry Andricprivate:
19940b57cec5SDimitry Andric    typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator;
19950b57cec5SDimitry Andric    typedef allocator_traits<__storage_allocator>    __storage_traits;
19960b57cec5SDimitry Andric    typedef typename __storage_traits::pointer       __storage_pointer;
19970b57cec5SDimitry Andric    typedef typename __storage_traits::const_pointer __const_storage_pointer;
19980b57cec5SDimitry Andric
19990b57cec5SDimitry Andric    __storage_pointer                                      __begin_;
20000b57cec5SDimitry Andric    size_type                                              __size_;
20010b57cec5SDimitry Andric    __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
20020b57cec5SDimitry Andricpublic:
20030b57cec5SDimitry Andric    typedef __bit_reference<vector>                  reference;
200481ad6265SDimitry Andric#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
200581ad6265SDimitry Andric    using const_reference = bool;
200681ad6265SDimitry Andric#else
20070b57cec5SDimitry Andric    typedef __bit_const_reference<vector>            const_reference;
200881ad6265SDimitry Andric#endif
20090b57cec5SDimitry Andricprivate:
20100b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20110b57cec5SDimitry Andric    size_type& __cap() _NOEXCEPT
20120b57cec5SDimitry Andric        {return __cap_alloc_.first();}
20130b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20140b57cec5SDimitry Andric    const size_type& __cap() const _NOEXCEPT
20150b57cec5SDimitry Andric        {return __cap_alloc_.first();}
20160b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20170b57cec5SDimitry Andric    __storage_allocator& __alloc() _NOEXCEPT
20180b57cec5SDimitry Andric        {return __cap_alloc_.second();}
20190b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20200b57cec5SDimitry Andric    const __storage_allocator& __alloc() const _NOEXCEPT
20210b57cec5SDimitry Andric        {return __cap_alloc_.second();}
20220b57cec5SDimitry Andric
20230b57cec5SDimitry Andric    static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
20240b57cec5SDimitry Andric
20250b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20260b57cec5SDimitry Andric    static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
20270b57cec5SDimitry Andric        {return __n * __bits_per_word;}
20280b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20290b57cec5SDimitry Andric    static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
20300b57cec5SDimitry Andric        {return (__n - 1) / __bits_per_word + 1;}
20310b57cec5SDimitry Andric
20320b57cec5SDimitry Andricpublic:
20330b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20340b57cec5SDimitry Andric    vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
20350b57cec5SDimitry Andric
20360b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
20370b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
20380b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
20390b57cec5SDimitry Andric#else
20400b57cec5SDimitry Andric        _NOEXCEPT;
20410b57cec5SDimitry Andric#endif
20420b57cec5SDimitry Andric    ~vector();
20430b57cec5SDimitry Andric    explicit vector(size_type __n);
20440b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
20450b57cec5SDimitry Andric    explicit vector(size_type __n, const allocator_type& __a);
20460b57cec5SDimitry Andric#endif
20470b57cec5SDimitry Andric    vector(size_type __n, const value_type& __v);
20480b57cec5SDimitry Andric    vector(size_type __n, const value_type& __v, const allocator_type& __a);
20490b57cec5SDimitry Andric    template <class _InputIterator>
20500b57cec5SDimitry Andric        vector(_InputIterator __first, _InputIterator __last,
2051753f127fSDimitry Andric               typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type* = 0);
20520b57cec5SDimitry Andric    template <class _InputIterator>
20530b57cec5SDimitry Andric        vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2054753f127fSDimitry Andric               typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type* = 0);
20550b57cec5SDimitry Andric    template <class _ForwardIterator>
20560b57cec5SDimitry Andric        vector(_ForwardIterator __first, _ForwardIterator __last,
2057480093f4SDimitry Andric               typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0);
20580b57cec5SDimitry Andric    template <class _ForwardIterator>
20590b57cec5SDimitry Andric        vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2060480093f4SDimitry Andric               typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0);
20610b57cec5SDimitry Andric
20620b57cec5SDimitry Andric    vector(const vector& __v);
20630b57cec5SDimitry Andric    vector(const vector& __v, const allocator_type& __a);
20640b57cec5SDimitry Andric    vector& operator=(const vector& __v);
20650b57cec5SDimitry Andric
20660b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
20670b57cec5SDimitry Andric    vector(initializer_list<value_type> __il);
20680b57cec5SDimitry Andric    vector(initializer_list<value_type> __il, const allocator_type& __a);
20690b57cec5SDimitry Andric
20700b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
20710b57cec5SDimitry Andric    vector& operator=(initializer_list<value_type> __il)
20720b57cec5SDimitry Andric        {assign(__il.begin(), __il.end()); return *this;}
20730b57cec5SDimitry Andric
20740b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG
20750b57cec5SDimitry Andric
207681ad6265SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
207781ad6265SDimitry Andric    vector(vector&& __v)
207881ad6265SDimitry Andric#if _LIBCPP_STD_VER > 14
207981ad6265SDimitry Andric        noexcept;
208081ad6265SDimitry Andric#else
208181ad6265SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
208281ad6265SDimitry Andric#endif
208381ad6265SDimitry Andric    vector(vector&& __v, const __type_identity_t<allocator_type>& __a);
208481ad6265SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
208581ad6265SDimitry Andric    vector& operator=(vector&& __v)
208681ad6265SDimitry Andric        _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
208781ad6265SDimitry Andric
20880b57cec5SDimitry Andric    template <class _InputIterator>
2089753f127fSDimitry Andric        typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
20900b57cec5SDimitry Andric           void
20910b57cec5SDimitry Andric        >::type
20920b57cec5SDimitry Andric        assign(_InputIterator __first, _InputIterator __last);
20930b57cec5SDimitry Andric    template <class _ForwardIterator>
20940b57cec5SDimitry Andric        typename enable_if
20950b57cec5SDimitry Andric        <
2096480093f4SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value,
20970b57cec5SDimitry Andric           void
20980b57cec5SDimitry Andric        >::type
20990b57cec5SDimitry Andric        assign(_ForwardIterator __first, _ForwardIterator __last);
21000b57cec5SDimitry Andric
21010b57cec5SDimitry Andric    void assign(size_type __n, const value_type& __x);
21020b57cec5SDimitry Andric
21030b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
21040b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21050b57cec5SDimitry Andric    void assign(initializer_list<value_type> __il)
21060b57cec5SDimitry Andric        {assign(__il.begin(), __il.end());}
21070b57cec5SDimitry Andric#endif
21080b57cec5SDimitry Andric
21090b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
21100b57cec5SDimitry Andric        {return allocator_type(this->__alloc());}
21110b57cec5SDimitry Andric
21120b57cec5SDimitry Andric    size_type max_size() const _NOEXCEPT;
21130b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21140b57cec5SDimitry Andric    size_type capacity() const _NOEXCEPT
21150b57cec5SDimitry Andric        {return __internal_cap_to_external(__cap());}
21160b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21170b57cec5SDimitry Andric    size_type size() const _NOEXCEPT
21180b57cec5SDimitry Andric        {return __size_;}
21190b57cec5SDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
21200b57cec5SDimitry Andric    bool empty() const _NOEXCEPT
21210b57cec5SDimitry Andric        {return __size_ == 0;}
21220b57cec5SDimitry Andric    void reserve(size_type __n);
21230b57cec5SDimitry Andric    void shrink_to_fit() _NOEXCEPT;
21240b57cec5SDimitry Andric
21250b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21260b57cec5SDimitry Andric    iterator begin() _NOEXCEPT
21270b57cec5SDimitry Andric        {return __make_iter(0);}
21280b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21290b57cec5SDimitry Andric    const_iterator begin() const _NOEXCEPT
21300b57cec5SDimitry Andric        {return __make_iter(0);}
21310b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21320b57cec5SDimitry Andric    iterator end() _NOEXCEPT
21330b57cec5SDimitry Andric        {return __make_iter(__size_);}
21340b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21350b57cec5SDimitry Andric    const_iterator end()   const _NOEXCEPT
21360b57cec5SDimitry Andric        {return __make_iter(__size_);}
21370b57cec5SDimitry Andric
21380b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21390b57cec5SDimitry Andric    reverse_iterator rbegin() _NOEXCEPT
21400b57cec5SDimitry Andric        {return       reverse_iterator(end());}
21410b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21420b57cec5SDimitry Andric    const_reverse_iterator rbegin() const _NOEXCEPT
21430b57cec5SDimitry Andric        {return const_reverse_iterator(end());}
21440b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21450b57cec5SDimitry Andric    reverse_iterator rend() _NOEXCEPT
21460b57cec5SDimitry Andric        {return       reverse_iterator(begin());}
21470b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21480b57cec5SDimitry Andric    const_reverse_iterator rend()   const _NOEXCEPT
21490b57cec5SDimitry Andric        {return const_reverse_iterator(begin());}
21500b57cec5SDimitry Andric
21510b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21520b57cec5SDimitry Andric    const_iterator         cbegin()  const _NOEXCEPT
21530b57cec5SDimitry Andric        {return __make_iter(0);}
21540b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21550b57cec5SDimitry Andric    const_iterator         cend()    const _NOEXCEPT
21560b57cec5SDimitry Andric        {return __make_iter(__size_);}
21570b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21580b57cec5SDimitry Andric    const_reverse_iterator crbegin() const _NOEXCEPT
21590b57cec5SDimitry Andric        {return rbegin();}
21600b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21610b57cec5SDimitry Andric    const_reverse_iterator crend()   const _NOEXCEPT
21620b57cec5SDimitry Andric        {return rend();}
21630b57cec5SDimitry Andric
21640b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY reference       operator[](size_type __n)       {return __make_ref(__n);}
21650b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
21660b57cec5SDimitry Andric    reference       at(size_type __n);
21670b57cec5SDimitry Andric    const_reference at(size_type __n) const;
21680b57cec5SDimitry Andric
21690b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY reference       front()       {return __make_ref(0);}
21700b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
21710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY reference       back()        {return __make_ref(__size_ - 1);}
21720b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const_reference back()  const {return __make_ref(__size_ - 1);}
21730b57cec5SDimitry Andric
21740b57cec5SDimitry Andric    void push_back(const value_type& __x);
21750b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
21760b57cec5SDimitry Andric    template <class... _Args>
21770b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
21780b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY reference emplace_back(_Args&&... __args)
21790b57cec5SDimitry Andric#else
21800b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void      emplace_back(_Args&&... __args)
21810b57cec5SDimitry Andric#endif
21820b57cec5SDimitry Andric    {
21830b57cec5SDimitry Andric        push_back ( value_type ( _VSTD::forward<_Args>(__args)... ));
21840b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
21850b57cec5SDimitry Andric        return this->back();
21860b57cec5SDimitry Andric#endif
21870b57cec5SDimitry Andric    }
21880b57cec5SDimitry Andric#endif
21890b57cec5SDimitry Andric
21900b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
21910b57cec5SDimitry Andric
21920b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
21930b57cec5SDimitry Andric    template <class... _Args>
2194753f127fSDimitry Andric   _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator __position, _Args&&... __args)
2195753f127fSDimitry Andric        { return insert ( __position, value_type ( _VSTD::forward<_Args>(__args)... )); }
21960b57cec5SDimitry Andric#endif
21970b57cec5SDimitry Andric
21980b57cec5SDimitry Andric    iterator insert(const_iterator __position, const value_type& __x);
21990b57cec5SDimitry Andric    iterator insert(const_iterator __position, size_type __n, const value_type& __x);
22000b57cec5SDimitry Andric    template <class _InputIterator>
2201753f127fSDimitry Andric        typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
22020b57cec5SDimitry Andric            iterator
22030b57cec5SDimitry Andric        >::type
22040b57cec5SDimitry Andric        insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
22050b57cec5SDimitry Andric    template <class _ForwardIterator>
22060b57cec5SDimitry Andric        typename enable_if
22070b57cec5SDimitry Andric        <
2208480093f4SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value,
22090b57cec5SDimitry Andric            iterator
22100b57cec5SDimitry Andric        >::type
22110b57cec5SDimitry Andric        insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
22120b57cec5SDimitry Andric
22130b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
22140b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
22150b57cec5SDimitry Andric    iterator insert(const_iterator __position, initializer_list<value_type> __il)
22160b57cec5SDimitry Andric        {return insert(__position, __il.begin(), __il.end());}
22170b57cec5SDimitry Andric#endif
22180b57cec5SDimitry Andric
22190b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
22200b57cec5SDimitry Andric    iterator erase(const_iterator __first, const_iterator __last);
22210b57cec5SDimitry Andric
22220b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
22230b57cec5SDimitry Andric    void clear() _NOEXCEPT {__size_ = 0;}
22240b57cec5SDimitry Andric
22250b57cec5SDimitry Andric    void swap(vector&)
22260b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
22270b57cec5SDimitry Andric        _NOEXCEPT;
22280b57cec5SDimitry Andric#else
22290b57cec5SDimitry Andric        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
22300b57cec5SDimitry Andric                    __is_nothrow_swappable<allocator_type>::value);
22310b57cec5SDimitry Andric#endif
22320b57cec5SDimitry Andric    static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); }
22330b57cec5SDimitry Andric
22340b57cec5SDimitry Andric    void resize(size_type __sz, value_type __x = false);
22350b57cec5SDimitry Andric    void flip() _NOEXCEPT;
22360b57cec5SDimitry Andric
22370b57cec5SDimitry Andric    bool __invariants() const;
22380b57cec5SDimitry Andric
22390b57cec5SDimitry Andricprivate:
2240d56accc7SDimitry Andric    _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
2241d56accc7SDimitry Andric    void __throw_length_error() const {
2242d56accc7SDimitry Andric        _VSTD::__throw_length_error("vector");
2243d56accc7SDimitry Andric    }
2244d56accc7SDimitry Andric
2245d56accc7SDimitry Andric    _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
2246d56accc7SDimitry Andric    void __throw_out_of_range() const {
2247d56accc7SDimitry Andric        _VSTD::__throw_out_of_range("vector");
2248d56accc7SDimitry Andric    }
2249d56accc7SDimitry Andric
225081ad6265SDimitry Andric    //  Allocate space for __n objects
225181ad6265SDimitry Andric    //  throws length_error if __n > max_size()
225281ad6265SDimitry Andric    //  throws (probably bad_alloc) if memory run out
225381ad6265SDimitry Andric    //  Precondition:  __begin_ == __end_ == __cap() == 0
225481ad6265SDimitry Andric    //  Precondition:  __n > 0
225581ad6265SDimitry Andric    //  Postcondition:  capacity() >= __n
225681ad6265SDimitry Andric    //  Postcondition:  size() == 0
225781ad6265SDimitry Andric    _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) {
225881ad6265SDimitry Andric        if (__n > max_size())
225981ad6265SDimitry Andric            __throw_length_error();
226081ad6265SDimitry Andric        auto __allocation = std::__allocate_at_least(__alloc(), __external_cap_to_internal(__n));
226181ad6265SDimitry Andric        __begin_ = __allocation.ptr;
226281ad6265SDimitry Andric        __size_ = 0;
226381ad6265SDimitry Andric        __cap() = __allocation.count;
226481ad6265SDimitry Andric    }
226581ad6265SDimitry Andric
22660b57cec5SDimitry Andric    void __vdeallocate() _NOEXCEPT;
22670b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
22680b57cec5SDimitry Andric    static size_type __align_it(size_type __new_size) _NOEXCEPT
226981ad6265SDimitry Andric        {return (__new_size + (__bits_per_word-1)) & ~((size_type)__bits_per_word-1);}
22700b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY  size_type __recommend(size_type __new_size) const;
22710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
22720b57cec5SDimitry Andric    template <class _ForwardIterator>
22730b57cec5SDimitry Andric        typename enable_if
22740b57cec5SDimitry Andric        <
2275480093f4SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value,
22760b57cec5SDimitry Andric            void
22770b57cec5SDimitry Andric        >::type
22780b57cec5SDimitry Andric        __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
22790b57cec5SDimitry Andric    void __append(size_type __n, const_reference __x);
22800b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
22810b57cec5SDimitry Andric    reference __make_ref(size_type __pos) _NOEXCEPT
22820b57cec5SDimitry Andric        {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
22830b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
228481ad6265SDimitry Andric    const_reference __make_ref(size_type __pos) const _NOEXCEPT {
228581ad6265SDimitry Andric        return __bit_const_reference<vector>(__begin_ + __pos / __bits_per_word,
228681ad6265SDimitry Andric                                             __storage_type(1) << __pos % __bits_per_word);
228781ad6265SDimitry Andric    }
22880b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
22890b57cec5SDimitry Andric    iterator __make_iter(size_type __pos) _NOEXCEPT
22900b57cec5SDimitry Andric        {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
22910b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
22920b57cec5SDimitry Andric    const_iterator __make_iter(size_type __pos) const _NOEXCEPT
22930b57cec5SDimitry Andric        {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
22940b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
22950b57cec5SDimitry Andric    iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
22960b57cec5SDimitry Andric        {return begin() + (__p - cbegin());}
22970b57cec5SDimitry Andric
22980b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
22990b57cec5SDimitry Andric    void __copy_assign_alloc(const vector& __v)
23000b57cec5SDimitry Andric        {__copy_assign_alloc(__v, integral_constant<bool,
23010b57cec5SDimitry Andric                      __storage_traits::propagate_on_container_copy_assignment::value>());}
23020b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23030b57cec5SDimitry Andric    void __copy_assign_alloc(const vector& __c, true_type)
23040b57cec5SDimitry Andric        {
23050b57cec5SDimitry Andric            if (__alloc() != __c.__alloc())
23060b57cec5SDimitry Andric                __vdeallocate();
23070b57cec5SDimitry Andric            __alloc() = __c.__alloc();
23080b57cec5SDimitry Andric        }
23090b57cec5SDimitry Andric
23100b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23110b57cec5SDimitry Andric    void __copy_assign_alloc(const vector&, false_type)
23120b57cec5SDimitry Andric        {}
23130b57cec5SDimitry Andric
23140b57cec5SDimitry Andric    void __move_assign(vector& __c, false_type);
23150b57cec5SDimitry Andric    void __move_assign(vector& __c, true_type)
23160b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
23170b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23180b57cec5SDimitry Andric    void __move_assign_alloc(vector& __c)
23190b57cec5SDimitry Andric        _NOEXCEPT_(
23200b57cec5SDimitry Andric            !__storage_traits::propagate_on_container_move_assignment::value ||
23210b57cec5SDimitry Andric            is_nothrow_move_assignable<allocator_type>::value)
23220b57cec5SDimitry Andric        {__move_assign_alloc(__c, integral_constant<bool,
23230b57cec5SDimitry Andric                      __storage_traits::propagate_on_container_move_assignment::value>());}
23240b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23250b57cec5SDimitry Andric    void __move_assign_alloc(vector& __c, true_type)
23260b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
23270b57cec5SDimitry Andric        {
23280b57cec5SDimitry Andric            __alloc() = _VSTD::move(__c.__alloc());
23290b57cec5SDimitry Andric        }
23300b57cec5SDimitry Andric
23310b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23320b57cec5SDimitry Andric    void __move_assign_alloc(vector&, false_type)
23330b57cec5SDimitry Andric        _NOEXCEPT
23340b57cec5SDimitry Andric        {}
23350b57cec5SDimitry Andric
23360b57cec5SDimitry Andric    size_t __hash_code() const _NOEXCEPT;
23370b57cec5SDimitry Andric
23380b57cec5SDimitry Andric    friend class __bit_reference<vector>;
23390b57cec5SDimitry Andric    friend class __bit_const_reference<vector>;
23400b57cec5SDimitry Andric    friend class __bit_iterator<vector, false>;
23410b57cec5SDimitry Andric    friend class __bit_iterator<vector, true>;
23420b57cec5SDimitry Andric    friend struct __bit_array<vector>;
23430b57cec5SDimitry Andric    friend struct _LIBCPP_TEMPLATE_VIS hash<vector>;
23440b57cec5SDimitry Andric};
23450b57cec5SDimitry Andric
23460b57cec5SDimitry Andrictemplate <class _Allocator>
23470b57cec5SDimitry Andricvoid
23480b57cec5SDimitry Andricvector<bool, _Allocator>::__vdeallocate() _NOEXCEPT
23490b57cec5SDimitry Andric{
23500b57cec5SDimitry Andric    if (this->__begin_ != nullptr)
23510b57cec5SDimitry Andric    {
23520b57cec5SDimitry Andric        __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
235381ad6265SDimitry Andric        std::__debug_db_invalidate_all(this);
23540b57cec5SDimitry Andric        this->__begin_ = nullptr;
23550b57cec5SDimitry Andric        this->__size_ = this->__cap() = 0;
23560b57cec5SDimitry Andric    }
23570b57cec5SDimitry Andric}
23580b57cec5SDimitry Andric
23590b57cec5SDimitry Andrictemplate <class _Allocator>
23600b57cec5SDimitry Andrictypename vector<bool, _Allocator>::size_type
23610b57cec5SDimitry Andricvector<bool, _Allocator>::max_size() const _NOEXCEPT
23620b57cec5SDimitry Andric{
23630b57cec5SDimitry Andric    size_type __amax = __storage_traits::max_size(__alloc());
23640b57cec5SDimitry Andric    size_type __nmax = numeric_limits<size_type>::max() / 2;  // end() >= begin(), always
23650b57cec5SDimitry Andric    if (__nmax / __bits_per_word <= __amax)
23660b57cec5SDimitry Andric        return __nmax;
23670b57cec5SDimitry Andric    return __internal_cap_to_external(__amax);
23680b57cec5SDimitry Andric}
23690b57cec5SDimitry Andric
23700b57cec5SDimitry Andric//  Precondition:  __new_size > capacity()
23710b57cec5SDimitry Andrictemplate <class _Allocator>
23720b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
23730b57cec5SDimitry Andrictypename vector<bool, _Allocator>::size_type
23740b57cec5SDimitry Andricvector<bool, _Allocator>::__recommend(size_type __new_size) const
23750b57cec5SDimitry Andric{
23760b57cec5SDimitry Andric    const size_type __ms = max_size();
23770b57cec5SDimitry Andric    if (__new_size > __ms)
23780b57cec5SDimitry Andric        this->__throw_length_error();
23790b57cec5SDimitry Andric    const size_type __cap = capacity();
23800b57cec5SDimitry Andric    if (__cap >= __ms / 2)
23810b57cec5SDimitry Andric        return __ms;
23820b57cec5SDimitry Andric    return _VSTD::max(2 * __cap, __align_it(__new_size));
23830b57cec5SDimitry Andric}
23840b57cec5SDimitry Andric
23850b57cec5SDimitry Andric//  Default constructs __n objects starting at __end_
23860b57cec5SDimitry Andric//  Precondition:  __n > 0
23870b57cec5SDimitry Andric//  Precondition:  size() + __n <= capacity()
23880b57cec5SDimitry Andric//  Postcondition:  size() == size() + __n
23890b57cec5SDimitry Andrictemplate <class _Allocator>
23900b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
23910b57cec5SDimitry Andricvoid
23920b57cec5SDimitry Andricvector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
23930b57cec5SDimitry Andric{
23940b57cec5SDimitry Andric    size_type __old_size = this->__size_;
23950b57cec5SDimitry Andric    this->__size_ += __n;
23960b57cec5SDimitry Andric    if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word))
23970b57cec5SDimitry Andric    {
23980b57cec5SDimitry Andric        if (this->__size_ <= __bits_per_word)
23990b57cec5SDimitry Andric            this->__begin_[0] = __storage_type(0);
24000b57cec5SDimitry Andric        else
24010b57cec5SDimitry Andric            this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
24020b57cec5SDimitry Andric    }
24030b57cec5SDimitry Andric    _VSTD::fill_n(__make_iter(__old_size), __n, __x);
24040b57cec5SDimitry Andric}
24050b57cec5SDimitry Andric
24060b57cec5SDimitry Andrictemplate <class _Allocator>
24070b57cec5SDimitry Andrictemplate <class _ForwardIterator>
24080b57cec5SDimitry Andrictypename enable_if
24090b57cec5SDimitry Andric<
2410480093f4SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value,
24110b57cec5SDimitry Andric    void
24120b57cec5SDimitry Andric>::type
24130b57cec5SDimitry Andricvector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
24140b57cec5SDimitry Andric{
24150b57cec5SDimitry Andric    size_type __old_size = this->__size_;
24160b57cec5SDimitry Andric    this->__size_ += _VSTD::distance(__first, __last);
24170b57cec5SDimitry Andric    if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word))
24180b57cec5SDimitry Andric    {
24190b57cec5SDimitry Andric        if (this->__size_ <= __bits_per_word)
24200b57cec5SDimitry Andric            this->__begin_[0] = __storage_type(0);
24210b57cec5SDimitry Andric        else
24220b57cec5SDimitry Andric            this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
24230b57cec5SDimitry Andric    }
24240b57cec5SDimitry Andric    _VSTD::copy(__first, __last, __make_iter(__old_size));
24250b57cec5SDimitry Andric}
24260b57cec5SDimitry Andric
24270b57cec5SDimitry Andrictemplate <class _Allocator>
24280b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
24290b57cec5SDimitry Andricvector<bool, _Allocator>::vector()
24300b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
24310b57cec5SDimitry Andric    : __begin_(nullptr),
24320b57cec5SDimitry Andric      __size_(0),
2433480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
24340b57cec5SDimitry Andric{
24350b57cec5SDimitry Andric}
24360b57cec5SDimitry Andric
24370b57cec5SDimitry Andrictemplate <class _Allocator>
24380b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
24390b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const allocator_type& __a)
24400b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
24410b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
24420b57cec5SDimitry Andric#else
24430b57cec5SDimitry Andric        _NOEXCEPT
24440b57cec5SDimitry Andric#endif
24450b57cec5SDimitry Andric    : __begin_(nullptr),
24460b57cec5SDimitry Andric      __size_(0),
24470b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
24480b57cec5SDimitry Andric{
24490b57cec5SDimitry Andric}
24500b57cec5SDimitry Andric
24510b57cec5SDimitry Andrictemplate <class _Allocator>
24520b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n)
24530b57cec5SDimitry Andric    : __begin_(nullptr),
24540b57cec5SDimitry Andric      __size_(0),
2455480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
24560b57cec5SDimitry Andric{
24570b57cec5SDimitry Andric    if (__n > 0)
24580b57cec5SDimitry Andric    {
24590b57cec5SDimitry Andric        __vallocate(__n);
24600b57cec5SDimitry Andric        __construct_at_end(__n, false);
24610b57cec5SDimitry Andric    }
24620b57cec5SDimitry Andric}
24630b57cec5SDimitry Andric
24640b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
24650b57cec5SDimitry Andrictemplate <class _Allocator>
24660b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
24670b57cec5SDimitry Andric    : __begin_(nullptr),
24680b57cec5SDimitry Andric      __size_(0),
24690b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
24700b57cec5SDimitry Andric{
24710b57cec5SDimitry Andric    if (__n > 0)
24720b57cec5SDimitry Andric    {
24730b57cec5SDimitry Andric        __vallocate(__n);
24740b57cec5SDimitry Andric        __construct_at_end(__n, false);
24750b57cec5SDimitry Andric    }
24760b57cec5SDimitry Andric}
24770b57cec5SDimitry Andric#endif
24780b57cec5SDimitry Andric
24790b57cec5SDimitry Andrictemplate <class _Allocator>
24800b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
24810b57cec5SDimitry Andric    : __begin_(nullptr),
24820b57cec5SDimitry Andric      __size_(0),
2483480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
24840b57cec5SDimitry Andric{
24850b57cec5SDimitry Andric    if (__n > 0)
24860b57cec5SDimitry Andric    {
24870b57cec5SDimitry Andric        __vallocate(__n);
24880b57cec5SDimitry Andric        __construct_at_end(__n, __x);
24890b57cec5SDimitry Andric    }
24900b57cec5SDimitry Andric}
24910b57cec5SDimitry Andric
24920b57cec5SDimitry Andrictemplate <class _Allocator>
24930b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
24940b57cec5SDimitry Andric    : __begin_(nullptr),
24950b57cec5SDimitry Andric      __size_(0),
24960b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
24970b57cec5SDimitry Andric{
24980b57cec5SDimitry Andric    if (__n > 0)
24990b57cec5SDimitry Andric    {
25000b57cec5SDimitry Andric        __vallocate(__n);
25010b57cec5SDimitry Andric        __construct_at_end(__n, __x);
25020b57cec5SDimitry Andric    }
25030b57cec5SDimitry Andric}
25040b57cec5SDimitry Andric
25050b57cec5SDimitry Andrictemplate <class _Allocator>
25060b57cec5SDimitry Andrictemplate <class _InputIterator>
25070b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2508753f127fSDimitry Andric       typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type*)
25090b57cec5SDimitry Andric    : __begin_(nullptr),
25100b57cec5SDimitry Andric      __size_(0),
2511480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
25120b57cec5SDimitry Andric{
25130b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
25140b57cec5SDimitry Andric    try
25150b57cec5SDimitry Andric    {
25160b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
25170b57cec5SDimitry Andric        for (; __first != __last; ++__first)
25180b57cec5SDimitry Andric            push_back(*__first);
25190b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
25200b57cec5SDimitry Andric    }
25210b57cec5SDimitry Andric    catch (...)
25220b57cec5SDimitry Andric    {
25230b57cec5SDimitry Andric        if (__begin_ != nullptr)
25240b57cec5SDimitry Andric            __storage_traits::deallocate(__alloc(), __begin_, __cap());
252581ad6265SDimitry Andric        std::__debug_db_invalidate_all(this);
25260b57cec5SDimitry Andric        throw;
25270b57cec5SDimitry Andric    }
25280b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
25290b57cec5SDimitry Andric}
25300b57cec5SDimitry Andric
25310b57cec5SDimitry Andrictemplate <class _Allocator>
25320b57cec5SDimitry Andrictemplate <class _InputIterator>
25330b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2534753f127fSDimitry Andric       typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type*)
25350b57cec5SDimitry Andric    : __begin_(nullptr),
25360b57cec5SDimitry Andric      __size_(0),
25370b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
25380b57cec5SDimitry Andric{
25390b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
25400b57cec5SDimitry Andric    try
25410b57cec5SDimitry Andric    {
25420b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
25430b57cec5SDimitry Andric        for (; __first != __last; ++__first)
25440b57cec5SDimitry Andric            push_back(*__first);
25450b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
25460b57cec5SDimitry Andric    }
25470b57cec5SDimitry Andric    catch (...)
25480b57cec5SDimitry Andric    {
25490b57cec5SDimitry Andric        if (__begin_ != nullptr)
25500b57cec5SDimitry Andric            __storage_traits::deallocate(__alloc(), __begin_, __cap());
255181ad6265SDimitry Andric        std::__debug_db_invalidate_all(this);
25520b57cec5SDimitry Andric        throw;
25530b57cec5SDimitry Andric    }
25540b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
25550b57cec5SDimitry Andric}
25560b57cec5SDimitry Andric
25570b57cec5SDimitry Andrictemplate <class _Allocator>
25580b57cec5SDimitry Andrictemplate <class _ForwardIterator>
25590b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2560480093f4SDimitry Andric                                typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*)
25610b57cec5SDimitry Andric    : __begin_(nullptr),
25620b57cec5SDimitry Andric      __size_(0),
2563480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
25640b57cec5SDimitry Andric{
25650b57cec5SDimitry Andric    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
25660b57cec5SDimitry Andric    if (__n > 0)
25670b57cec5SDimitry Andric    {
25680b57cec5SDimitry Andric        __vallocate(__n);
25690b57cec5SDimitry Andric        __construct_at_end(__first, __last);
25700b57cec5SDimitry Andric    }
25710b57cec5SDimitry Andric}
25720b57cec5SDimitry Andric
25730b57cec5SDimitry Andrictemplate <class _Allocator>
25740b57cec5SDimitry Andrictemplate <class _ForwardIterator>
25750b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2576480093f4SDimitry Andric                                typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*)
25770b57cec5SDimitry Andric    : __begin_(nullptr),
25780b57cec5SDimitry Andric      __size_(0),
25790b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
25800b57cec5SDimitry Andric{
25810b57cec5SDimitry Andric    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
25820b57cec5SDimitry Andric    if (__n > 0)
25830b57cec5SDimitry Andric    {
25840b57cec5SDimitry Andric        __vallocate(__n);
25850b57cec5SDimitry Andric        __construct_at_end(__first, __last);
25860b57cec5SDimitry Andric    }
25870b57cec5SDimitry Andric}
25880b57cec5SDimitry Andric
25890b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
25900b57cec5SDimitry Andric
25910b57cec5SDimitry Andrictemplate <class _Allocator>
25920b57cec5SDimitry Andricvector<bool, _Allocator>::vector(initializer_list<value_type> __il)
25930b57cec5SDimitry Andric    : __begin_(nullptr),
25940b57cec5SDimitry Andric      __size_(0),
2595480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
25960b57cec5SDimitry Andric{
25970b57cec5SDimitry Andric    size_type __n = static_cast<size_type>(__il.size());
25980b57cec5SDimitry Andric    if (__n > 0)
25990b57cec5SDimitry Andric    {
26000b57cec5SDimitry Andric        __vallocate(__n);
26010b57cec5SDimitry Andric        __construct_at_end(__il.begin(), __il.end());
26020b57cec5SDimitry Andric    }
26030b57cec5SDimitry Andric}
26040b57cec5SDimitry Andric
26050b57cec5SDimitry Andrictemplate <class _Allocator>
26060b57cec5SDimitry Andricvector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
26070b57cec5SDimitry Andric    : __begin_(nullptr),
26080b57cec5SDimitry Andric      __size_(0),
26090b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
26100b57cec5SDimitry Andric{
26110b57cec5SDimitry Andric    size_type __n = static_cast<size_type>(__il.size());
26120b57cec5SDimitry Andric    if (__n > 0)
26130b57cec5SDimitry Andric    {
26140b57cec5SDimitry Andric        __vallocate(__n);
26150b57cec5SDimitry Andric        __construct_at_end(__il.begin(), __il.end());
26160b57cec5SDimitry Andric    }
26170b57cec5SDimitry Andric}
26180b57cec5SDimitry Andric
26190b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
26200b57cec5SDimitry Andric
26210b57cec5SDimitry Andrictemplate <class _Allocator>
26220b57cec5SDimitry Andricvector<bool, _Allocator>::~vector()
26230b57cec5SDimitry Andric{
26240b57cec5SDimitry Andric    if (__begin_ != nullptr)
26250b57cec5SDimitry Andric        __storage_traits::deallocate(__alloc(), __begin_, __cap());
262681ad6265SDimitry Andric    std::__debug_db_invalidate_all(this);
26270b57cec5SDimitry Andric}
26280b57cec5SDimitry Andric
26290b57cec5SDimitry Andrictemplate <class _Allocator>
26300b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const vector& __v)
26310b57cec5SDimitry Andric    : __begin_(nullptr),
26320b57cec5SDimitry Andric      __size_(0),
26330b57cec5SDimitry Andric      __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
26340b57cec5SDimitry Andric{
26350b57cec5SDimitry Andric    if (__v.size() > 0)
26360b57cec5SDimitry Andric    {
26370b57cec5SDimitry Andric        __vallocate(__v.size());
26380b57cec5SDimitry Andric        __construct_at_end(__v.begin(), __v.end());
26390b57cec5SDimitry Andric    }
26400b57cec5SDimitry Andric}
26410b57cec5SDimitry Andric
26420b57cec5SDimitry Andrictemplate <class _Allocator>
26430b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
26440b57cec5SDimitry Andric    : __begin_(nullptr),
26450b57cec5SDimitry Andric      __size_(0),
26460b57cec5SDimitry Andric      __cap_alloc_(0, __a)
26470b57cec5SDimitry Andric{
26480b57cec5SDimitry Andric    if (__v.size() > 0)
26490b57cec5SDimitry Andric    {
26500b57cec5SDimitry Andric        __vallocate(__v.size());
26510b57cec5SDimitry Andric        __construct_at_end(__v.begin(), __v.end());
26520b57cec5SDimitry Andric    }
26530b57cec5SDimitry Andric}
26540b57cec5SDimitry Andric
26550b57cec5SDimitry Andrictemplate <class _Allocator>
26560b57cec5SDimitry Andricvector<bool, _Allocator>&
26570b57cec5SDimitry Andricvector<bool, _Allocator>::operator=(const vector& __v)
26580b57cec5SDimitry Andric{
2659349cc55cSDimitry Andric    if (this != _VSTD::addressof(__v))
26600b57cec5SDimitry Andric    {
26610b57cec5SDimitry Andric        __copy_assign_alloc(__v);
26620b57cec5SDimitry Andric        if (__v.__size_)
26630b57cec5SDimitry Andric        {
26640b57cec5SDimitry Andric            if (__v.__size_ > capacity())
26650b57cec5SDimitry Andric            {
26660b57cec5SDimitry Andric                __vdeallocate();
26670b57cec5SDimitry Andric                __vallocate(__v.__size_);
26680b57cec5SDimitry Andric            }
26690b57cec5SDimitry Andric            _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
26700b57cec5SDimitry Andric        }
26710b57cec5SDimitry Andric        __size_ = __v.__size_;
26720b57cec5SDimitry Andric    }
26730b57cec5SDimitry Andric    return *this;
26740b57cec5SDimitry Andric}
26750b57cec5SDimitry Andric
26760b57cec5SDimitry Andrictemplate <class _Allocator>
26770b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY vector<bool, _Allocator>::vector(vector&& __v)
26780b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
26790b57cec5SDimitry Andric    _NOEXCEPT
26800b57cec5SDimitry Andric#else
26810b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
26820b57cec5SDimitry Andric#endif
26830b57cec5SDimitry Andric    : __begin_(__v.__begin_),
26840b57cec5SDimitry Andric      __size_(__v.__size_),
2685e8d8bef9SDimitry Andric      __cap_alloc_(_VSTD::move(__v.__cap_alloc_)) {
26860b57cec5SDimitry Andric    __v.__begin_ = nullptr;
26870b57cec5SDimitry Andric    __v.__size_ = 0;
26880b57cec5SDimitry Andric    __v.__cap() = 0;
26890b57cec5SDimitry Andric}
26900b57cec5SDimitry Andric
26910b57cec5SDimitry Andrictemplate <class _Allocator>
269281ad6265SDimitry Andricvector<bool, _Allocator>::vector(vector&& __v, const __type_identity_t<allocator_type>& __a)
26930b57cec5SDimitry Andric    : __begin_(nullptr),
26940b57cec5SDimitry Andric      __size_(0),
26950b57cec5SDimitry Andric      __cap_alloc_(0, __a)
26960b57cec5SDimitry Andric{
26970b57cec5SDimitry Andric    if (__a == allocator_type(__v.__alloc()))
26980b57cec5SDimitry Andric    {
26990b57cec5SDimitry Andric        this->__begin_ = __v.__begin_;
27000b57cec5SDimitry Andric        this->__size_ = __v.__size_;
27010b57cec5SDimitry Andric        this->__cap() = __v.__cap();
27020b57cec5SDimitry Andric        __v.__begin_ = nullptr;
27030b57cec5SDimitry Andric        __v.__cap() = __v.__size_ = 0;
27040b57cec5SDimitry Andric    }
27050b57cec5SDimitry Andric    else if (__v.size() > 0)
27060b57cec5SDimitry Andric    {
27070b57cec5SDimitry Andric        __vallocate(__v.size());
27080b57cec5SDimitry Andric        __construct_at_end(__v.begin(), __v.end());
27090b57cec5SDimitry Andric    }
27100b57cec5SDimitry Andric}
27110b57cec5SDimitry Andric
27120b57cec5SDimitry Andrictemplate <class _Allocator>
27130b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
27140b57cec5SDimitry Andricvector<bool, _Allocator>&
27150b57cec5SDimitry Andricvector<bool, _Allocator>::operator=(vector&& __v)
27160b57cec5SDimitry Andric    _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
27170b57cec5SDimitry Andric{
27180b57cec5SDimitry Andric    __move_assign(__v, integral_constant<bool,
27190b57cec5SDimitry Andric          __storage_traits::propagate_on_container_move_assignment::value>());
27200b57cec5SDimitry Andric    return *this;
27210b57cec5SDimitry Andric}
27220b57cec5SDimitry Andric
27230b57cec5SDimitry Andrictemplate <class _Allocator>
27240b57cec5SDimitry Andricvoid
27250b57cec5SDimitry Andricvector<bool, _Allocator>::__move_assign(vector& __c, false_type)
27260b57cec5SDimitry Andric{
27270b57cec5SDimitry Andric    if (__alloc() != __c.__alloc())
27280b57cec5SDimitry Andric        assign(__c.begin(), __c.end());
27290b57cec5SDimitry Andric    else
27300b57cec5SDimitry Andric        __move_assign(__c, true_type());
27310b57cec5SDimitry Andric}
27320b57cec5SDimitry Andric
27330b57cec5SDimitry Andrictemplate <class _Allocator>
27340b57cec5SDimitry Andricvoid
27350b57cec5SDimitry Andricvector<bool, _Allocator>::__move_assign(vector& __c, true_type)
27360b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
27370b57cec5SDimitry Andric{
27380b57cec5SDimitry Andric    __vdeallocate();
27390b57cec5SDimitry Andric    __move_assign_alloc(__c);
27400b57cec5SDimitry Andric    this->__begin_ = __c.__begin_;
27410b57cec5SDimitry Andric    this->__size_ = __c.__size_;
27420b57cec5SDimitry Andric    this->__cap() = __c.__cap();
27430b57cec5SDimitry Andric    __c.__begin_ = nullptr;
27440b57cec5SDimitry Andric    __c.__cap() = __c.__size_ = 0;
27450b57cec5SDimitry Andric}
27460b57cec5SDimitry Andric
27470b57cec5SDimitry Andrictemplate <class _Allocator>
27480b57cec5SDimitry Andricvoid
27490b57cec5SDimitry Andricvector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
27500b57cec5SDimitry Andric{
27510b57cec5SDimitry Andric    __size_ = 0;
27520b57cec5SDimitry Andric    if (__n > 0)
27530b57cec5SDimitry Andric    {
27540b57cec5SDimitry Andric        size_type __c = capacity();
27550b57cec5SDimitry Andric        if (__n <= __c)
27560b57cec5SDimitry Andric            __size_ = __n;
27570b57cec5SDimitry Andric        else
27580b57cec5SDimitry Andric        {
2759349cc55cSDimitry Andric            vector __v(get_allocator());
27600b57cec5SDimitry Andric            __v.reserve(__recommend(__n));
27610b57cec5SDimitry Andric            __v.__size_ = __n;
27620b57cec5SDimitry Andric            swap(__v);
27630b57cec5SDimitry Andric        }
27640b57cec5SDimitry Andric        _VSTD::fill_n(begin(), __n, __x);
27650b57cec5SDimitry Andric    }
276681ad6265SDimitry Andric    std::__debug_db_invalidate_all(this);
27670b57cec5SDimitry Andric}
27680b57cec5SDimitry Andric
27690b57cec5SDimitry Andrictemplate <class _Allocator>
27700b57cec5SDimitry Andrictemplate <class _InputIterator>
2771753f127fSDimitry Andrictypename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
27720b57cec5SDimitry Andric   void
27730b57cec5SDimitry Andric>::type
27740b57cec5SDimitry Andricvector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
27750b57cec5SDimitry Andric{
27760b57cec5SDimitry Andric    clear();
27770b57cec5SDimitry Andric    for (; __first != __last; ++__first)
27780b57cec5SDimitry Andric        push_back(*__first);
27790b57cec5SDimitry Andric}
27800b57cec5SDimitry Andric
27810b57cec5SDimitry Andrictemplate <class _Allocator>
27820b57cec5SDimitry Andrictemplate <class _ForwardIterator>
27830b57cec5SDimitry Andrictypename enable_if
27840b57cec5SDimitry Andric<
2785480093f4SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value,
27860b57cec5SDimitry Andric   void
27870b57cec5SDimitry Andric>::type
27880b57cec5SDimitry Andricvector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
27890b57cec5SDimitry Andric{
27900b57cec5SDimitry Andric    clear();
27910b57cec5SDimitry Andric    difference_type __ns = _VSTD::distance(__first, __last);
27920b57cec5SDimitry Andric    _LIBCPP_ASSERT(__ns >= 0, "invalid range specified");
27930b57cec5SDimitry Andric    const size_t __n = static_cast<size_type>(__ns);
27940b57cec5SDimitry Andric    if (__n)
27950b57cec5SDimitry Andric    {
27960b57cec5SDimitry Andric        if (__n > capacity())
27970b57cec5SDimitry Andric        {
27980b57cec5SDimitry Andric            __vdeallocate();
27990b57cec5SDimitry Andric            __vallocate(__n);
28000b57cec5SDimitry Andric        }
28010b57cec5SDimitry Andric        __construct_at_end(__first, __last);
28020b57cec5SDimitry Andric    }
28030b57cec5SDimitry Andric}
28040b57cec5SDimitry Andric
28050b57cec5SDimitry Andrictemplate <class _Allocator>
28060b57cec5SDimitry Andricvoid
28070b57cec5SDimitry Andricvector<bool, _Allocator>::reserve(size_type __n)
28080b57cec5SDimitry Andric{
28090b57cec5SDimitry Andric    if (__n > capacity())
28100b57cec5SDimitry Andric    {
2811349cc55cSDimitry Andric        if (__n > max_size())
2812349cc55cSDimitry Andric            this->__throw_length_error();
2813349cc55cSDimitry Andric        vector __v(this->get_allocator());
28140b57cec5SDimitry Andric        __v.__vallocate(__n);
28150b57cec5SDimitry Andric        __v.__construct_at_end(this->begin(), this->end());
28160b57cec5SDimitry Andric        swap(__v);
281781ad6265SDimitry Andric        std::__debug_db_invalidate_all(this);
28180b57cec5SDimitry Andric    }
28190b57cec5SDimitry Andric}
28200b57cec5SDimitry Andric
28210b57cec5SDimitry Andrictemplate <class _Allocator>
28220b57cec5SDimitry Andricvoid
28230b57cec5SDimitry Andricvector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
28240b57cec5SDimitry Andric{
28250b57cec5SDimitry Andric    if (__external_cap_to_internal(size()) > __cap())
28260b57cec5SDimitry Andric    {
28270b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
28280b57cec5SDimitry Andric        try
28290b57cec5SDimitry Andric        {
28300b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
28310b57cec5SDimitry Andric            vector(*this, allocator_type(__alloc())).swap(*this);
28320b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
28330b57cec5SDimitry Andric        }
28340b57cec5SDimitry Andric        catch (...)
28350b57cec5SDimitry Andric        {
28360b57cec5SDimitry Andric        }
28370b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
28380b57cec5SDimitry Andric    }
28390b57cec5SDimitry Andric}
28400b57cec5SDimitry Andric
28410b57cec5SDimitry Andrictemplate <class _Allocator>
28420b57cec5SDimitry Andrictypename vector<bool, _Allocator>::reference
28430b57cec5SDimitry Andricvector<bool, _Allocator>::at(size_type __n)
28440b57cec5SDimitry Andric{
28450b57cec5SDimitry Andric    if (__n >= size())
28460b57cec5SDimitry Andric        this->__throw_out_of_range();
28470b57cec5SDimitry Andric    return (*this)[__n];
28480b57cec5SDimitry Andric}
28490b57cec5SDimitry Andric
28500b57cec5SDimitry Andrictemplate <class _Allocator>
28510b57cec5SDimitry Andrictypename vector<bool, _Allocator>::const_reference
28520b57cec5SDimitry Andricvector<bool, _Allocator>::at(size_type __n) const
28530b57cec5SDimitry Andric{
28540b57cec5SDimitry Andric    if (__n >= size())
28550b57cec5SDimitry Andric        this->__throw_out_of_range();
28560b57cec5SDimitry Andric    return (*this)[__n];
28570b57cec5SDimitry Andric}
28580b57cec5SDimitry Andric
28590b57cec5SDimitry Andrictemplate <class _Allocator>
28600b57cec5SDimitry Andricvoid
28610b57cec5SDimitry Andricvector<bool, _Allocator>::push_back(const value_type& __x)
28620b57cec5SDimitry Andric{
28630b57cec5SDimitry Andric    if (this->__size_ == this->capacity())
28640b57cec5SDimitry Andric        reserve(__recommend(this->__size_ + 1));
28650b57cec5SDimitry Andric    ++this->__size_;
28660b57cec5SDimitry Andric    back() = __x;
28670b57cec5SDimitry Andric}
28680b57cec5SDimitry Andric
28690b57cec5SDimitry Andrictemplate <class _Allocator>
28700b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator
28710b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
28720b57cec5SDimitry Andric{
28730b57cec5SDimitry Andric    iterator __r;
28740b57cec5SDimitry Andric    if (size() < capacity())
28750b57cec5SDimitry Andric    {
28760b57cec5SDimitry Andric        const_iterator __old_end = end();
28770b57cec5SDimitry Andric        ++__size_;
28780b57cec5SDimitry Andric        _VSTD::copy_backward(__position, __old_end, end());
28790b57cec5SDimitry Andric        __r = __const_iterator_cast(__position);
28800b57cec5SDimitry Andric    }
28810b57cec5SDimitry Andric    else
28820b57cec5SDimitry Andric    {
2883349cc55cSDimitry Andric        vector __v(get_allocator());
28840b57cec5SDimitry Andric        __v.reserve(__recommend(__size_ + 1));
28850b57cec5SDimitry Andric        __v.__size_ = __size_ + 1;
28860b57cec5SDimitry Andric        __r = _VSTD::copy(cbegin(), __position, __v.begin());
28870b57cec5SDimitry Andric        _VSTD::copy_backward(__position, cend(), __v.end());
28880b57cec5SDimitry Andric        swap(__v);
28890b57cec5SDimitry Andric    }
28900b57cec5SDimitry Andric    *__r = __x;
28910b57cec5SDimitry Andric    return __r;
28920b57cec5SDimitry Andric}
28930b57cec5SDimitry Andric
28940b57cec5SDimitry Andrictemplate <class _Allocator>
28950b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator
28960b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
28970b57cec5SDimitry Andric{
28980b57cec5SDimitry Andric    iterator __r;
28990b57cec5SDimitry Andric    size_type __c = capacity();
29000b57cec5SDimitry Andric    if (__n <= __c && size() <= __c - __n)
29010b57cec5SDimitry Andric    {
29020b57cec5SDimitry Andric        const_iterator __old_end = end();
29030b57cec5SDimitry Andric        __size_ += __n;
29040b57cec5SDimitry Andric        _VSTD::copy_backward(__position, __old_end, end());
29050b57cec5SDimitry Andric        __r = __const_iterator_cast(__position);
29060b57cec5SDimitry Andric    }
29070b57cec5SDimitry Andric    else
29080b57cec5SDimitry Andric    {
2909349cc55cSDimitry Andric        vector __v(get_allocator());
29100b57cec5SDimitry Andric        __v.reserve(__recommend(__size_ + __n));
29110b57cec5SDimitry Andric        __v.__size_ = __size_ + __n;
29120b57cec5SDimitry Andric        __r = _VSTD::copy(cbegin(), __position, __v.begin());
29130b57cec5SDimitry Andric        _VSTD::copy_backward(__position, cend(), __v.end());
29140b57cec5SDimitry Andric        swap(__v);
29150b57cec5SDimitry Andric    }
29160b57cec5SDimitry Andric    _VSTD::fill_n(__r, __n, __x);
29170b57cec5SDimitry Andric    return __r;
29180b57cec5SDimitry Andric}
29190b57cec5SDimitry Andric
29200b57cec5SDimitry Andrictemplate <class _Allocator>
29210b57cec5SDimitry Andrictemplate <class _InputIterator>
2922753f127fSDimitry Andrictypename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
29230b57cec5SDimitry Andric    typename vector<bool, _Allocator>::iterator
29240b57cec5SDimitry Andric>::type
29250b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
29260b57cec5SDimitry Andric{
29270b57cec5SDimitry Andric    difference_type __off = __position - begin();
29280b57cec5SDimitry Andric    iterator __p = __const_iterator_cast(__position);
29290b57cec5SDimitry Andric    iterator __old_end = end();
29300b57cec5SDimitry Andric    for (; size() != capacity() && __first != __last; ++__first)
29310b57cec5SDimitry Andric    {
29320b57cec5SDimitry Andric        ++this->__size_;
29330b57cec5SDimitry Andric        back() = *__first;
29340b57cec5SDimitry Andric    }
2935349cc55cSDimitry Andric    vector __v(get_allocator());
29360b57cec5SDimitry Andric    if (__first != __last)
29370b57cec5SDimitry Andric    {
29380b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
29390b57cec5SDimitry Andric        try
29400b57cec5SDimitry Andric        {
29410b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
29420b57cec5SDimitry Andric            __v.assign(__first, __last);
29430b57cec5SDimitry Andric            difference_type __old_size = static_cast<difference_type>(__old_end - begin());
29440b57cec5SDimitry Andric            difference_type __old_p = __p - begin();
29450b57cec5SDimitry Andric            reserve(__recommend(size() + __v.size()));
29460b57cec5SDimitry Andric            __p = begin() + __old_p;
29470b57cec5SDimitry Andric            __old_end = begin() + __old_size;
29480b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
29490b57cec5SDimitry Andric        }
29500b57cec5SDimitry Andric        catch (...)
29510b57cec5SDimitry Andric        {
29520b57cec5SDimitry Andric            erase(__old_end, end());
29530b57cec5SDimitry Andric            throw;
29540b57cec5SDimitry Andric        }
29550b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
29560b57cec5SDimitry Andric    }
29570b57cec5SDimitry Andric    __p = _VSTD::rotate(__p, __old_end, end());
29580b57cec5SDimitry Andric    insert(__p, __v.begin(), __v.end());
29590b57cec5SDimitry Andric    return begin() + __off;
29600b57cec5SDimitry Andric}
29610b57cec5SDimitry Andric
29620b57cec5SDimitry Andrictemplate <class _Allocator>
29630b57cec5SDimitry Andrictemplate <class _ForwardIterator>
29640b57cec5SDimitry Andrictypename enable_if
29650b57cec5SDimitry Andric<
2966480093f4SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value,
29670b57cec5SDimitry Andric    typename vector<bool, _Allocator>::iterator
29680b57cec5SDimitry Andric>::type
29690b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
29700b57cec5SDimitry Andric{
29710b57cec5SDimitry Andric    const difference_type __n_signed = _VSTD::distance(__first, __last);
29720b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n_signed >= 0, "invalid range specified");
29730b57cec5SDimitry Andric    const size_type __n = static_cast<size_type>(__n_signed);
29740b57cec5SDimitry Andric    iterator __r;
29750b57cec5SDimitry Andric    size_type __c = capacity();
29760b57cec5SDimitry Andric    if (__n <= __c && size() <= __c - __n)
29770b57cec5SDimitry Andric    {
29780b57cec5SDimitry Andric        const_iterator __old_end = end();
29790b57cec5SDimitry Andric        __size_ += __n;
29800b57cec5SDimitry Andric        _VSTD::copy_backward(__position, __old_end, end());
29810b57cec5SDimitry Andric        __r = __const_iterator_cast(__position);
29820b57cec5SDimitry Andric    }
29830b57cec5SDimitry Andric    else
29840b57cec5SDimitry Andric    {
2985349cc55cSDimitry Andric        vector __v(get_allocator());
29860b57cec5SDimitry Andric        __v.reserve(__recommend(__size_ + __n));
29870b57cec5SDimitry Andric        __v.__size_ = __size_ + __n;
29880b57cec5SDimitry Andric        __r = _VSTD::copy(cbegin(), __position, __v.begin());
29890b57cec5SDimitry Andric        _VSTD::copy_backward(__position, cend(), __v.end());
29900b57cec5SDimitry Andric        swap(__v);
29910b57cec5SDimitry Andric    }
29920b57cec5SDimitry Andric    _VSTD::copy(__first, __last, __r);
29930b57cec5SDimitry Andric    return __r;
29940b57cec5SDimitry Andric}
29950b57cec5SDimitry Andric
29960b57cec5SDimitry Andrictemplate <class _Allocator>
29970b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
29980b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator
29990b57cec5SDimitry Andricvector<bool, _Allocator>::erase(const_iterator __position)
30000b57cec5SDimitry Andric{
30010b57cec5SDimitry Andric    iterator __r = __const_iterator_cast(__position);
30020b57cec5SDimitry Andric    _VSTD::copy(__position + 1, this->cend(), __r);
30030b57cec5SDimitry Andric    --__size_;
30040b57cec5SDimitry Andric    return __r;
30050b57cec5SDimitry Andric}
30060b57cec5SDimitry Andric
30070b57cec5SDimitry Andrictemplate <class _Allocator>
30080b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator
30090b57cec5SDimitry Andricvector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
30100b57cec5SDimitry Andric{
30110b57cec5SDimitry Andric    iterator __r = __const_iterator_cast(__first);
30120b57cec5SDimitry Andric    difference_type __d = __last - __first;
30130b57cec5SDimitry Andric    _VSTD::copy(__last, this->cend(), __r);
30140b57cec5SDimitry Andric    __size_ -= __d;
30150b57cec5SDimitry Andric    return __r;
30160b57cec5SDimitry Andric}
30170b57cec5SDimitry Andric
30180b57cec5SDimitry Andrictemplate <class _Allocator>
30190b57cec5SDimitry Andricvoid
30200b57cec5SDimitry Andricvector<bool, _Allocator>::swap(vector& __x)
30210b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
30220b57cec5SDimitry Andric    _NOEXCEPT
30230b57cec5SDimitry Andric#else
30240b57cec5SDimitry Andric    _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
30250b57cec5SDimitry Andric                __is_nothrow_swappable<allocator_type>::value)
30260b57cec5SDimitry Andric#endif
30270b57cec5SDimitry Andric{
30280b57cec5SDimitry Andric    _VSTD::swap(this->__begin_, __x.__begin_);
30290b57cec5SDimitry Andric    _VSTD::swap(this->__size_, __x.__size_);
30300b57cec5SDimitry Andric    _VSTD::swap(this->__cap(), __x.__cap());
3031e8d8bef9SDimitry Andric    _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(),
30320b57cec5SDimitry Andric        integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
30330b57cec5SDimitry Andric}
30340b57cec5SDimitry Andric
30350b57cec5SDimitry Andrictemplate <class _Allocator>
30360b57cec5SDimitry Andricvoid
30370b57cec5SDimitry Andricvector<bool, _Allocator>::resize(size_type __sz, value_type __x)
30380b57cec5SDimitry Andric{
30390b57cec5SDimitry Andric    size_type __cs = size();
30400b57cec5SDimitry Andric    if (__cs < __sz)
30410b57cec5SDimitry Andric    {
30420b57cec5SDimitry Andric        iterator __r;
30430b57cec5SDimitry Andric        size_type __c = capacity();
30440b57cec5SDimitry Andric        size_type __n = __sz - __cs;
30450b57cec5SDimitry Andric        if (__n <= __c && __cs <= __c - __n)
30460b57cec5SDimitry Andric        {
30470b57cec5SDimitry Andric            __r = end();
30480b57cec5SDimitry Andric            __size_ += __n;
30490b57cec5SDimitry Andric        }
30500b57cec5SDimitry Andric        else
30510b57cec5SDimitry Andric        {
3052349cc55cSDimitry Andric            vector __v(get_allocator());
30530b57cec5SDimitry Andric            __v.reserve(__recommend(__size_ + __n));
30540b57cec5SDimitry Andric            __v.__size_ = __size_ + __n;
30550b57cec5SDimitry Andric            __r = _VSTD::copy(cbegin(), cend(), __v.begin());
30560b57cec5SDimitry Andric            swap(__v);
30570b57cec5SDimitry Andric        }
30580b57cec5SDimitry Andric        _VSTD::fill_n(__r, __n, __x);
30590b57cec5SDimitry Andric    }
30600b57cec5SDimitry Andric    else
30610b57cec5SDimitry Andric        __size_ = __sz;
30620b57cec5SDimitry Andric}
30630b57cec5SDimitry Andric
30640b57cec5SDimitry Andrictemplate <class _Allocator>
30650b57cec5SDimitry Andricvoid
30660b57cec5SDimitry Andricvector<bool, _Allocator>::flip() _NOEXCEPT
30670b57cec5SDimitry Andric{
30680b57cec5SDimitry Andric    // do middle whole words
30690b57cec5SDimitry Andric    size_type __n = __size_;
30700b57cec5SDimitry Andric    __storage_pointer __p = __begin_;
30710b57cec5SDimitry Andric    for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
30720b57cec5SDimitry Andric        *__p = ~*__p;
30730b57cec5SDimitry Andric    // do last partial word
30740b57cec5SDimitry Andric    if (__n > 0)
30750b57cec5SDimitry Andric    {
30760b57cec5SDimitry Andric        __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
30770b57cec5SDimitry Andric        __storage_type __b = *__p & __m;
30780b57cec5SDimitry Andric        *__p &= ~__m;
30790b57cec5SDimitry Andric        *__p |= ~__b & __m;
30800b57cec5SDimitry Andric    }
30810b57cec5SDimitry Andric}
30820b57cec5SDimitry Andric
30830b57cec5SDimitry Andrictemplate <class _Allocator>
30840b57cec5SDimitry Andricbool
30850b57cec5SDimitry Andricvector<bool, _Allocator>::__invariants() const
30860b57cec5SDimitry Andric{
30870b57cec5SDimitry Andric    if (this->__begin_ == nullptr)
30880b57cec5SDimitry Andric    {
30890b57cec5SDimitry Andric        if (this->__size_ != 0 || this->__cap() != 0)
30900b57cec5SDimitry Andric            return false;
30910b57cec5SDimitry Andric    }
30920b57cec5SDimitry Andric    else
30930b57cec5SDimitry Andric    {
30940b57cec5SDimitry Andric        if (this->__cap() == 0)
30950b57cec5SDimitry Andric            return false;
30960b57cec5SDimitry Andric        if (this->__size_ > this->capacity())
30970b57cec5SDimitry Andric            return false;
30980b57cec5SDimitry Andric    }
30990b57cec5SDimitry Andric    return true;
31000b57cec5SDimitry Andric}
31010b57cec5SDimitry Andric
31020b57cec5SDimitry Andrictemplate <class _Allocator>
31030b57cec5SDimitry Andricsize_t
31040b57cec5SDimitry Andricvector<bool, _Allocator>::__hash_code() const _NOEXCEPT
31050b57cec5SDimitry Andric{
31060b57cec5SDimitry Andric    size_t __h = 0;
31070b57cec5SDimitry Andric    // do middle whole words
31080b57cec5SDimitry Andric    size_type __n = __size_;
31090b57cec5SDimitry Andric    __storage_pointer __p = __begin_;
31100b57cec5SDimitry Andric    for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
31110b57cec5SDimitry Andric        __h ^= *__p;
31120b57cec5SDimitry Andric    // do last partial word
31130b57cec5SDimitry Andric    if (__n > 0)
31140b57cec5SDimitry Andric    {
31150b57cec5SDimitry Andric        const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
31160b57cec5SDimitry Andric        __h ^= *__p & __m;
31170b57cec5SDimitry Andric    }
31180b57cec5SDimitry Andric    return __h;
31190b57cec5SDimitry Andric}
31200b57cec5SDimitry Andric
31210b57cec5SDimitry Andrictemplate <class _Allocator>
31220b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
312381ad6265SDimitry Andric    : public __unary_function<vector<bool, _Allocator>, size_t>
31240b57cec5SDimitry Andric{
31250b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
31260b57cec5SDimitry Andric    size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
31270b57cec5SDimitry Andric        {return __vec.__hash_code();}
31280b57cec5SDimitry Andric};
31290b57cec5SDimitry Andric
31300b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
31310b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
31320b57cec5SDimitry Andricbool
31330b57cec5SDimitry Andricoperator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
31340b57cec5SDimitry Andric{
31350b57cec5SDimitry Andric    const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
31360b57cec5SDimitry Andric    return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
31370b57cec5SDimitry Andric}
31380b57cec5SDimitry Andric
31390b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
31400b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
31410b57cec5SDimitry Andricbool
31420b57cec5SDimitry Andricoperator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
31430b57cec5SDimitry Andric{
31440b57cec5SDimitry Andric    return !(__x == __y);
31450b57cec5SDimitry Andric}
31460b57cec5SDimitry Andric
31470b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
31480b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
31490b57cec5SDimitry Andricbool
31500b57cec5SDimitry Andricoperator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
31510b57cec5SDimitry Andric{
31520b57cec5SDimitry Andric    return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
31530b57cec5SDimitry Andric}
31540b57cec5SDimitry Andric
31550b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
31560b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
31570b57cec5SDimitry Andricbool
31580b57cec5SDimitry Andricoperator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
31590b57cec5SDimitry Andric{
31600b57cec5SDimitry Andric    return __y < __x;
31610b57cec5SDimitry Andric}
31620b57cec5SDimitry Andric
31630b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
31640b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
31650b57cec5SDimitry Andricbool
31660b57cec5SDimitry Andricoperator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
31670b57cec5SDimitry Andric{
31680b57cec5SDimitry Andric    return !(__x < __y);
31690b57cec5SDimitry Andric}
31700b57cec5SDimitry Andric
31710b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
31720b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
31730b57cec5SDimitry Andricbool
31740b57cec5SDimitry Andricoperator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
31750b57cec5SDimitry Andric{
31760b57cec5SDimitry Andric    return !(__y < __x);
31770b57cec5SDimitry Andric}
31780b57cec5SDimitry Andric
31790b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
31800b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
31810b57cec5SDimitry Andricvoid
31820b57cec5SDimitry Andricswap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
31830b57cec5SDimitry Andric    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
31840b57cec5SDimitry Andric{
31850b57cec5SDimitry Andric    __x.swap(__y);
31860b57cec5SDimitry Andric}
31870b57cec5SDimitry Andric
31880b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17
31890b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Up>
31905ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type
31915ffd83dbSDimitry Andricerase(vector<_Tp, _Allocator>& __c, const _Up& __v) {
31925ffd83dbSDimitry Andric  auto __old_size = __c.size();
31935ffd83dbSDimitry Andric  __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end());
31945ffd83dbSDimitry Andric  return __old_size - __c.size();
31955ffd83dbSDimitry Andric}
31960b57cec5SDimitry Andric
31970b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Predicate>
31985ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type
31995ffd83dbSDimitry Andricerase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) {
32005ffd83dbSDimitry Andric  auto __old_size = __c.size();
32015ffd83dbSDimitry Andric  __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end());
32025ffd83dbSDimitry Andric  return __old_size - __c.size();
32035ffd83dbSDimitry Andric}
320481ad6265SDimitry Andric
320581ad6265SDimitry Andrictemplate <>
320681ad6265SDimitry Andricinline constexpr bool __format::__enable_insertable<std::vector<char>> = true;
320781ad6265SDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
320881ad6265SDimitry Andrictemplate <>
320981ad6265SDimitry Andricinline constexpr bool __format::__enable_insertable<std::vector<wchar_t>> = true;
32100b57cec5SDimitry Andric#endif
32110b57cec5SDimitry Andric
321281ad6265SDimitry Andric#endif // _LIBCPP_STD_VER > 17
321381ad6265SDimitry Andric
32140b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
32150b57cec5SDimitry Andric
32160b57cec5SDimitry Andric_LIBCPP_POP_MACROS
32170b57cec5SDimitry Andric
32180b57cec5SDimitry Andric#endif // _LIBCPP_VECTOR
3219