xref: /freebsd/contrib/llvm-project/libcxx/include/vector (revision fe6060f10f634930ff71b7c50291ddc610da2475)
10b57cec5SDimitry Andric// -*- C++ -*-
20b57cec5SDimitry Andric//===------------------------------ vector --------------------------------===//
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;
147*fe6060f1SDimitry 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())
2480b57cec5SDimitry Andric   -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>;
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
2740b57cec5SDimitry Andric#include <__config>
2750b57cec5SDimitry Andric#include <__bit_reference>
276*fe6060f1SDimitry Andric#include <__debug>
277*fe6060f1SDimitry Andric#include <__functional_base>
278*fe6060f1SDimitry Andric#include <__iterator/wrap_iter.h>
279*fe6060f1SDimitry Andric#include <__split_buffer>
280*fe6060f1SDimitry Andric#include <__utility/forward.h>
281*fe6060f1SDimitry Andric#include <algorithm>
2820b57cec5SDimitry Andric#include <climits>
283*fe6060f1SDimitry Andric#include <compare>
284*fe6060f1SDimitry Andric#include <cstring>
2850b57cec5SDimitry Andric#include <initializer_list>
286*fe6060f1SDimitry Andric#include <iosfwd> // for forward declaration of vector
287*fe6060f1SDimitry Andric#include <limits>
2880b57cec5SDimitry Andric#include <memory>
2890b57cec5SDimitry Andric#include <stdexcept>
290*fe6060f1SDimitry Andric#include <type_traits>
2910b57cec5SDimitry Andric#include <version>
2920b57cec5SDimitry Andric
2930b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2940b57cec5SDimitry Andric#pragma GCC system_header
2950b57cec5SDimitry Andric#endif
2960b57cec5SDimitry Andric
2970b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS
2980b57cec5SDimitry Andric#include <__undef_macros>
2990b57cec5SDimitry Andric
3000b57cec5SDimitry Andric
3010b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
3020b57cec5SDimitry Andric
3030b57cec5SDimitry Andrictemplate <bool>
304e40139ffSDimitry Andricclass _LIBCPP_TEMPLATE_VIS __vector_base_common
3050b57cec5SDimitry Andric{
3060b57cec5SDimitry Andricprotected:
3070b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY __vector_base_common() {}
3080b57cec5SDimitry Andric    _LIBCPP_NORETURN void __throw_length_error() const;
3090b57cec5SDimitry Andric    _LIBCPP_NORETURN void __throw_out_of_range() const;
3100b57cec5SDimitry Andric};
3110b57cec5SDimitry Andric
3120b57cec5SDimitry Andrictemplate <bool __b>
3130b57cec5SDimitry Andricvoid
3140b57cec5SDimitry Andric__vector_base_common<__b>::__throw_length_error() const
3150b57cec5SDimitry Andric{
3160b57cec5SDimitry Andric    _VSTD::__throw_length_error("vector");
3170b57cec5SDimitry Andric}
3180b57cec5SDimitry Andric
3190b57cec5SDimitry Andrictemplate <bool __b>
3200b57cec5SDimitry Andricvoid
3210b57cec5SDimitry Andric__vector_base_common<__b>::__throw_out_of_range() const
3220b57cec5SDimitry Andric{
3230b57cec5SDimitry Andric    _VSTD::__throw_out_of_range("vector");
3240b57cec5SDimitry Andric}
3250b57cec5SDimitry Andric
3260b57cec5SDimitry Andric_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __vector_base_common<true>)
3270b57cec5SDimitry Andric
3280b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
3290b57cec5SDimitry Andricclass __vector_base
3300b57cec5SDimitry Andric    : protected __vector_base_common<true>
3310b57cec5SDimitry Andric{
3320b57cec5SDimitry Andricpublic:
3330b57cec5SDimitry Andric    typedef _Allocator                               allocator_type;
3340b57cec5SDimitry Andric    typedef allocator_traits<allocator_type>         __alloc_traits;
3350b57cec5SDimitry Andric    typedef typename __alloc_traits::size_type       size_type;
3360b57cec5SDimitry Andricprotected:
3370b57cec5SDimitry Andric    typedef _Tp                                      value_type;
3380b57cec5SDimitry Andric    typedef value_type&                              reference;
3390b57cec5SDimitry Andric    typedef const value_type&                        const_reference;
3400b57cec5SDimitry Andric    typedef typename __alloc_traits::difference_type difference_type;
3410b57cec5SDimitry Andric    typedef typename __alloc_traits::pointer         pointer;
3420b57cec5SDimitry Andric    typedef typename __alloc_traits::const_pointer   const_pointer;
3430b57cec5SDimitry Andric    typedef pointer                                  iterator;
3440b57cec5SDimitry Andric    typedef const_pointer                            const_iterator;
3450b57cec5SDimitry Andric
3460b57cec5SDimitry Andric    pointer                                         __begin_;
3470b57cec5SDimitry Andric    pointer                                         __end_;
3480b57cec5SDimitry Andric    __compressed_pair<pointer, allocator_type> __end_cap_;
3490b57cec5SDimitry Andric
3500b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3510b57cec5SDimitry Andric    allocator_type& __alloc() _NOEXCEPT
3520b57cec5SDimitry Andric        {return __end_cap_.second();}
3530b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3540b57cec5SDimitry Andric    const allocator_type& __alloc() const _NOEXCEPT
3550b57cec5SDimitry Andric        {return __end_cap_.second();}
3560b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3570b57cec5SDimitry Andric    pointer& __end_cap() _NOEXCEPT
3580b57cec5SDimitry Andric        {return __end_cap_.first();}
3590b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3600b57cec5SDimitry Andric    const pointer& __end_cap() const _NOEXCEPT
3610b57cec5SDimitry Andric        {return __end_cap_.first();}
3620b57cec5SDimitry Andric
3630b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3640b57cec5SDimitry Andric    __vector_base()
3650b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
3660b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
3670b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
3680b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY __vector_base(allocator_type&& __a) _NOEXCEPT;
3690b57cec5SDimitry Andric#endif
3700b57cec5SDimitry Andric    ~__vector_base();
3710b57cec5SDimitry Andric
3720b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3730b57cec5SDimitry Andric    void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
3740b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3750b57cec5SDimitry Andric    size_type capacity() const _NOEXCEPT
3760b57cec5SDimitry Andric        {return static_cast<size_type>(__end_cap() - __begin_);}
3770b57cec5SDimitry Andric
3780b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3790b57cec5SDimitry Andric    void __destruct_at_end(pointer __new_last) _NOEXCEPT;
3800b57cec5SDimitry Andric
3810b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3820b57cec5SDimitry Andric    void __copy_assign_alloc(const __vector_base& __c)
3830b57cec5SDimitry Andric        {__copy_assign_alloc(__c, integral_constant<bool,
3840b57cec5SDimitry Andric                      __alloc_traits::propagate_on_container_copy_assignment::value>());}
3850b57cec5SDimitry Andric
3860b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3870b57cec5SDimitry Andric    void __move_assign_alloc(__vector_base& __c)
3880b57cec5SDimitry Andric        _NOEXCEPT_(
3890b57cec5SDimitry Andric            !__alloc_traits::propagate_on_container_move_assignment::value ||
3900b57cec5SDimitry Andric            is_nothrow_move_assignable<allocator_type>::value)
3910b57cec5SDimitry Andric        {__move_assign_alloc(__c, integral_constant<bool,
3920b57cec5SDimitry Andric                      __alloc_traits::propagate_on_container_move_assignment::value>());}
3930b57cec5SDimitry Andricprivate:
3940b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3950b57cec5SDimitry Andric    void __copy_assign_alloc(const __vector_base& __c, true_type)
3960b57cec5SDimitry Andric        {
3970b57cec5SDimitry Andric            if (__alloc() != __c.__alloc())
3980b57cec5SDimitry Andric            {
3990b57cec5SDimitry Andric                clear();
4000b57cec5SDimitry Andric                __alloc_traits::deallocate(__alloc(), __begin_, capacity());
4010b57cec5SDimitry Andric                __begin_ = __end_ = __end_cap() = nullptr;
4020b57cec5SDimitry Andric            }
4030b57cec5SDimitry Andric            __alloc() = __c.__alloc();
4040b57cec5SDimitry Andric        }
4050b57cec5SDimitry Andric
4060b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4070b57cec5SDimitry Andric    void __copy_assign_alloc(const __vector_base&, false_type)
4080b57cec5SDimitry Andric        {}
4090b57cec5SDimitry Andric
4100b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4110b57cec5SDimitry Andric    void __move_assign_alloc(__vector_base& __c, true_type)
4120b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
4130b57cec5SDimitry Andric        {
4140b57cec5SDimitry Andric            __alloc() = _VSTD::move(__c.__alloc());
4150b57cec5SDimitry Andric        }
4160b57cec5SDimitry Andric
4170b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4180b57cec5SDimitry Andric    void __move_assign_alloc(__vector_base&, false_type)
4190b57cec5SDimitry Andric        _NOEXCEPT
4200b57cec5SDimitry Andric        {}
4210b57cec5SDimitry Andric};
4220b57cec5SDimitry Andric
4230b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
4240b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
4250b57cec5SDimitry Andricvoid
4260b57cec5SDimitry Andric__vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT
4270b57cec5SDimitry Andric{
4280b57cec5SDimitry Andric    pointer __soon_to_be_end = __end_;
4290b57cec5SDimitry Andric    while (__new_last != __soon_to_be_end)
430480093f4SDimitry Andric        __alloc_traits::destroy(__alloc(), _VSTD::__to_address(--__soon_to_be_end));
4310b57cec5SDimitry Andric    __end_ = __new_last;
4320b57cec5SDimitry Andric}
4330b57cec5SDimitry Andric
4340b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
4350b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
4360b57cec5SDimitry Andric__vector_base<_Tp, _Allocator>::__vector_base()
4370b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
4380b57cec5SDimitry Andric    : __begin_(nullptr),
4390b57cec5SDimitry Andric      __end_(nullptr),
440480093f4SDimitry Andric      __end_cap_(nullptr, __default_init_tag())
4410b57cec5SDimitry Andric{
4420b57cec5SDimitry Andric}
4430b57cec5SDimitry Andric
4440b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
4450b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
4460b57cec5SDimitry Andric__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
4470b57cec5SDimitry Andric    : __begin_(nullptr),
4480b57cec5SDimitry Andric      __end_(nullptr),
4490b57cec5SDimitry Andric      __end_cap_(nullptr, __a)
4500b57cec5SDimitry Andric{
4510b57cec5SDimitry Andric}
4520b57cec5SDimitry Andric
4530b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
4540b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
4550b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
4560b57cec5SDimitry Andric__vector_base<_Tp, _Allocator>::__vector_base(allocator_type&& __a) _NOEXCEPT
4570b57cec5SDimitry Andric    : __begin_(nullptr),
4580b57cec5SDimitry Andric      __end_(nullptr),
459e8d8bef9SDimitry Andric      __end_cap_(nullptr, _VSTD::move(__a)) {}
4600b57cec5SDimitry Andric#endif
4610b57cec5SDimitry Andric
4620b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
4630b57cec5SDimitry Andric__vector_base<_Tp, _Allocator>::~__vector_base()
4640b57cec5SDimitry Andric{
4650b57cec5SDimitry Andric    if (__begin_ != nullptr)
4660b57cec5SDimitry Andric    {
4670b57cec5SDimitry Andric        clear();
4680b57cec5SDimitry Andric        __alloc_traits::deallocate(__alloc(), __begin_, capacity());
4690b57cec5SDimitry Andric    }
4700b57cec5SDimitry Andric}
4710b57cec5SDimitry Andric
4720b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator /* = allocator<_Tp> */>
4730b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector
4740b57cec5SDimitry Andric    : private __vector_base<_Tp, _Allocator>
4750b57cec5SDimitry Andric{
4760b57cec5SDimitry Andricprivate:
4770b57cec5SDimitry Andric    typedef __vector_base<_Tp, _Allocator>           __base;
4780b57cec5SDimitry Andric    typedef allocator<_Tp>                           __default_allocator_type;
4790b57cec5SDimitry Andricpublic:
4800b57cec5SDimitry Andric    typedef vector                                   __self;
4810b57cec5SDimitry Andric    typedef _Tp                                      value_type;
4820b57cec5SDimitry Andric    typedef _Allocator                               allocator_type;
4830b57cec5SDimitry Andric    typedef typename __base::__alloc_traits          __alloc_traits;
4840b57cec5SDimitry Andric    typedef typename __base::reference               reference;
4850b57cec5SDimitry Andric    typedef typename __base::const_reference         const_reference;
4860b57cec5SDimitry Andric    typedef typename __base::size_type               size_type;
4870b57cec5SDimitry Andric    typedef typename __base::difference_type         difference_type;
4880b57cec5SDimitry Andric    typedef typename __base::pointer                 pointer;
4890b57cec5SDimitry Andric    typedef typename __base::const_pointer           const_pointer;
4900b57cec5SDimitry Andric    typedef __wrap_iter<pointer>                     iterator;
4910b57cec5SDimitry Andric    typedef __wrap_iter<const_pointer>               const_iterator;
4920b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<iterator>         reverse_iterator;
4930b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<const_iterator>   const_reverse_iterator;
4940b57cec5SDimitry Andric
4950b57cec5SDimitry Andric    static_assert((is_same<typename allocator_type::value_type, value_type>::value),
4960b57cec5SDimitry Andric                  "Allocator::value_type must be same type as value_type");
4970b57cec5SDimitry Andric
4980b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
4990b57cec5SDimitry Andric    vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
5000b57cec5SDimitry Andric        {
501e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
5020b57cec5SDimitry Andric            __get_db()->__insert_c(this);
5030b57cec5SDimitry Andric#endif
5040b57cec5SDimitry Andric        }
5050b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
5060b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
5070b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
5080b57cec5SDimitry Andric#else
5090b57cec5SDimitry Andric        _NOEXCEPT
5100b57cec5SDimitry Andric#endif
5110b57cec5SDimitry Andric        : __base(__a)
5120b57cec5SDimitry Andric    {
513e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
5140b57cec5SDimitry Andric        __get_db()->__insert_c(this);
5150b57cec5SDimitry Andric#endif
5160b57cec5SDimitry Andric    }
5170b57cec5SDimitry Andric    explicit vector(size_type __n);
5180b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
5190b57cec5SDimitry Andric    explicit vector(size_type __n, const allocator_type& __a);
5200b57cec5SDimitry Andric#endif
5210b57cec5SDimitry Andric    vector(size_type __n, const value_type& __x);
5220b57cec5SDimitry Andric    vector(size_type __n, const value_type& __x, const allocator_type& __a);
5230b57cec5SDimitry Andric    template <class _InputIterator>
5240b57cec5SDimitry Andric        vector(_InputIterator __first,
525480093f4SDimitry Andric               typename enable_if<__is_cpp17_input_iterator  <_InputIterator>::value &&
526480093f4SDimitry Andric                                 !__is_cpp17_forward_iterator<_InputIterator>::value &&
5270b57cec5SDimitry Andric                                 is_constructible<
5280b57cec5SDimitry Andric                                    value_type,
5290b57cec5SDimitry Andric                                    typename iterator_traits<_InputIterator>::reference>::value,
5300b57cec5SDimitry Andric                                 _InputIterator>::type __last);
5310b57cec5SDimitry Andric    template <class _InputIterator>
5320b57cec5SDimitry Andric        vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
533480093f4SDimitry Andric               typename enable_if<__is_cpp17_input_iterator  <_InputIterator>::value &&
534480093f4SDimitry Andric                                 !__is_cpp17_forward_iterator<_InputIterator>::value &&
5350b57cec5SDimitry Andric                                 is_constructible<
5360b57cec5SDimitry Andric                                    value_type,
5370b57cec5SDimitry Andric                                    typename iterator_traits<_InputIterator>::reference>::value>::type* = 0);
5380b57cec5SDimitry Andric    template <class _ForwardIterator>
5390b57cec5SDimitry Andric        vector(_ForwardIterator __first,
540480093f4SDimitry Andric               typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
5410b57cec5SDimitry Andric                                 is_constructible<
5420b57cec5SDimitry Andric                                    value_type,
5430b57cec5SDimitry Andric                                    typename iterator_traits<_ForwardIterator>::reference>::value,
5440b57cec5SDimitry Andric                                 _ForwardIterator>::type __last);
5450b57cec5SDimitry Andric    template <class _ForwardIterator>
5460b57cec5SDimitry Andric        vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
547480093f4SDimitry Andric               typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
5480b57cec5SDimitry Andric                                 is_constructible<
5490b57cec5SDimitry Andric                                    value_type,
5500b57cec5SDimitry Andric                                    typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0);
5510b57cec5SDimitry Andric
5520b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5530b57cec5SDimitry Andric    ~vector()
5540b57cec5SDimitry Andric    {
5550b57cec5SDimitry Andric        __annotate_delete();
556e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
5570b57cec5SDimitry Andric        __get_db()->__erase_c(this);
5580b57cec5SDimitry Andric#endif
5590b57cec5SDimitry Andric    }
5600b57cec5SDimitry Andric
5610b57cec5SDimitry Andric    vector(const vector& __x);
562*fe6060f1SDimitry Andric    vector(const vector& __x, const __identity_t<allocator_type>& __a);
5630b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5640b57cec5SDimitry Andric    vector& operator=(const vector& __x);
5650b57cec5SDimitry Andric
5660b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
5670b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5680b57cec5SDimitry Andric    vector(initializer_list<value_type> __il);
5690b57cec5SDimitry Andric
5700b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5710b57cec5SDimitry Andric    vector(initializer_list<value_type> __il, const allocator_type& __a);
5720b57cec5SDimitry Andric
5730b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5740b57cec5SDimitry Andric    vector(vector&& __x)
5750b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
5760b57cec5SDimitry Andric        _NOEXCEPT;
5770b57cec5SDimitry Andric#else
5780b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
5790b57cec5SDimitry Andric#endif
5800b57cec5SDimitry Andric
5810b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
582*fe6060f1SDimitry Andric    vector(vector&& __x, const __identity_t<allocator_type>& __a);
5830b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5840b57cec5SDimitry Andric    vector& operator=(vector&& __x)
5850b57cec5SDimitry Andric        _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
5860b57cec5SDimitry Andric
5870b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
5880b57cec5SDimitry Andric    vector& operator=(initializer_list<value_type> __il)
5890b57cec5SDimitry Andric        {assign(__il.begin(), __il.end()); return *this;}
5900b57cec5SDimitry Andric
5910b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG
5920b57cec5SDimitry Andric
5930b57cec5SDimitry Andric    template <class _InputIterator>
5940b57cec5SDimitry Andric        typename enable_if
5950b57cec5SDimitry Andric        <
596480093f4SDimitry Andric             __is_cpp17_input_iterator  <_InputIterator>::value &&
597480093f4SDimitry Andric            !__is_cpp17_forward_iterator<_InputIterator>::value &&
5980b57cec5SDimitry Andric            is_constructible<
5990b57cec5SDimitry Andric                 value_type,
6000b57cec5SDimitry Andric                 typename iterator_traits<_InputIterator>::reference>::value,
6010b57cec5SDimitry Andric            void
6020b57cec5SDimitry Andric        >::type
6030b57cec5SDimitry Andric        assign(_InputIterator __first, _InputIterator __last);
6040b57cec5SDimitry Andric    template <class _ForwardIterator>
6050b57cec5SDimitry Andric        typename enable_if
6060b57cec5SDimitry Andric        <
607480093f4SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value &&
6080b57cec5SDimitry Andric            is_constructible<
6090b57cec5SDimitry Andric                 value_type,
6100b57cec5SDimitry Andric                 typename iterator_traits<_ForwardIterator>::reference>::value,
6110b57cec5SDimitry Andric            void
6120b57cec5SDimitry Andric        >::type
6130b57cec5SDimitry Andric        assign(_ForwardIterator __first, _ForwardIterator __last);
6140b57cec5SDimitry Andric
6150b57cec5SDimitry Andric    void assign(size_type __n, const_reference __u);
6160b57cec5SDimitry Andric
6170b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
6180b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6190b57cec5SDimitry Andric    void assign(initializer_list<value_type> __il)
6200b57cec5SDimitry Andric        {assign(__il.begin(), __il.end());}
6210b57cec5SDimitry Andric#endif
6220b57cec5SDimitry Andric
6230b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6240b57cec5SDimitry Andric    allocator_type get_allocator() const _NOEXCEPT
6250b57cec5SDimitry Andric        {return this->__alloc();}
6260b57cec5SDimitry Andric
6270b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY iterator               begin() _NOEXCEPT;
6280b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const_iterator         begin()   const _NOEXCEPT;
6290b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY iterator               end() _NOEXCEPT;
6300b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const_iterator         end()     const _NOEXCEPT;
6310b57cec5SDimitry Andric
6320b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6330b57cec5SDimitry Andric    reverse_iterator       rbegin() _NOEXCEPT
6340b57cec5SDimitry Andric        {return       reverse_iterator(end());}
6350b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6360b57cec5SDimitry Andric    const_reverse_iterator rbegin()  const _NOEXCEPT
6370b57cec5SDimitry Andric        {return const_reverse_iterator(end());}
6380b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6390b57cec5SDimitry Andric    reverse_iterator       rend() _NOEXCEPT
6400b57cec5SDimitry Andric        {return       reverse_iterator(begin());}
6410b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6420b57cec5SDimitry Andric    const_reverse_iterator rend()    const _NOEXCEPT
6430b57cec5SDimitry Andric        {return const_reverse_iterator(begin());}
6440b57cec5SDimitry Andric
6450b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6460b57cec5SDimitry Andric    const_iterator         cbegin()  const _NOEXCEPT
6470b57cec5SDimitry Andric        {return begin();}
6480b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6490b57cec5SDimitry Andric    const_iterator         cend()    const _NOEXCEPT
6500b57cec5SDimitry Andric        {return end();}
6510b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6520b57cec5SDimitry Andric    const_reverse_iterator crbegin() const _NOEXCEPT
6530b57cec5SDimitry Andric        {return rbegin();}
6540b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6550b57cec5SDimitry Andric    const_reverse_iterator crend()   const _NOEXCEPT
6560b57cec5SDimitry Andric        {return rend();}
6570b57cec5SDimitry Andric
6580b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6590b57cec5SDimitry Andric    size_type size() const _NOEXCEPT
6600b57cec5SDimitry Andric        {return static_cast<size_type>(this->__end_ - this->__begin_);}
6610b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6620b57cec5SDimitry Andric    size_type capacity() const _NOEXCEPT
6630b57cec5SDimitry Andric        {return __base::capacity();}
6640b57cec5SDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
6650b57cec5SDimitry Andric    bool empty() const _NOEXCEPT
6660b57cec5SDimitry Andric        {return this->__begin_ == this->__end_;}
6670b57cec5SDimitry Andric    size_type max_size() const _NOEXCEPT;
6680b57cec5SDimitry Andric    void reserve(size_type __n);
6690b57cec5SDimitry Andric    void shrink_to_fit() _NOEXCEPT;
6700b57cec5SDimitry Andric
6710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY reference       operator[](size_type __n) _NOEXCEPT;
6720b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const _NOEXCEPT;
6730b57cec5SDimitry Andric    reference       at(size_type __n);
6740b57cec5SDimitry Andric    const_reference at(size_type __n) const;
6750b57cec5SDimitry Andric
6760b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY reference       front() _NOEXCEPT
6770b57cec5SDimitry Andric    {
678*fe6060f1SDimitry Andric        _LIBCPP_ASSERT(!empty(), "front() called on an empty vector");
6790b57cec5SDimitry Andric        return *this->__begin_;
6800b57cec5SDimitry Andric    }
6810b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT
6820b57cec5SDimitry Andric    {
683*fe6060f1SDimitry Andric        _LIBCPP_ASSERT(!empty(), "front() called on an empty vector");
6840b57cec5SDimitry Andric        return *this->__begin_;
6850b57cec5SDimitry Andric    }
6860b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY reference       back() _NOEXCEPT
6870b57cec5SDimitry Andric    {
688*fe6060f1SDimitry Andric        _LIBCPP_ASSERT(!empty(), "back() called on an empty vector");
6890b57cec5SDimitry Andric        return *(this->__end_ - 1);
6900b57cec5SDimitry Andric    }
6910b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const_reference back()  const _NOEXCEPT
6920b57cec5SDimitry Andric    {
693*fe6060f1SDimitry Andric        _LIBCPP_ASSERT(!empty(), "back() called on an empty vector");
6940b57cec5SDimitry Andric        return *(this->__end_ - 1);
6950b57cec5SDimitry Andric    }
6960b57cec5SDimitry Andric
6970b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
6980b57cec5SDimitry Andric    value_type*       data() _NOEXCEPT
699480093f4SDimitry Andric        {return _VSTD::__to_address(this->__begin_);}
7000b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7010b57cec5SDimitry Andric    const value_type* data() const _NOEXCEPT
702480093f4SDimitry Andric        {return _VSTD::__to_address(this->__begin_);}
7030b57cec5SDimitry Andric
7040b57cec5SDimitry Andric#ifdef _LIBCPP_CXX03_LANG
7050b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7060b57cec5SDimitry Andric    void __emplace_back(const value_type& __x) { push_back(__x); }
7070b57cec5SDimitry Andric#else
7080b57cec5SDimitry Andric    template <class _Arg>
7090b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7100b57cec5SDimitry Andric    void __emplace_back(_Arg&& __arg) {
7110b57cec5SDimitry Andric      emplace_back(_VSTD::forward<_Arg>(__arg));
7120b57cec5SDimitry Andric    }
7130b57cec5SDimitry Andric#endif
7140b57cec5SDimitry Andric
7150b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
7160b57cec5SDimitry Andric
7170b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
7180b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
7190b57cec5SDimitry Andric
7200b57cec5SDimitry Andric    template <class... _Args>
7210b57cec5SDimitry Andric        _LIBCPP_INLINE_VISIBILITY
7220b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
7230b57cec5SDimitry Andric        reference emplace_back(_Args&&... __args);
7240b57cec5SDimitry Andric#else
7250b57cec5SDimitry Andric        void      emplace_back(_Args&&... __args);
7260b57cec5SDimitry Andric#endif
7270b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG
7280b57cec5SDimitry Andric
7290b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7300b57cec5SDimitry Andric    void pop_back();
7310b57cec5SDimitry Andric
7320b57cec5SDimitry Andric    iterator insert(const_iterator __position, const_reference __x);
7330b57cec5SDimitry Andric
7340b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
7350b57cec5SDimitry Andric    iterator insert(const_iterator __position, value_type&& __x);
7360b57cec5SDimitry Andric    template <class... _Args>
7370b57cec5SDimitry Andric        iterator emplace(const_iterator __position, _Args&&... __args);
7380b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG
7390b57cec5SDimitry Andric
7400b57cec5SDimitry Andric    iterator insert(const_iterator __position, size_type __n, const_reference __x);
7410b57cec5SDimitry Andric    template <class _InputIterator>
7420b57cec5SDimitry Andric        typename enable_if
7430b57cec5SDimitry Andric        <
744480093f4SDimitry Andric             __is_cpp17_input_iterator  <_InputIterator>::value &&
745480093f4SDimitry Andric            !__is_cpp17_forward_iterator<_InputIterator>::value &&
7460b57cec5SDimitry Andric            is_constructible<
7470b57cec5SDimitry Andric                 value_type,
7480b57cec5SDimitry Andric                 typename iterator_traits<_InputIterator>::reference>::value,
7490b57cec5SDimitry Andric            iterator
7500b57cec5SDimitry Andric        >::type
7510b57cec5SDimitry Andric        insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
7520b57cec5SDimitry Andric    template <class _ForwardIterator>
7530b57cec5SDimitry Andric        typename enable_if
7540b57cec5SDimitry Andric        <
755480093f4SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value &&
7560b57cec5SDimitry Andric            is_constructible<
7570b57cec5SDimitry Andric                 value_type,
7580b57cec5SDimitry Andric                 typename iterator_traits<_ForwardIterator>::reference>::value,
7590b57cec5SDimitry Andric            iterator
7600b57cec5SDimitry Andric        >::type
7610b57cec5SDimitry Andric        insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
7620b57cec5SDimitry Andric
7630b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
7640b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7650b57cec5SDimitry Andric    iterator insert(const_iterator __position, initializer_list<value_type> __il)
7660b57cec5SDimitry Andric        {return insert(__position, __il.begin(), __il.end());}
7670b57cec5SDimitry Andric#endif
7680b57cec5SDimitry Andric
7690b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
7700b57cec5SDimitry Andric    iterator erase(const_iterator __first, const_iterator __last);
7710b57cec5SDimitry Andric
7720b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
7730b57cec5SDimitry Andric    void clear() _NOEXCEPT
7740b57cec5SDimitry Andric    {
7750b57cec5SDimitry Andric        size_type __old_size = size();
7760b57cec5SDimitry Andric        __base::clear();
7770b57cec5SDimitry Andric        __annotate_shrink(__old_size);
7780b57cec5SDimitry Andric        __invalidate_all_iterators();
7790b57cec5SDimitry Andric    }
7800b57cec5SDimitry Andric
7810b57cec5SDimitry Andric    void resize(size_type __sz);
7820b57cec5SDimitry Andric    void resize(size_type __sz, const_reference __x);
7830b57cec5SDimitry Andric
7840b57cec5SDimitry Andric    void swap(vector&)
7850b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
7860b57cec5SDimitry Andric        _NOEXCEPT;
7870b57cec5SDimitry Andric#else
7880b57cec5SDimitry Andric        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
7890b57cec5SDimitry Andric                    __is_nothrow_swappable<allocator_type>::value);
7900b57cec5SDimitry Andric#endif
7910b57cec5SDimitry Andric
7920b57cec5SDimitry Andric    bool __invariants() const;
7930b57cec5SDimitry Andric
794e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
7950b57cec5SDimitry Andric
7960b57cec5SDimitry Andric    bool __dereferenceable(const const_iterator* __i) const;
7970b57cec5SDimitry Andric    bool __decrementable(const const_iterator* __i) const;
7980b57cec5SDimitry Andric    bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
7990b57cec5SDimitry Andric    bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
8000b57cec5SDimitry Andric
801e8d8bef9SDimitry Andric#endif // _LIBCPP_DEBUG_LEVEL == 2
8020b57cec5SDimitry Andric
8030b57cec5SDimitry Andricprivate:
8040b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
8050b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last);
8060b57cec5SDimitry Andric    void __vallocate(size_type __n);
8070b57cec5SDimitry Andric    void __vdeallocate() _NOEXCEPT;
8080b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
8090b57cec5SDimitry Andric    void __construct_at_end(size_type __n);
8100b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8110b57cec5SDimitry Andric    void __construct_at_end(size_type __n, const_reference __x);
8120b57cec5SDimitry Andric    template <class _ForwardIterator>
8130b57cec5SDimitry Andric        typename enable_if
8140b57cec5SDimitry Andric        <
815480093f4SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value,
8160b57cec5SDimitry Andric            void
8170b57cec5SDimitry Andric        >::type
8180b57cec5SDimitry Andric        __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n);
8190b57cec5SDimitry Andric    void __append(size_type __n);
8200b57cec5SDimitry Andric    void __append(size_type __n, const_reference __x);
8210b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8220b57cec5SDimitry Andric    iterator       __make_iter(pointer __p) _NOEXCEPT;
8230b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8240b57cec5SDimitry Andric    const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
8250b57cec5SDimitry Andric    void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
8260b57cec5SDimitry Andric    pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
8270b57cec5SDimitry Andric    void __move_range(pointer __from_s, pointer __from_e, pointer __to);
8280b57cec5SDimitry Andric    void __move_assign(vector& __c, true_type)
8290b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
8300b57cec5SDimitry Andric    void __move_assign(vector& __c, false_type)
8310b57cec5SDimitry Andric        _NOEXCEPT_(__alloc_traits::is_always_equal::value);
8320b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8330b57cec5SDimitry Andric    void __destruct_at_end(pointer __new_last) _NOEXCEPT
8340b57cec5SDimitry Andric    {
8350b57cec5SDimitry Andric        __invalidate_iterators_past(__new_last);
8360b57cec5SDimitry Andric        size_type __old_size = size();
8370b57cec5SDimitry Andric        __base::__destruct_at_end(__new_last);
8380b57cec5SDimitry Andric        __annotate_shrink(__old_size);
8390b57cec5SDimitry Andric    }
8400b57cec5SDimitry Andric
8410b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
8420b57cec5SDimitry Andric    template <class _Up>
8430b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8440b57cec5SDimitry Andric    inline void __push_back_slow_path(_Up&& __x);
8450b57cec5SDimitry Andric
8460b57cec5SDimitry Andric    template <class... _Args>
8470b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8480b57cec5SDimitry Andric    inline void __emplace_back_slow_path(_Args&&... __args);
8490b57cec5SDimitry Andric#else
8500b57cec5SDimitry Andric    template <class _Up>
8510b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8520b57cec5SDimitry Andric    inline void __push_back_slow_path(_Up& __x);
8530b57cec5SDimitry Andric#endif
8540b57cec5SDimitry Andric
8550b57cec5SDimitry Andric    // The following functions are no-ops outside of AddressSanitizer mode.
8560b57cec5SDimitry Andric    // We call annotatations only for the default Allocator because other allocators
8570b57cec5SDimitry Andric    // may not meet the AddressSanitizer alignment constraints.
8580b57cec5SDimitry Andric    // See the documentation for __sanitizer_annotate_contiguous_container for more details.
8590b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
8600b57cec5SDimitry Andric    void __annotate_contiguous_container(const void *__beg, const void *__end,
8610b57cec5SDimitry Andric                                         const void *__old_mid,
8620b57cec5SDimitry Andric                                         const void *__new_mid) const
8630b57cec5SDimitry Andric    {
8640b57cec5SDimitry Andric
8650b57cec5SDimitry Andric      if (__beg && is_same<allocator_type, __default_allocator_type>::value)
8660b57cec5SDimitry Andric        __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
8670b57cec5SDimitry Andric    }
8680b57cec5SDimitry Andric#else
8690b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
8700b57cec5SDimitry Andric    void __annotate_contiguous_container(const void*, const void*, const void*,
871e40139ffSDimitry Andric                                         const void*) const _NOEXCEPT {}
8720b57cec5SDimitry Andric#endif
8730b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
874e40139ffSDimitry Andric    void __annotate_new(size_type __current_size) const _NOEXCEPT {
8750b57cec5SDimitry Andric      __annotate_contiguous_container(data(), data() + capacity(),
8760b57cec5SDimitry Andric                                      data() + capacity(), data() + __current_size);
8770b57cec5SDimitry Andric    }
8780b57cec5SDimitry Andric
8790b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
880e40139ffSDimitry Andric    void __annotate_delete() const _NOEXCEPT {
8810b57cec5SDimitry Andric      __annotate_contiguous_container(data(), data() + capacity(),
8820b57cec5SDimitry Andric                                      data() + size(), data() + capacity());
8830b57cec5SDimitry Andric    }
8840b57cec5SDimitry Andric
8850b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
886e40139ffSDimitry Andric    void __annotate_increase(size_type __n) const _NOEXCEPT
8870b57cec5SDimitry Andric    {
8880b57cec5SDimitry Andric      __annotate_contiguous_container(data(), data() + capacity(),
8890b57cec5SDimitry Andric                                      data() + size(), data() + size() + __n);
8900b57cec5SDimitry Andric    }
8910b57cec5SDimitry Andric
8920b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
893e40139ffSDimitry Andric    void __annotate_shrink(size_type __old_size) const _NOEXCEPT
8940b57cec5SDimitry Andric    {
8950b57cec5SDimitry Andric      __annotate_contiguous_container(data(), data() + capacity(),
8960b57cec5SDimitry Andric                                      data() + __old_size, data() + size());
8970b57cec5SDimitry Andric    }
8980b57cec5SDimitry Andric
899e40139ffSDimitry Andric  struct _ConstructTransaction {
900e40139ffSDimitry Andric    explicit _ConstructTransaction(vector &__v, size_type __n)
901e40139ffSDimitry Andric      : __v_(__v),  __pos_(__v.__end_), __new_end_(__v.__end_ + __n) {
902e40139ffSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
903e40139ffSDimitry Andric      __v_.__annotate_increase(__n);
904e40139ffSDimitry Andric#endif
905e40139ffSDimitry Andric    }
906e40139ffSDimitry Andric    ~_ConstructTransaction() {
907e40139ffSDimitry Andric      __v_.__end_ = __pos_;
908e40139ffSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
909e40139ffSDimitry Andric      if (__pos_ != __new_end_) {
910e40139ffSDimitry Andric        __v_.__annotate_shrink(__new_end_ - __v_.__begin_);
911e40139ffSDimitry Andric      }
912e40139ffSDimitry Andric#endif
913e40139ffSDimitry Andric    }
914e40139ffSDimitry Andric
915e40139ffSDimitry Andric    vector &__v_;
916e40139ffSDimitry Andric    pointer __pos_;
917e40139ffSDimitry Andric    const_pointer const __new_end_;
918e40139ffSDimitry Andric
919e40139ffSDimitry Andric  private:
920e40139ffSDimitry Andric    _ConstructTransaction(_ConstructTransaction const&) = delete;
921e40139ffSDimitry Andric    _ConstructTransaction& operator=(_ConstructTransaction const&) = delete;
922e40139ffSDimitry Andric  };
923e40139ffSDimitry Andric
924e40139ffSDimitry Andric  template <class ..._Args>
925e40139ffSDimitry Andric  _LIBCPP_INLINE_VISIBILITY
926e40139ffSDimitry Andric  void __construct_one_at_end(_Args&& ...__args) {
927e40139ffSDimitry Andric    _ConstructTransaction __tx(*this, 1);
928480093f4SDimitry Andric    __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__tx.__pos_),
929e40139ffSDimitry Andric        _VSTD::forward<_Args>(__args)...);
930e40139ffSDimitry Andric    ++__tx.__pos_;
931e40139ffSDimitry Andric  }
9320b57cec5SDimitry Andric};
9330b57cec5SDimitry Andric
9340b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
9350b57cec5SDimitry Andrictemplate<class _InputIterator,
936*fe6060f1SDimitry Andric         class _Alloc = allocator<__iter_value_type<_InputIterator>>,
937*fe6060f1SDimitry Andric         class = _EnableIf<__is_allocator<_Alloc>::value>
9380b57cec5SDimitry Andric         >
9390b57cec5SDimitry Andricvector(_InputIterator, _InputIterator)
940*fe6060f1SDimitry Andric  -> vector<__iter_value_type<_InputIterator>, _Alloc>;
9410b57cec5SDimitry Andric
9420b57cec5SDimitry Andrictemplate<class _InputIterator,
9430b57cec5SDimitry Andric         class _Alloc,
944*fe6060f1SDimitry Andric         class = _EnableIf<__is_allocator<_Alloc>::value>
9450b57cec5SDimitry Andric         >
9460b57cec5SDimitry Andricvector(_InputIterator, _InputIterator, _Alloc)
947*fe6060f1SDimitry Andric  -> vector<__iter_value_type<_InputIterator>, _Alloc>;
9480b57cec5SDimitry Andric#endif
9490b57cec5SDimitry Andric
9500b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
9510b57cec5SDimitry Andricvoid
9520b57cec5SDimitry Andricvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
9530b57cec5SDimitry Andric{
954e40139ffSDimitry Andric
9550b57cec5SDimitry Andric    __annotate_delete();
956e8d8bef9SDimitry Andric    _VSTD::__construct_backward_with_exception_guarantees(this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
9570b57cec5SDimitry Andric    _VSTD::swap(this->__begin_, __v.__begin_);
9580b57cec5SDimitry Andric    _VSTD::swap(this->__end_, __v.__end_);
9590b57cec5SDimitry Andric    _VSTD::swap(this->__end_cap(), __v.__end_cap());
9600b57cec5SDimitry Andric    __v.__first_ = __v.__begin_;
9610b57cec5SDimitry Andric    __annotate_new(size());
9620b57cec5SDimitry Andric    __invalidate_all_iterators();
9630b57cec5SDimitry Andric}
9640b57cec5SDimitry Andric
9650b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
9660b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::pointer
9670b57cec5SDimitry Andricvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
9680b57cec5SDimitry Andric{
9690b57cec5SDimitry Andric    __annotate_delete();
9700b57cec5SDimitry Andric    pointer __r = __v.__begin_;
971e8d8bef9SDimitry Andric    _VSTD::__construct_backward_with_exception_guarantees(this->__alloc(), this->__begin_, __p, __v.__begin_);
972e8d8bef9SDimitry Andric    _VSTD::__construct_forward_with_exception_guarantees(this->__alloc(), __p, this->__end_, __v.__end_);
9730b57cec5SDimitry Andric    _VSTD::swap(this->__begin_, __v.__begin_);
9740b57cec5SDimitry Andric    _VSTD::swap(this->__end_, __v.__end_);
9750b57cec5SDimitry Andric    _VSTD::swap(this->__end_cap(), __v.__end_cap());
9760b57cec5SDimitry Andric    __v.__first_ = __v.__begin_;
9770b57cec5SDimitry Andric    __annotate_new(size());
9780b57cec5SDimitry Andric    __invalidate_all_iterators();
9790b57cec5SDimitry Andric    return __r;
9800b57cec5SDimitry Andric}
9810b57cec5SDimitry Andric
9820b57cec5SDimitry Andric//  Allocate space for __n objects
9830b57cec5SDimitry Andric//  throws length_error if __n > max_size()
9840b57cec5SDimitry Andric//  throws (probably bad_alloc) if memory run out
9850b57cec5SDimitry Andric//  Precondition:  __begin_ == __end_ == __end_cap() == 0
9860b57cec5SDimitry Andric//  Precondition:  __n > 0
9870b57cec5SDimitry Andric//  Postcondition:  capacity() == __n
9880b57cec5SDimitry Andric//  Postcondition:  size() == 0
9890b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
9900b57cec5SDimitry Andricvoid
9910b57cec5SDimitry Andricvector<_Tp, _Allocator>::__vallocate(size_type __n)
9920b57cec5SDimitry Andric{
9930b57cec5SDimitry Andric    if (__n > max_size())
9940b57cec5SDimitry Andric        this->__throw_length_error();
9950b57cec5SDimitry Andric    this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
9960b57cec5SDimitry Andric    this->__end_cap() = this->__begin_ + __n;
9970b57cec5SDimitry Andric    __annotate_new(0);
9980b57cec5SDimitry Andric}
9990b57cec5SDimitry Andric
10000b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
10010b57cec5SDimitry Andricvoid
10020b57cec5SDimitry Andricvector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT
10030b57cec5SDimitry Andric{
10040b57cec5SDimitry Andric    if (this->__begin_ != nullptr)
10050b57cec5SDimitry Andric    {
10060b57cec5SDimitry Andric        clear();
10070b57cec5SDimitry Andric        __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
10080b57cec5SDimitry Andric        this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
10090b57cec5SDimitry Andric    }
10100b57cec5SDimitry Andric}
10110b57cec5SDimitry Andric
10120b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
10130b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::size_type
10140b57cec5SDimitry Andricvector<_Tp, _Allocator>::max_size() const _NOEXCEPT
10150b57cec5SDimitry Andric{
10160b57cec5SDimitry Andric    return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()),
10170b57cec5SDimitry Andric                                 numeric_limits<difference_type>::max());
10180b57cec5SDimitry Andric}
10190b57cec5SDimitry Andric
10200b57cec5SDimitry Andric//  Precondition:  __new_size > capacity()
10210b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
10220b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
10230b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::size_type
10240b57cec5SDimitry Andricvector<_Tp, _Allocator>::__recommend(size_type __new_size) const
10250b57cec5SDimitry Andric{
10260b57cec5SDimitry Andric    const size_type __ms = max_size();
10270b57cec5SDimitry Andric    if (__new_size > __ms)
10280b57cec5SDimitry Andric        this->__throw_length_error();
10290b57cec5SDimitry Andric    const size_type __cap = capacity();
10300b57cec5SDimitry Andric    if (__cap >= __ms / 2)
10310b57cec5SDimitry Andric        return __ms;
10320b57cec5SDimitry Andric    return _VSTD::max<size_type>(2 * __cap, __new_size);
10330b57cec5SDimitry Andric}
10340b57cec5SDimitry Andric
10350b57cec5SDimitry Andric//  Default constructs __n objects starting at __end_
10360b57cec5SDimitry Andric//  throws if construction throws
10370b57cec5SDimitry Andric//  Precondition:  __n > 0
10380b57cec5SDimitry Andric//  Precondition:  size() + __n <= capacity()
10390b57cec5SDimitry Andric//  Postcondition:  size() == size() + __n
10400b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
10410b57cec5SDimitry Andricvoid
10420b57cec5SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(size_type __n)
10430b57cec5SDimitry Andric{
1044e40139ffSDimitry Andric    _ConstructTransaction __tx(*this, __n);
10455ffd83dbSDimitry Andric    const_pointer __new_end = __tx.__new_end_;
10465ffd83dbSDimitry Andric    for (pointer __pos = __tx.__pos_; __pos != __new_end; ++__pos, __tx.__pos_ = __pos) {
10475ffd83dbSDimitry Andric        __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos));
1048e40139ffSDimitry Andric    }
10490b57cec5SDimitry Andric}
10500b57cec5SDimitry Andric
10510b57cec5SDimitry Andric//  Copy constructs __n objects starting at __end_ from __x
10520b57cec5SDimitry Andric//  throws if construction throws
10530b57cec5SDimitry Andric//  Precondition:  __n > 0
10540b57cec5SDimitry Andric//  Precondition:  size() + __n <= capacity()
10550b57cec5SDimitry Andric//  Postcondition:  size() == old size() + __n
10560b57cec5SDimitry Andric//  Postcondition:  [i] == __x for all i in [size() - __n, __n)
10570b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
10580b57cec5SDimitry Andricinline
10590b57cec5SDimitry Andricvoid
10600b57cec5SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
10610b57cec5SDimitry Andric{
1062e40139ffSDimitry Andric    _ConstructTransaction __tx(*this, __n);
10635ffd83dbSDimitry Andric    const_pointer __new_end = __tx.__new_end_;
10645ffd83dbSDimitry Andric    for (pointer __pos = __tx.__pos_; __pos != __new_end; ++__pos, __tx.__pos_ = __pos) {
10655ffd83dbSDimitry Andric        __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos), __x);
1066e40139ffSDimitry Andric    }
10670b57cec5SDimitry Andric}
10680b57cec5SDimitry Andric
10690b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
10700b57cec5SDimitry Andrictemplate <class _ForwardIterator>
10710b57cec5SDimitry Andrictypename enable_if
10720b57cec5SDimitry Andric<
1073480093f4SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value,
10740b57cec5SDimitry Andric    void
10750b57cec5SDimitry Andric>::type
10760b57cec5SDimitry Andricvector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n)
10770b57cec5SDimitry Andric{
1078e40139ffSDimitry Andric    _ConstructTransaction __tx(*this, __n);
1079e8d8bef9SDimitry Andric    _VSTD::__construct_range_forward(this->__alloc(), __first, __last, __tx.__pos_);
10800b57cec5SDimitry Andric}
10810b57cec5SDimitry Andric
10820b57cec5SDimitry Andric//  Default constructs __n objects starting at __end_
10830b57cec5SDimitry Andric//  throws if construction throws
10840b57cec5SDimitry Andric//  Postcondition:  size() == size() + __n
10850b57cec5SDimitry Andric//  Exception safety: strong.
10860b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
10870b57cec5SDimitry Andricvoid
10880b57cec5SDimitry Andricvector<_Tp, _Allocator>::__append(size_type __n)
10890b57cec5SDimitry Andric{
10900b57cec5SDimitry Andric    if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
10910b57cec5SDimitry Andric        this->__construct_at_end(__n);
10920b57cec5SDimitry Andric    else
10930b57cec5SDimitry Andric    {
10940b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
10950b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
10960b57cec5SDimitry Andric        __v.__construct_at_end(__n);
10970b57cec5SDimitry Andric        __swap_out_circular_buffer(__v);
10980b57cec5SDimitry Andric    }
10990b57cec5SDimitry Andric}
11000b57cec5SDimitry Andric
11010b57cec5SDimitry Andric//  Default constructs __n objects starting at __end_
11020b57cec5SDimitry Andric//  throws if construction throws
11030b57cec5SDimitry Andric//  Postcondition:  size() == size() + __n
11040b57cec5SDimitry Andric//  Exception safety: strong.
11050b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
11060b57cec5SDimitry Andricvoid
11070b57cec5SDimitry Andricvector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
11080b57cec5SDimitry Andric{
11090b57cec5SDimitry Andric    if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
11100b57cec5SDimitry Andric        this->__construct_at_end(__n, __x);
11110b57cec5SDimitry Andric    else
11120b57cec5SDimitry Andric    {
11130b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
11140b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
11150b57cec5SDimitry Andric        __v.__construct_at_end(__n, __x);
11160b57cec5SDimitry Andric        __swap_out_circular_buffer(__v);
11170b57cec5SDimitry Andric    }
11180b57cec5SDimitry Andric}
11190b57cec5SDimitry Andric
11200b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
11210b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n)
11220b57cec5SDimitry Andric{
1123e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
11240b57cec5SDimitry Andric    __get_db()->__insert_c(this);
11250b57cec5SDimitry Andric#endif
11260b57cec5SDimitry Andric    if (__n > 0)
11270b57cec5SDimitry Andric    {
11280b57cec5SDimitry Andric        __vallocate(__n);
11290b57cec5SDimitry Andric        __construct_at_end(__n);
11300b57cec5SDimitry Andric    }
11310b57cec5SDimitry Andric}
11320b57cec5SDimitry Andric
11330b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
11340b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
11350b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
11360b57cec5SDimitry Andric    : __base(__a)
11370b57cec5SDimitry Andric{
1138e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
11390b57cec5SDimitry Andric    __get_db()->__insert_c(this);
11400b57cec5SDimitry Andric#endif
11410b57cec5SDimitry Andric    if (__n > 0)
11420b57cec5SDimitry Andric    {
11430b57cec5SDimitry Andric        __vallocate(__n);
11440b57cec5SDimitry Andric        __construct_at_end(__n);
11450b57cec5SDimitry Andric    }
11460b57cec5SDimitry Andric}
11470b57cec5SDimitry Andric#endif
11480b57cec5SDimitry Andric
11490b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
11500b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x)
11510b57cec5SDimitry Andric{
1152e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
11530b57cec5SDimitry Andric    __get_db()->__insert_c(this);
11540b57cec5SDimitry Andric#endif
11550b57cec5SDimitry Andric    if (__n > 0)
11560b57cec5SDimitry Andric    {
11570b57cec5SDimitry Andric        __vallocate(__n);
11580b57cec5SDimitry Andric        __construct_at_end(__n, __x);
11590b57cec5SDimitry Andric    }
11600b57cec5SDimitry Andric}
11610b57cec5SDimitry Andric
11620b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
11630b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
11640b57cec5SDimitry Andric    : __base(__a)
11650b57cec5SDimitry Andric{
1166e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
11670b57cec5SDimitry Andric    __get_db()->__insert_c(this);
11680b57cec5SDimitry Andric#endif
11690b57cec5SDimitry Andric    if (__n > 0)
11700b57cec5SDimitry Andric    {
11710b57cec5SDimitry Andric        __vallocate(__n);
11720b57cec5SDimitry Andric        __construct_at_end(__n, __x);
11730b57cec5SDimitry Andric    }
11740b57cec5SDimitry Andric}
11750b57cec5SDimitry Andric
11760b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
11770b57cec5SDimitry Andrictemplate <class _InputIterator>
11780b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_InputIterator __first,
1179480093f4SDimitry Andric       typename enable_if<__is_cpp17_input_iterator  <_InputIterator>::value &&
1180480093f4SDimitry Andric                         !__is_cpp17_forward_iterator<_InputIterator>::value &&
11810b57cec5SDimitry Andric                         is_constructible<
11820b57cec5SDimitry Andric                            value_type,
11830b57cec5SDimitry Andric                            typename iterator_traits<_InputIterator>::reference>::value,
11840b57cec5SDimitry Andric                          _InputIterator>::type __last)
11850b57cec5SDimitry Andric{
1186e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
11870b57cec5SDimitry Andric    __get_db()->__insert_c(this);
11880b57cec5SDimitry Andric#endif
11890b57cec5SDimitry Andric    for (; __first != __last; ++__first)
11900b57cec5SDimitry Andric        __emplace_back(*__first);
11910b57cec5SDimitry Andric}
11920b57cec5SDimitry Andric
11930b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
11940b57cec5SDimitry Andrictemplate <class _InputIterator>
11950b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1196480093f4SDimitry Andric       typename enable_if<__is_cpp17_input_iterator  <_InputIterator>::value &&
1197480093f4SDimitry Andric                         !__is_cpp17_forward_iterator<_InputIterator>::value &&
11980b57cec5SDimitry Andric                         is_constructible<
11990b57cec5SDimitry Andric                            value_type,
12000b57cec5SDimitry Andric                            typename iterator_traits<_InputIterator>::reference>::value>::type*)
12010b57cec5SDimitry Andric    : __base(__a)
12020b57cec5SDimitry Andric{
1203e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
12040b57cec5SDimitry Andric    __get_db()->__insert_c(this);
12050b57cec5SDimitry Andric#endif
12060b57cec5SDimitry Andric    for (; __first != __last; ++__first)
12070b57cec5SDimitry Andric        __emplace_back(*__first);
12080b57cec5SDimitry Andric}
12090b57cec5SDimitry Andric
12100b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
12110b57cec5SDimitry Andrictemplate <class _ForwardIterator>
12120b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_ForwardIterator __first,
1213480093f4SDimitry Andric                                typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
12140b57cec5SDimitry Andric                                is_constructible<
12150b57cec5SDimitry Andric                                   value_type,
12160b57cec5SDimitry Andric                                   typename iterator_traits<_ForwardIterator>::reference>::value,
12170b57cec5SDimitry Andric                                                   _ForwardIterator>::type __last)
12180b57cec5SDimitry Andric{
1219e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
12200b57cec5SDimitry Andric    __get_db()->__insert_c(this);
12210b57cec5SDimitry Andric#endif
12220b57cec5SDimitry Andric    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
12230b57cec5SDimitry Andric    if (__n > 0)
12240b57cec5SDimitry Andric    {
12250b57cec5SDimitry Andric        __vallocate(__n);
12260b57cec5SDimitry Andric        __construct_at_end(__first, __last, __n);
12270b57cec5SDimitry Andric    }
12280b57cec5SDimitry Andric}
12290b57cec5SDimitry Andric
12300b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
12310b57cec5SDimitry Andrictemplate <class _ForwardIterator>
12320b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
1233480093f4SDimitry Andric                                typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value &&
12340b57cec5SDimitry Andric                                is_constructible<
12350b57cec5SDimitry Andric                                   value_type,
12360b57cec5SDimitry Andric                                   typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
12370b57cec5SDimitry Andric    : __base(__a)
12380b57cec5SDimitry Andric{
1239e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
12400b57cec5SDimitry Andric    __get_db()->__insert_c(this);
12410b57cec5SDimitry Andric#endif
12420b57cec5SDimitry Andric    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
12430b57cec5SDimitry Andric    if (__n > 0)
12440b57cec5SDimitry Andric    {
12450b57cec5SDimitry Andric        __vallocate(__n);
12460b57cec5SDimitry Andric        __construct_at_end(__first, __last, __n);
12470b57cec5SDimitry Andric    }
12480b57cec5SDimitry Andric}
12490b57cec5SDimitry Andric
12500b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
12510b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(const vector& __x)
12520b57cec5SDimitry Andric    : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
12530b57cec5SDimitry Andric{
1254e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
12550b57cec5SDimitry Andric    __get_db()->__insert_c(this);
12560b57cec5SDimitry Andric#endif
12570b57cec5SDimitry Andric    size_type __n = __x.size();
12580b57cec5SDimitry Andric    if (__n > 0)
12590b57cec5SDimitry Andric    {
12600b57cec5SDimitry Andric        __vallocate(__n);
12610b57cec5SDimitry Andric        __construct_at_end(__x.__begin_, __x.__end_, __n);
12620b57cec5SDimitry Andric    }
12630b57cec5SDimitry Andric}
12640b57cec5SDimitry Andric
12650b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
1266*fe6060f1SDimitry Andricvector<_Tp, _Allocator>::vector(const vector& __x, const __identity_t<allocator_type>& __a)
12670b57cec5SDimitry Andric    : __base(__a)
12680b57cec5SDimitry Andric{
1269e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
12700b57cec5SDimitry Andric    __get_db()->__insert_c(this);
12710b57cec5SDimitry Andric#endif
12720b57cec5SDimitry Andric    size_type __n = __x.size();
12730b57cec5SDimitry Andric    if (__n > 0)
12740b57cec5SDimitry Andric    {
12750b57cec5SDimitry Andric        __vallocate(__n);
12760b57cec5SDimitry Andric        __construct_at_end(__x.__begin_, __x.__end_, __n);
12770b57cec5SDimitry Andric    }
12780b57cec5SDimitry Andric}
12790b57cec5SDimitry Andric
12800b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
12810b57cec5SDimitry Andric
12820b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
12830b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
12840b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(vector&& __x)
12850b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
12860b57cec5SDimitry Andric        _NOEXCEPT
12870b57cec5SDimitry Andric#else
12880b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
12890b57cec5SDimitry Andric#endif
12900b57cec5SDimitry Andric    : __base(_VSTD::move(__x.__alloc()))
12910b57cec5SDimitry Andric{
1292e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
12930b57cec5SDimitry Andric    __get_db()->__insert_c(this);
12940b57cec5SDimitry Andric    __get_db()->swap(this, &__x);
12950b57cec5SDimitry Andric#endif
12960b57cec5SDimitry Andric    this->__begin_ = __x.__begin_;
12970b57cec5SDimitry Andric    this->__end_ = __x.__end_;
12980b57cec5SDimitry Andric    this->__end_cap() = __x.__end_cap();
12990b57cec5SDimitry Andric    __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
13000b57cec5SDimitry Andric}
13010b57cec5SDimitry Andric
13020b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
13030b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
1304*fe6060f1SDimitry Andricvector<_Tp, _Allocator>::vector(vector&& __x, const __identity_t<allocator_type>& __a)
13050b57cec5SDimitry Andric    : __base(__a)
13060b57cec5SDimitry Andric{
1307e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
13080b57cec5SDimitry Andric    __get_db()->__insert_c(this);
13090b57cec5SDimitry Andric#endif
13100b57cec5SDimitry Andric    if (__a == __x.__alloc())
13110b57cec5SDimitry Andric    {
13120b57cec5SDimitry Andric        this->__begin_ = __x.__begin_;
13130b57cec5SDimitry Andric        this->__end_ = __x.__end_;
13140b57cec5SDimitry Andric        this->__end_cap() = __x.__end_cap();
13150b57cec5SDimitry Andric        __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1316e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
13170b57cec5SDimitry Andric        __get_db()->swap(this, &__x);
13180b57cec5SDimitry Andric#endif
13190b57cec5SDimitry Andric    }
13200b57cec5SDimitry Andric    else
13210b57cec5SDimitry Andric    {
13220b57cec5SDimitry Andric        typedef move_iterator<iterator> _Ip;
13230b57cec5SDimitry Andric        assign(_Ip(__x.begin()), _Ip(__x.end()));
13240b57cec5SDimitry Andric    }
13250b57cec5SDimitry Andric}
13260b57cec5SDimitry Andric
13270b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
13280b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
13290b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
13300b57cec5SDimitry Andric{
1331e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
13320b57cec5SDimitry Andric    __get_db()->__insert_c(this);
13330b57cec5SDimitry Andric#endif
13340b57cec5SDimitry Andric    if (__il.size() > 0)
13350b57cec5SDimitry Andric    {
13360b57cec5SDimitry Andric        __vallocate(__il.size());
13370b57cec5SDimitry Andric        __construct_at_end(__il.begin(), __il.end(), __il.size());
13380b57cec5SDimitry Andric    }
13390b57cec5SDimitry Andric}
13400b57cec5SDimitry Andric
13410b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
13420b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
13430b57cec5SDimitry Andricvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
13440b57cec5SDimitry Andric    : __base(__a)
13450b57cec5SDimitry Andric{
1346e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
13470b57cec5SDimitry Andric    __get_db()->__insert_c(this);
13480b57cec5SDimitry Andric#endif
13490b57cec5SDimitry Andric    if (__il.size() > 0)
13500b57cec5SDimitry Andric    {
13510b57cec5SDimitry Andric        __vallocate(__il.size());
13520b57cec5SDimitry Andric        __construct_at_end(__il.begin(), __il.end(), __il.size());
13530b57cec5SDimitry Andric    }
13540b57cec5SDimitry Andric}
13550b57cec5SDimitry Andric
13560b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
13570b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
13580b57cec5SDimitry Andricvector<_Tp, _Allocator>&
13590b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator=(vector&& __x)
13600b57cec5SDimitry Andric    _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
13610b57cec5SDimitry Andric{
13620b57cec5SDimitry Andric    __move_assign(__x, integral_constant<bool,
13630b57cec5SDimitry Andric          __alloc_traits::propagate_on_container_move_assignment::value>());
13640b57cec5SDimitry Andric    return *this;
13650b57cec5SDimitry Andric}
13660b57cec5SDimitry Andric
13670b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
13680b57cec5SDimitry Andricvoid
13690b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
13700b57cec5SDimitry Andric    _NOEXCEPT_(__alloc_traits::is_always_equal::value)
13710b57cec5SDimitry Andric{
13720b57cec5SDimitry Andric    if (__base::__alloc() != __c.__alloc())
13730b57cec5SDimitry Andric    {
13740b57cec5SDimitry Andric        typedef move_iterator<iterator> _Ip;
13750b57cec5SDimitry Andric        assign(_Ip(__c.begin()), _Ip(__c.end()));
13760b57cec5SDimitry Andric    }
13770b57cec5SDimitry Andric    else
13780b57cec5SDimitry Andric        __move_assign(__c, true_type());
13790b57cec5SDimitry Andric}
13800b57cec5SDimitry Andric
13810b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
13820b57cec5SDimitry Andricvoid
13830b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
13840b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
13850b57cec5SDimitry Andric{
13860b57cec5SDimitry Andric    __vdeallocate();
13870b57cec5SDimitry Andric    __base::__move_assign_alloc(__c); // this can throw
13880b57cec5SDimitry Andric    this->__begin_ = __c.__begin_;
13890b57cec5SDimitry Andric    this->__end_ = __c.__end_;
13900b57cec5SDimitry Andric    this->__end_cap() = __c.__end_cap();
13910b57cec5SDimitry Andric    __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
1392e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
13930b57cec5SDimitry Andric    __get_db()->swap(this, &__c);
13940b57cec5SDimitry Andric#endif
13950b57cec5SDimitry Andric}
13960b57cec5SDimitry Andric
13970b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG
13980b57cec5SDimitry Andric
13990b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
14000b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
14010b57cec5SDimitry Andricvector<_Tp, _Allocator>&
14020b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator=(const vector& __x)
14030b57cec5SDimitry Andric{
14040b57cec5SDimitry Andric    if (this != &__x)
14050b57cec5SDimitry Andric    {
14060b57cec5SDimitry Andric        __base::__copy_assign_alloc(__x);
14070b57cec5SDimitry Andric        assign(__x.__begin_, __x.__end_);
14080b57cec5SDimitry Andric    }
14090b57cec5SDimitry Andric    return *this;
14100b57cec5SDimitry Andric}
14110b57cec5SDimitry Andric
14120b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
14130b57cec5SDimitry Andrictemplate <class _InputIterator>
14140b57cec5SDimitry Andrictypename enable_if
14150b57cec5SDimitry Andric<
1416480093f4SDimitry Andric     __is_cpp17_input_iterator  <_InputIterator>::value &&
1417480093f4SDimitry Andric    !__is_cpp17_forward_iterator<_InputIterator>::value &&
14180b57cec5SDimitry Andric    is_constructible<
14190b57cec5SDimitry Andric       _Tp,
14200b57cec5SDimitry Andric       typename iterator_traits<_InputIterator>::reference>::value,
14210b57cec5SDimitry Andric    void
14220b57cec5SDimitry Andric>::type
14230b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
14240b57cec5SDimitry Andric{
14250b57cec5SDimitry Andric    clear();
14260b57cec5SDimitry Andric    for (; __first != __last; ++__first)
14270b57cec5SDimitry Andric        __emplace_back(*__first);
14280b57cec5SDimitry Andric}
14290b57cec5SDimitry Andric
14300b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
14310b57cec5SDimitry Andrictemplate <class _ForwardIterator>
14320b57cec5SDimitry Andrictypename enable_if
14330b57cec5SDimitry Andric<
1434480093f4SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value &&
14350b57cec5SDimitry Andric    is_constructible<
14360b57cec5SDimitry Andric       _Tp,
14370b57cec5SDimitry Andric       typename iterator_traits<_ForwardIterator>::reference>::value,
14380b57cec5SDimitry Andric    void
14390b57cec5SDimitry Andric>::type
14400b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
14410b57cec5SDimitry Andric{
14420b57cec5SDimitry Andric    size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last));
14430b57cec5SDimitry Andric    if (__new_size <= capacity())
14440b57cec5SDimitry Andric    {
14450b57cec5SDimitry Andric        _ForwardIterator __mid = __last;
14460b57cec5SDimitry Andric        bool __growing = false;
14470b57cec5SDimitry Andric        if (__new_size > size())
14480b57cec5SDimitry Andric        {
14490b57cec5SDimitry Andric            __growing = true;
14500b57cec5SDimitry Andric            __mid =  __first;
14510b57cec5SDimitry Andric            _VSTD::advance(__mid, size());
14520b57cec5SDimitry Andric        }
14530b57cec5SDimitry Andric        pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
14540b57cec5SDimitry Andric        if (__growing)
14550b57cec5SDimitry Andric            __construct_at_end(__mid, __last, __new_size - size());
14560b57cec5SDimitry Andric        else
14570b57cec5SDimitry Andric            this->__destruct_at_end(__m);
14580b57cec5SDimitry Andric    }
14590b57cec5SDimitry Andric    else
14600b57cec5SDimitry Andric    {
14610b57cec5SDimitry Andric        __vdeallocate();
14620b57cec5SDimitry Andric        __vallocate(__recommend(__new_size));
14630b57cec5SDimitry Andric        __construct_at_end(__first, __last, __new_size);
14640b57cec5SDimitry Andric    }
14650b57cec5SDimitry Andric    __invalidate_all_iterators();
14660b57cec5SDimitry Andric}
14670b57cec5SDimitry Andric
14680b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
14690b57cec5SDimitry Andricvoid
14700b57cec5SDimitry Andricvector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
14710b57cec5SDimitry Andric{
14720b57cec5SDimitry Andric    if (__n <= capacity())
14730b57cec5SDimitry Andric    {
14740b57cec5SDimitry Andric        size_type __s = size();
14750b57cec5SDimitry Andric        _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
14760b57cec5SDimitry Andric        if (__n > __s)
14770b57cec5SDimitry Andric            __construct_at_end(__n - __s, __u);
14780b57cec5SDimitry Andric        else
14790b57cec5SDimitry Andric            this->__destruct_at_end(this->__begin_ + __n);
14800b57cec5SDimitry Andric    }
14810b57cec5SDimitry Andric    else
14820b57cec5SDimitry Andric    {
14830b57cec5SDimitry Andric        __vdeallocate();
14840b57cec5SDimitry Andric        __vallocate(__recommend(static_cast<size_type>(__n)));
14850b57cec5SDimitry Andric        __construct_at_end(__n, __u);
14860b57cec5SDimitry Andric    }
14870b57cec5SDimitry Andric    __invalidate_all_iterators();
14880b57cec5SDimitry Andric}
14890b57cec5SDimitry Andric
14900b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
14910b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
14920b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
14930b57cec5SDimitry Andricvector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
14940b57cec5SDimitry Andric{
1495e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
14960b57cec5SDimitry Andric    return iterator(this, __p);
14970b57cec5SDimitry Andric#else
14980b57cec5SDimitry Andric    return iterator(__p);
14990b57cec5SDimitry Andric#endif
15000b57cec5SDimitry Andric}
15010b57cec5SDimitry Andric
15020b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
15030b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
15040b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_iterator
15050b57cec5SDimitry Andricvector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
15060b57cec5SDimitry Andric{
1507e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
15080b57cec5SDimitry Andric    return const_iterator(this, __p);
15090b57cec5SDimitry Andric#else
15100b57cec5SDimitry Andric    return const_iterator(__p);
15110b57cec5SDimitry Andric#endif
15120b57cec5SDimitry Andric}
15130b57cec5SDimitry Andric
15140b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
15150b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
15160b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
15170b57cec5SDimitry Andricvector<_Tp, _Allocator>::begin() _NOEXCEPT
15180b57cec5SDimitry Andric{
15190b57cec5SDimitry Andric    return __make_iter(this->__begin_);
15200b57cec5SDimitry Andric}
15210b57cec5SDimitry Andric
15220b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
15230b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
15240b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_iterator
15250b57cec5SDimitry Andricvector<_Tp, _Allocator>::begin() const _NOEXCEPT
15260b57cec5SDimitry Andric{
15270b57cec5SDimitry Andric    return __make_iter(this->__begin_);
15280b57cec5SDimitry Andric}
15290b57cec5SDimitry Andric
15300b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
15310b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
15320b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
15330b57cec5SDimitry Andricvector<_Tp, _Allocator>::end() _NOEXCEPT
15340b57cec5SDimitry Andric{
15350b57cec5SDimitry Andric    return __make_iter(this->__end_);
15360b57cec5SDimitry Andric}
15370b57cec5SDimitry Andric
15380b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
15390b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
15400b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_iterator
15410b57cec5SDimitry Andricvector<_Tp, _Allocator>::end() const _NOEXCEPT
15420b57cec5SDimitry Andric{
15430b57cec5SDimitry Andric    return __make_iter(this->__end_);
15440b57cec5SDimitry Andric}
15450b57cec5SDimitry Andric
15460b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
15470b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
15480b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference
15490b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT
15500b57cec5SDimitry Andric{
15510b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
15520b57cec5SDimitry Andric    return this->__begin_[__n];
15530b57cec5SDimitry Andric}
15540b57cec5SDimitry Andric
15550b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
15560b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
15570b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_reference
15580b57cec5SDimitry Andricvector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT
15590b57cec5SDimitry Andric{
15600b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
15610b57cec5SDimitry Andric    return this->__begin_[__n];
15620b57cec5SDimitry Andric}
15630b57cec5SDimitry Andric
15640b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
15650b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference
15660b57cec5SDimitry Andricvector<_Tp, _Allocator>::at(size_type __n)
15670b57cec5SDimitry Andric{
15680b57cec5SDimitry Andric    if (__n >= size())
15690b57cec5SDimitry Andric        this->__throw_out_of_range();
15700b57cec5SDimitry Andric    return this->__begin_[__n];
15710b57cec5SDimitry Andric}
15720b57cec5SDimitry Andric
15730b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
15740b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::const_reference
15750b57cec5SDimitry Andricvector<_Tp, _Allocator>::at(size_type __n) const
15760b57cec5SDimitry Andric{
15770b57cec5SDimitry Andric    if (__n >= size())
15780b57cec5SDimitry Andric        this->__throw_out_of_range();
15790b57cec5SDimitry Andric    return this->__begin_[__n];
15800b57cec5SDimitry Andric}
15810b57cec5SDimitry Andric
15820b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
15830b57cec5SDimitry Andricvoid
15840b57cec5SDimitry Andricvector<_Tp, _Allocator>::reserve(size_type __n)
15850b57cec5SDimitry Andric{
15860b57cec5SDimitry Andric    if (__n > capacity())
15870b57cec5SDimitry Andric    {
15880b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
15890b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
15900b57cec5SDimitry Andric        __swap_out_circular_buffer(__v);
15910b57cec5SDimitry Andric    }
15920b57cec5SDimitry Andric}
15930b57cec5SDimitry Andric
15940b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
15950b57cec5SDimitry Andricvoid
15960b57cec5SDimitry Andricvector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
15970b57cec5SDimitry Andric{
15980b57cec5SDimitry Andric    if (capacity() > size())
15990b57cec5SDimitry Andric    {
16000b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
16010b57cec5SDimitry Andric        try
16020b57cec5SDimitry Andric        {
16030b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
16040b57cec5SDimitry Andric            allocator_type& __a = this->__alloc();
16050b57cec5SDimitry Andric            __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
16060b57cec5SDimitry Andric            __swap_out_circular_buffer(__v);
16070b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
16080b57cec5SDimitry Andric        }
16090b57cec5SDimitry Andric        catch (...)
16100b57cec5SDimitry Andric        {
16110b57cec5SDimitry Andric        }
16120b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
16130b57cec5SDimitry Andric    }
16140b57cec5SDimitry Andric}
16150b57cec5SDimitry Andric
16160b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
16170b57cec5SDimitry Andrictemplate <class _Up>
16180b57cec5SDimitry Andricvoid
16190b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
16200b57cec5SDimitry Andricvector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
16210b57cec5SDimitry Andric#else
16220b57cec5SDimitry Andricvector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x)
16230b57cec5SDimitry Andric#endif
16240b57cec5SDimitry Andric{
16250b57cec5SDimitry Andric    allocator_type& __a = this->__alloc();
16260b57cec5SDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
16270b57cec5SDimitry Andric    // __v.push_back(_VSTD::forward<_Up>(__x));
1628480093f4SDimitry Andric    __alloc_traits::construct(__a, _VSTD::__to_address(__v.__end_), _VSTD::forward<_Up>(__x));
16290b57cec5SDimitry Andric    __v.__end_++;
16300b57cec5SDimitry Andric    __swap_out_circular_buffer(__v);
16310b57cec5SDimitry Andric}
16320b57cec5SDimitry Andric
16330b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
16340b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
16350b57cec5SDimitry Andricvoid
16360b57cec5SDimitry Andricvector<_Tp, _Allocator>::push_back(const_reference __x)
16370b57cec5SDimitry Andric{
16380b57cec5SDimitry Andric    if (this->__end_ != this->__end_cap())
16390b57cec5SDimitry Andric    {
1640e40139ffSDimitry Andric        __construct_one_at_end(__x);
16410b57cec5SDimitry Andric    }
16420b57cec5SDimitry Andric    else
16430b57cec5SDimitry Andric        __push_back_slow_path(__x);
16440b57cec5SDimitry Andric}
16450b57cec5SDimitry Andric
16460b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
16470b57cec5SDimitry Andric
16480b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
16490b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
16500b57cec5SDimitry Andricvoid
16510b57cec5SDimitry Andricvector<_Tp, _Allocator>::push_back(value_type&& __x)
16520b57cec5SDimitry Andric{
16530b57cec5SDimitry Andric    if (this->__end_ < this->__end_cap())
16540b57cec5SDimitry Andric    {
1655e40139ffSDimitry Andric        __construct_one_at_end(_VSTD::move(__x));
16560b57cec5SDimitry Andric    }
16570b57cec5SDimitry Andric    else
16580b57cec5SDimitry Andric        __push_back_slow_path(_VSTD::move(__x));
16590b57cec5SDimitry Andric}
16600b57cec5SDimitry Andric
16610b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
16620b57cec5SDimitry Andrictemplate <class... _Args>
16630b57cec5SDimitry Andricvoid
16640b57cec5SDimitry Andricvector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
16650b57cec5SDimitry Andric{
16660b57cec5SDimitry Andric    allocator_type& __a = this->__alloc();
16670b57cec5SDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
16680b57cec5SDimitry Andric//    __v.emplace_back(_VSTD::forward<_Args>(__args)...);
1669480093f4SDimitry Andric    __alloc_traits::construct(__a, _VSTD::__to_address(__v.__end_), _VSTD::forward<_Args>(__args)...);
16700b57cec5SDimitry Andric    __v.__end_++;
16710b57cec5SDimitry Andric    __swap_out_circular_buffer(__v);
16720b57cec5SDimitry Andric}
16730b57cec5SDimitry Andric
16740b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
16750b57cec5SDimitry Andrictemplate <class... _Args>
16760b57cec5SDimitry Andricinline
16770b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
16780b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::reference
16790b57cec5SDimitry Andric#else
16800b57cec5SDimitry Andricvoid
16810b57cec5SDimitry Andric#endif
16820b57cec5SDimitry Andricvector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
16830b57cec5SDimitry Andric{
16840b57cec5SDimitry Andric    if (this->__end_ < this->__end_cap())
16850b57cec5SDimitry Andric    {
1686e40139ffSDimitry Andric        __construct_one_at_end(_VSTD::forward<_Args>(__args)...);
16870b57cec5SDimitry Andric    }
16880b57cec5SDimitry Andric    else
16890b57cec5SDimitry Andric        __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...);
16900b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
16910b57cec5SDimitry Andric    return this->back();
16920b57cec5SDimitry Andric#endif
16930b57cec5SDimitry Andric}
16940b57cec5SDimitry Andric
16950b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG
16960b57cec5SDimitry Andric
16970b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
16980b57cec5SDimitry Andricinline
16990b57cec5SDimitry Andricvoid
17000b57cec5SDimitry Andricvector<_Tp, _Allocator>::pop_back()
17010b57cec5SDimitry Andric{
1702*fe6060f1SDimitry Andric    _LIBCPP_ASSERT(!empty(), "vector::pop_back called on an empty vector");
17030b57cec5SDimitry Andric    this->__destruct_at_end(this->__end_ - 1);
17040b57cec5SDimitry Andric}
17050b57cec5SDimitry Andric
17060b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
17070b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
17080b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
17090b57cec5SDimitry Andricvector<_Tp, _Allocator>::erase(const_iterator __position)
17100b57cec5SDimitry Andric{
1711e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
17120b57cec5SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
17130b57cec5SDimitry Andric        "vector::erase(iterator) called with an iterator not"
17140b57cec5SDimitry Andric        " referring to this vector");
17150b57cec5SDimitry Andric#endif
17160b57cec5SDimitry Andric    _LIBCPP_ASSERT(__position != end(),
17170b57cec5SDimitry Andric        "vector::erase(iterator) called with a non-dereferenceable iterator");
17180b57cec5SDimitry Andric    difference_type __ps = __position - cbegin();
17190b57cec5SDimitry Andric    pointer __p = this->__begin_ + __ps;
17200b57cec5SDimitry Andric    this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
17210b57cec5SDimitry Andric    this->__invalidate_iterators_past(__p-1);
17220b57cec5SDimitry Andric    iterator __r = __make_iter(__p);
17230b57cec5SDimitry Andric    return __r;
17240b57cec5SDimitry Andric}
17250b57cec5SDimitry Andric
17260b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
17270b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
17280b57cec5SDimitry Andricvector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
17290b57cec5SDimitry Andric{
1730e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
17310b57cec5SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
17320b57cec5SDimitry Andric        "vector::erase(iterator,  iterator) called with an iterator not"
17330b57cec5SDimitry Andric        " referring to this vector");
17340b57cec5SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this,
17350b57cec5SDimitry Andric        "vector::erase(iterator,  iterator) called with an iterator not"
17360b57cec5SDimitry Andric        " referring to this vector");
17370b57cec5SDimitry Andric#endif
17380b57cec5SDimitry Andric    _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
17390b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__first - begin());
17400b57cec5SDimitry Andric    if (__first != __last) {
17410b57cec5SDimitry Andric        this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
17420b57cec5SDimitry Andric        this->__invalidate_iterators_past(__p - 1);
17430b57cec5SDimitry Andric    }
17440b57cec5SDimitry Andric    iterator __r = __make_iter(__p);
17450b57cec5SDimitry Andric    return __r;
17460b57cec5SDimitry Andric}
17470b57cec5SDimitry Andric
17480b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
17490b57cec5SDimitry Andricvoid
17500b57cec5SDimitry Andricvector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
17510b57cec5SDimitry Andric{
17520b57cec5SDimitry Andric    pointer __old_last = this->__end_;
17530b57cec5SDimitry Andric    difference_type __n = __old_last - __to;
1754e40139ffSDimitry Andric    {
1755e40139ffSDimitry Andric      pointer __i = __from_s + __n;
1756e40139ffSDimitry Andric      _ConstructTransaction __tx(*this, __from_e - __i);
17575ffd83dbSDimitry Andric      for (pointer __pos = __tx.__pos_; __i < __from_e;
17585ffd83dbSDimitry Andric           ++__i, ++__pos, __tx.__pos_ = __pos) {
17590b57cec5SDimitry Andric          __alloc_traits::construct(this->__alloc(),
17605ffd83dbSDimitry Andric                                    _VSTD::__to_address(__pos),
17610b57cec5SDimitry Andric                                    _VSTD::move(*__i));
1762e40139ffSDimitry Andric      }
1763e40139ffSDimitry Andric    }
17640b57cec5SDimitry Andric    _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
17650b57cec5SDimitry Andric}
17660b57cec5SDimitry Andric
17670b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
17680b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
17690b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
17700b57cec5SDimitry Andric{
1771e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
17720b57cec5SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
17730b57cec5SDimitry Andric        "vector::insert(iterator, x) called with an iterator not"
17740b57cec5SDimitry Andric        " referring to this vector");
17750b57cec5SDimitry Andric#endif
17760b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__position - begin());
17770b57cec5SDimitry Andric    if (this->__end_ < this->__end_cap())
17780b57cec5SDimitry Andric    {
17790b57cec5SDimitry Andric        if (__p == this->__end_)
17800b57cec5SDimitry Andric        {
1781e40139ffSDimitry Andric            __construct_one_at_end(__x);
17820b57cec5SDimitry Andric        }
17830b57cec5SDimitry Andric        else
17840b57cec5SDimitry Andric        {
17850b57cec5SDimitry Andric            __move_range(__p, this->__end_, __p + 1);
17860b57cec5SDimitry Andric            const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
17870b57cec5SDimitry Andric            if (__p <= __xr && __xr < this->__end_)
17880b57cec5SDimitry Andric                ++__xr;
17890b57cec5SDimitry Andric            *__p = *__xr;
17900b57cec5SDimitry Andric        }
17910b57cec5SDimitry Andric    }
17920b57cec5SDimitry Andric    else
17930b57cec5SDimitry Andric    {
17940b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
17950b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
17960b57cec5SDimitry Andric        __v.push_back(__x);
17970b57cec5SDimitry Andric        __p = __swap_out_circular_buffer(__v, __p);
17980b57cec5SDimitry Andric    }
17990b57cec5SDimitry Andric    return __make_iter(__p);
18000b57cec5SDimitry Andric}
18010b57cec5SDimitry Andric
18020b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
18030b57cec5SDimitry Andric
18040b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
18050b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
18060b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
18070b57cec5SDimitry Andric{
1808e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
18090b57cec5SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
18100b57cec5SDimitry Andric        "vector::insert(iterator, x) called with an iterator not"
18110b57cec5SDimitry Andric        " referring to this vector");
18120b57cec5SDimitry Andric#endif
18130b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__position - begin());
18140b57cec5SDimitry Andric    if (this->__end_ < this->__end_cap())
18150b57cec5SDimitry Andric    {
18160b57cec5SDimitry Andric        if (__p == this->__end_)
18170b57cec5SDimitry Andric        {
1818e40139ffSDimitry Andric            __construct_one_at_end(_VSTD::move(__x));
18190b57cec5SDimitry Andric        }
18200b57cec5SDimitry Andric        else
18210b57cec5SDimitry Andric        {
18220b57cec5SDimitry Andric            __move_range(__p, this->__end_, __p + 1);
18230b57cec5SDimitry Andric            *__p = _VSTD::move(__x);
18240b57cec5SDimitry Andric        }
18250b57cec5SDimitry Andric    }
18260b57cec5SDimitry Andric    else
18270b57cec5SDimitry Andric    {
18280b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
18290b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
18300b57cec5SDimitry Andric        __v.push_back(_VSTD::move(__x));
18310b57cec5SDimitry Andric        __p = __swap_out_circular_buffer(__v, __p);
18320b57cec5SDimitry Andric    }
18330b57cec5SDimitry Andric    return __make_iter(__p);
18340b57cec5SDimitry Andric}
18350b57cec5SDimitry Andric
18360b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
18370b57cec5SDimitry Andrictemplate <class... _Args>
18380b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
18390b57cec5SDimitry Andricvector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
18400b57cec5SDimitry Andric{
1841e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
18420b57cec5SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
18430b57cec5SDimitry Andric        "vector::emplace(iterator, x) called with an iterator not"
18440b57cec5SDimitry Andric        " referring to this vector");
18450b57cec5SDimitry Andric#endif
18460b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__position - begin());
18470b57cec5SDimitry Andric    if (this->__end_ < this->__end_cap())
18480b57cec5SDimitry Andric    {
18490b57cec5SDimitry Andric        if (__p == this->__end_)
18500b57cec5SDimitry Andric        {
1851e40139ffSDimitry Andric            __construct_one_at_end(_VSTD::forward<_Args>(__args)...);
18520b57cec5SDimitry Andric        }
18530b57cec5SDimitry Andric        else
18540b57cec5SDimitry Andric        {
18550b57cec5SDimitry Andric            __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...);
18560b57cec5SDimitry Andric            __move_range(__p, this->__end_, __p + 1);
18570b57cec5SDimitry Andric            *__p = _VSTD::move(__tmp.get());
18580b57cec5SDimitry Andric        }
18590b57cec5SDimitry Andric    }
18600b57cec5SDimitry Andric    else
18610b57cec5SDimitry Andric    {
18620b57cec5SDimitry Andric        allocator_type& __a = this->__alloc();
18630b57cec5SDimitry Andric        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
18640b57cec5SDimitry Andric        __v.emplace_back(_VSTD::forward<_Args>(__args)...);
18650b57cec5SDimitry Andric        __p = __swap_out_circular_buffer(__v, __p);
18660b57cec5SDimitry Andric    }
18670b57cec5SDimitry Andric    return __make_iter(__p);
18680b57cec5SDimitry Andric}
18690b57cec5SDimitry Andric
18700b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG
18710b57cec5SDimitry Andric
18720b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
18730b57cec5SDimitry Andrictypename vector<_Tp, _Allocator>::iterator
18740b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
18750b57cec5SDimitry Andric{
1876e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
18770b57cec5SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
18780b57cec5SDimitry Andric        "vector::insert(iterator, n, x) called with an iterator not"
18790b57cec5SDimitry Andric        " referring to this vector");
18800b57cec5SDimitry Andric#endif
18810b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__position - begin());
18820b57cec5SDimitry Andric    if (__n > 0)
18830b57cec5SDimitry Andric    {
18840b57cec5SDimitry Andric        if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
18850b57cec5SDimitry Andric        {
18860b57cec5SDimitry Andric            size_type __old_n = __n;
18870b57cec5SDimitry Andric            pointer __old_last = this->__end_;
18880b57cec5SDimitry Andric            if (__n > static_cast<size_type>(this->__end_ - __p))
18890b57cec5SDimitry Andric            {
18900b57cec5SDimitry Andric                size_type __cx = __n - (this->__end_ - __p);
18910b57cec5SDimitry Andric                __construct_at_end(__cx, __x);
18920b57cec5SDimitry Andric                __n -= __cx;
18930b57cec5SDimitry Andric            }
18940b57cec5SDimitry Andric            if (__n > 0)
18950b57cec5SDimitry Andric            {
18960b57cec5SDimitry Andric                __move_range(__p, __old_last, __p + __old_n);
18970b57cec5SDimitry Andric                const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
18980b57cec5SDimitry Andric                if (__p <= __xr && __xr < this->__end_)
18990b57cec5SDimitry Andric                    __xr += __old_n;
19000b57cec5SDimitry Andric                _VSTD::fill_n(__p, __n, *__xr);
19010b57cec5SDimitry Andric            }
19020b57cec5SDimitry Andric        }
19030b57cec5SDimitry Andric        else
19040b57cec5SDimitry Andric        {
19050b57cec5SDimitry Andric            allocator_type& __a = this->__alloc();
19060b57cec5SDimitry Andric            __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
19070b57cec5SDimitry Andric            __v.__construct_at_end(__n, __x);
19080b57cec5SDimitry Andric            __p = __swap_out_circular_buffer(__v, __p);
19090b57cec5SDimitry Andric        }
19100b57cec5SDimitry Andric    }
19110b57cec5SDimitry Andric    return __make_iter(__p);
19120b57cec5SDimitry Andric}
19130b57cec5SDimitry Andric
19140b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
19150b57cec5SDimitry Andrictemplate <class _InputIterator>
19160b57cec5SDimitry Andrictypename enable_if
19170b57cec5SDimitry Andric<
1918480093f4SDimitry Andric     __is_cpp17_input_iterator  <_InputIterator>::value &&
1919480093f4SDimitry Andric    !__is_cpp17_forward_iterator<_InputIterator>::value &&
19200b57cec5SDimitry Andric    is_constructible<
19210b57cec5SDimitry Andric       _Tp,
19220b57cec5SDimitry Andric       typename iterator_traits<_InputIterator>::reference>::value,
19230b57cec5SDimitry Andric    typename vector<_Tp, _Allocator>::iterator
19240b57cec5SDimitry Andric>::type
19250b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
19260b57cec5SDimitry Andric{
1927e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
19280b57cec5SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
19290b57cec5SDimitry Andric        "vector::insert(iterator, range) called with an iterator not"
19300b57cec5SDimitry Andric        " referring to this vector");
19310b57cec5SDimitry Andric#endif
19320b57cec5SDimitry Andric    difference_type __off = __position - begin();
19330b57cec5SDimitry Andric    pointer __p = this->__begin_ + __off;
19340b57cec5SDimitry Andric    allocator_type& __a = this->__alloc();
19350b57cec5SDimitry Andric    pointer __old_last = this->__end_;
19360b57cec5SDimitry Andric    for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
19370b57cec5SDimitry Andric    {
1938e40139ffSDimitry Andric        __construct_one_at_end(*__first);
19390b57cec5SDimitry Andric    }
19400b57cec5SDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__a);
19410b57cec5SDimitry Andric    if (__first != __last)
19420b57cec5SDimitry Andric    {
19430b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
19440b57cec5SDimitry Andric        try
19450b57cec5SDimitry Andric        {
19460b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
19470b57cec5SDimitry Andric            __v.__construct_at_end(__first, __last);
19480b57cec5SDimitry Andric            difference_type __old_size = __old_last - this->__begin_;
19490b57cec5SDimitry Andric            difference_type __old_p = __p - this->__begin_;
19500b57cec5SDimitry Andric            reserve(__recommend(size() + __v.size()));
19510b57cec5SDimitry Andric            __p = this->__begin_ + __old_p;
19520b57cec5SDimitry Andric            __old_last = this->__begin_ + __old_size;
19530b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
19540b57cec5SDimitry Andric        }
19550b57cec5SDimitry Andric        catch (...)
19560b57cec5SDimitry Andric        {
19570b57cec5SDimitry Andric            erase(__make_iter(__old_last), end());
19580b57cec5SDimitry Andric            throw;
19590b57cec5SDimitry Andric        }
19600b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
19610b57cec5SDimitry Andric    }
19620b57cec5SDimitry Andric    __p = _VSTD::rotate(__p, __old_last, this->__end_);
19635ffd83dbSDimitry Andric    insert(__make_iter(__p), _VSTD::make_move_iterator(__v.begin()),
19645ffd83dbSDimitry Andric                             _VSTD::make_move_iterator(__v.end()));
19650b57cec5SDimitry Andric    return begin() + __off;
19660b57cec5SDimitry Andric}
19670b57cec5SDimitry Andric
19680b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
19690b57cec5SDimitry Andrictemplate <class _ForwardIterator>
19700b57cec5SDimitry Andrictypename enable_if
19710b57cec5SDimitry Andric<
1972480093f4SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value &&
19730b57cec5SDimitry Andric    is_constructible<
19740b57cec5SDimitry Andric       _Tp,
19750b57cec5SDimitry Andric       typename iterator_traits<_ForwardIterator>::reference>::value,
19760b57cec5SDimitry Andric    typename vector<_Tp, _Allocator>::iterator
19770b57cec5SDimitry Andric>::type
19780b57cec5SDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
19790b57cec5SDimitry Andric{
1980e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
19810b57cec5SDimitry Andric    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
19820b57cec5SDimitry Andric        "vector::insert(iterator, range) called with an iterator not"
19830b57cec5SDimitry Andric        " referring to this vector");
19840b57cec5SDimitry Andric#endif
19850b57cec5SDimitry Andric    pointer __p = this->__begin_ + (__position - begin());
19860b57cec5SDimitry Andric    difference_type __n = _VSTD::distance(__first, __last);
19870b57cec5SDimitry Andric    if (__n > 0)
19880b57cec5SDimitry Andric    {
19890b57cec5SDimitry Andric        if (__n <= this->__end_cap() - this->__end_)
19900b57cec5SDimitry Andric        {
19910b57cec5SDimitry Andric            size_type __old_n = __n;
19920b57cec5SDimitry Andric            pointer __old_last = this->__end_;
19930b57cec5SDimitry Andric            _ForwardIterator __m = __last;
19940b57cec5SDimitry Andric            difference_type __dx = this->__end_ - __p;
19950b57cec5SDimitry Andric            if (__n > __dx)
19960b57cec5SDimitry Andric            {
19970b57cec5SDimitry Andric                __m = __first;
19980b57cec5SDimitry Andric                difference_type __diff = this->__end_ - __p;
19990b57cec5SDimitry Andric                _VSTD::advance(__m, __diff);
20000b57cec5SDimitry Andric                __construct_at_end(__m, __last, __n - __diff);
20010b57cec5SDimitry Andric                __n = __dx;
20020b57cec5SDimitry Andric            }
20030b57cec5SDimitry Andric            if (__n > 0)
20040b57cec5SDimitry Andric            {
20050b57cec5SDimitry Andric                __move_range(__p, __old_last, __p + __old_n);
20060b57cec5SDimitry Andric                _VSTD::copy(__first, __m, __p);
20070b57cec5SDimitry Andric            }
20080b57cec5SDimitry Andric        }
20090b57cec5SDimitry Andric        else
20100b57cec5SDimitry Andric        {
20110b57cec5SDimitry Andric            allocator_type& __a = this->__alloc();
20120b57cec5SDimitry Andric            __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
20130b57cec5SDimitry Andric            __v.__construct_at_end(__first, __last);
20140b57cec5SDimitry Andric            __p = __swap_out_circular_buffer(__v, __p);
20150b57cec5SDimitry Andric        }
20160b57cec5SDimitry Andric    }
20170b57cec5SDimitry Andric    return __make_iter(__p);
20180b57cec5SDimitry Andric}
20190b57cec5SDimitry Andric
20200b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
20210b57cec5SDimitry Andricvoid
20220b57cec5SDimitry Andricvector<_Tp, _Allocator>::resize(size_type __sz)
20230b57cec5SDimitry Andric{
20240b57cec5SDimitry Andric    size_type __cs = size();
20250b57cec5SDimitry Andric    if (__cs < __sz)
20260b57cec5SDimitry Andric        this->__append(__sz - __cs);
20270b57cec5SDimitry Andric    else if (__cs > __sz)
20280b57cec5SDimitry Andric        this->__destruct_at_end(this->__begin_ + __sz);
20290b57cec5SDimitry Andric}
20300b57cec5SDimitry Andric
20310b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
20320b57cec5SDimitry Andricvoid
20330b57cec5SDimitry Andricvector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
20340b57cec5SDimitry Andric{
20350b57cec5SDimitry Andric    size_type __cs = size();
20360b57cec5SDimitry Andric    if (__cs < __sz)
20370b57cec5SDimitry Andric        this->__append(__sz - __cs, __x);
20380b57cec5SDimitry Andric    else if (__cs > __sz)
20390b57cec5SDimitry Andric        this->__destruct_at_end(this->__begin_ + __sz);
20400b57cec5SDimitry Andric}
20410b57cec5SDimitry Andric
20420b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
20430b57cec5SDimitry Andricvoid
20440b57cec5SDimitry Andricvector<_Tp, _Allocator>::swap(vector& __x)
20450b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
20460b57cec5SDimitry Andric    _NOEXCEPT
20470b57cec5SDimitry Andric#else
20480b57cec5SDimitry Andric    _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
20490b57cec5SDimitry Andric                __is_nothrow_swappable<allocator_type>::value)
20500b57cec5SDimitry Andric#endif
20510b57cec5SDimitry Andric{
20520b57cec5SDimitry Andric    _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
20530b57cec5SDimitry Andric                   this->__alloc() == __x.__alloc(),
20540b57cec5SDimitry Andric                   "vector::swap: Either propagate_on_container_swap must be true"
20550b57cec5SDimitry Andric                   " or the allocators must compare equal");
20560b57cec5SDimitry Andric    _VSTD::swap(this->__begin_, __x.__begin_);
20570b57cec5SDimitry Andric    _VSTD::swap(this->__end_, __x.__end_);
20580b57cec5SDimitry Andric    _VSTD::swap(this->__end_cap(), __x.__end_cap());
2059e8d8bef9SDimitry Andric    _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(),
20600b57cec5SDimitry Andric        integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>());
2061e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
20620b57cec5SDimitry Andric    __get_db()->swap(this, &__x);
2063e8d8bef9SDimitry Andric#endif
20640b57cec5SDimitry Andric}
20650b57cec5SDimitry Andric
20660b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
20670b57cec5SDimitry Andricbool
20680b57cec5SDimitry Andricvector<_Tp, _Allocator>::__invariants() const
20690b57cec5SDimitry Andric{
20700b57cec5SDimitry Andric    if (this->__begin_ == nullptr)
20710b57cec5SDimitry Andric    {
20720b57cec5SDimitry Andric        if (this->__end_ != nullptr || this->__end_cap() != nullptr)
20730b57cec5SDimitry Andric            return false;
20740b57cec5SDimitry Andric    }
20750b57cec5SDimitry Andric    else
20760b57cec5SDimitry Andric    {
20770b57cec5SDimitry Andric        if (this->__begin_ > this->__end_)
20780b57cec5SDimitry Andric            return false;
20790b57cec5SDimitry Andric        if (this->__begin_ == this->__end_cap())
20800b57cec5SDimitry Andric            return false;
20810b57cec5SDimitry Andric        if (this->__end_ > this->__end_cap())
20820b57cec5SDimitry Andric            return false;
20830b57cec5SDimitry Andric    }
20840b57cec5SDimitry Andric    return true;
20850b57cec5SDimitry Andric}
20860b57cec5SDimitry Andric
2087e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
20880b57cec5SDimitry Andric
20890b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
20900b57cec5SDimitry Andricbool
20910b57cec5SDimitry Andricvector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
20920b57cec5SDimitry Andric{
20930b57cec5SDimitry Andric    return this->__begin_ <= __i->base() && __i->base() < this->__end_;
20940b57cec5SDimitry Andric}
20950b57cec5SDimitry Andric
20960b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
20970b57cec5SDimitry Andricbool
20980b57cec5SDimitry Andricvector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
20990b57cec5SDimitry Andric{
21000b57cec5SDimitry Andric    return this->__begin_ < __i->base() && __i->base() <= this->__end_;
21010b57cec5SDimitry Andric}
21020b57cec5SDimitry Andric
21030b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
21040b57cec5SDimitry Andricbool
21050b57cec5SDimitry Andricvector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
21060b57cec5SDimitry Andric{
21070b57cec5SDimitry Andric    const_pointer __p = __i->base() + __n;
21080b57cec5SDimitry Andric    return this->__begin_ <= __p && __p <= this->__end_;
21090b57cec5SDimitry Andric}
21100b57cec5SDimitry Andric
21110b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
21120b57cec5SDimitry Andricbool
21130b57cec5SDimitry Andricvector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
21140b57cec5SDimitry Andric{
21150b57cec5SDimitry Andric    const_pointer __p = __i->base() + __n;
21160b57cec5SDimitry Andric    return this->__begin_ <= __p && __p < this->__end_;
21170b57cec5SDimitry Andric}
21180b57cec5SDimitry Andric
2119e8d8bef9SDimitry Andric#endif // _LIBCPP_DEBUG_LEVEL == 2
21200b57cec5SDimitry Andric
21210b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
21220b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
21230b57cec5SDimitry Andricvoid
21240b57cec5SDimitry Andricvector<_Tp, _Allocator>::__invalidate_all_iterators()
21250b57cec5SDimitry Andric{
2126e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
21270b57cec5SDimitry Andric    __get_db()->__invalidate_all(this);
2128e8d8bef9SDimitry Andric#endif
21290b57cec5SDimitry Andric}
21300b57cec5SDimitry Andric
21310b57cec5SDimitry Andric
21320b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
21330b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
21340b57cec5SDimitry Andricvoid
21350b57cec5SDimitry Andricvector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) {
2136e8d8bef9SDimitry Andric#if _LIBCPP_DEBUG_LEVEL == 2
21370b57cec5SDimitry Andric  __c_node* __c = __get_db()->__find_c_and_lock(this);
21380b57cec5SDimitry Andric  for (__i_node** __p = __c->end_; __p != __c->beg_; ) {
21390b57cec5SDimitry Andric    --__p;
21400b57cec5SDimitry Andric    const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
21410b57cec5SDimitry Andric    if (__i->base() > __new_last) {
21420b57cec5SDimitry Andric      (*__p)->__c_ = nullptr;
21430b57cec5SDimitry Andric      if (--__c->end_ != __p)
2144e8d8bef9SDimitry Andric        _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
21450b57cec5SDimitry Andric    }
21460b57cec5SDimitry Andric  }
21470b57cec5SDimitry Andric  __get_db()->unlock();
21480b57cec5SDimitry Andric#else
21490b57cec5SDimitry Andric  ((void)__new_last);
21500b57cec5SDimitry Andric#endif
21510b57cec5SDimitry Andric}
21520b57cec5SDimitry Andric
21530b57cec5SDimitry Andric// vector<bool>
21540b57cec5SDimitry Andric
21550b57cec5SDimitry Andrictemplate <class _Allocator> class vector<bool, _Allocator>;
21560b57cec5SDimitry Andric
21570b57cec5SDimitry Andrictemplate <class _Allocator> struct hash<vector<bool, _Allocator> >;
21580b57cec5SDimitry Andric
21590b57cec5SDimitry Andrictemplate <class _Allocator>
21600b57cec5SDimitry Andricstruct __has_storage_type<vector<bool, _Allocator> >
21610b57cec5SDimitry Andric{
21620b57cec5SDimitry Andric    static const bool value = true;
21630b57cec5SDimitry Andric};
21640b57cec5SDimitry Andric
21650b57cec5SDimitry Andrictemplate <class _Allocator>
21660b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator>
21670b57cec5SDimitry Andric    : private __vector_base_common<true>
21680b57cec5SDimitry Andric{
21690b57cec5SDimitry Andricpublic:
21700b57cec5SDimitry Andric    typedef vector                                   __self;
21710b57cec5SDimitry Andric    typedef bool                                     value_type;
21720b57cec5SDimitry Andric    typedef _Allocator                               allocator_type;
21730b57cec5SDimitry Andric    typedef allocator_traits<allocator_type>         __alloc_traits;
21740b57cec5SDimitry Andric    typedef typename __alloc_traits::size_type       size_type;
21750b57cec5SDimitry Andric    typedef typename __alloc_traits::difference_type difference_type;
21760b57cec5SDimitry Andric    typedef size_type __storage_type;
21770b57cec5SDimitry Andric    typedef __bit_iterator<vector, false>            pointer;
21780b57cec5SDimitry Andric    typedef __bit_iterator<vector, true>             const_pointer;
21790b57cec5SDimitry Andric    typedef pointer                                  iterator;
21800b57cec5SDimitry Andric    typedef const_pointer                            const_iterator;
21810b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<iterator>         reverse_iterator;
21820b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<const_iterator>   const_reverse_iterator;
21830b57cec5SDimitry Andric
21840b57cec5SDimitry Andricprivate:
21850b57cec5SDimitry Andric    typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator;
21860b57cec5SDimitry Andric    typedef allocator_traits<__storage_allocator>    __storage_traits;
21870b57cec5SDimitry Andric    typedef typename __storage_traits::pointer       __storage_pointer;
21880b57cec5SDimitry Andric    typedef typename __storage_traits::const_pointer __const_storage_pointer;
21890b57cec5SDimitry Andric
21900b57cec5SDimitry Andric    __storage_pointer                                      __begin_;
21910b57cec5SDimitry Andric    size_type                                              __size_;
21920b57cec5SDimitry Andric    __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
21930b57cec5SDimitry Andricpublic:
21940b57cec5SDimitry Andric    typedef __bit_reference<vector>                  reference;
21950b57cec5SDimitry Andric    typedef __bit_const_reference<vector>            const_reference;
21960b57cec5SDimitry Andricprivate:
21970b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
21980b57cec5SDimitry Andric    size_type& __cap() _NOEXCEPT
21990b57cec5SDimitry Andric        {return __cap_alloc_.first();}
22000b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
22010b57cec5SDimitry Andric    const size_type& __cap() const _NOEXCEPT
22020b57cec5SDimitry Andric        {return __cap_alloc_.first();}
22030b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
22040b57cec5SDimitry Andric    __storage_allocator& __alloc() _NOEXCEPT
22050b57cec5SDimitry Andric        {return __cap_alloc_.second();}
22060b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
22070b57cec5SDimitry Andric    const __storage_allocator& __alloc() const _NOEXCEPT
22080b57cec5SDimitry Andric        {return __cap_alloc_.second();}
22090b57cec5SDimitry Andric
22100b57cec5SDimitry Andric    static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
22110b57cec5SDimitry Andric
22120b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
22130b57cec5SDimitry Andric    static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
22140b57cec5SDimitry Andric        {return __n * __bits_per_word;}
22150b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
22160b57cec5SDimitry Andric    static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
22170b57cec5SDimitry Andric        {return (__n - 1) / __bits_per_word + 1;}
22180b57cec5SDimitry Andric
22190b57cec5SDimitry Andricpublic:
22200b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
22210b57cec5SDimitry Andric    vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
22220b57cec5SDimitry Andric
22230b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
22240b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
22250b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
22260b57cec5SDimitry Andric#else
22270b57cec5SDimitry Andric        _NOEXCEPT;
22280b57cec5SDimitry Andric#endif
22290b57cec5SDimitry Andric    ~vector();
22300b57cec5SDimitry Andric    explicit vector(size_type __n);
22310b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
22320b57cec5SDimitry Andric    explicit vector(size_type __n, const allocator_type& __a);
22330b57cec5SDimitry Andric#endif
22340b57cec5SDimitry Andric    vector(size_type __n, const value_type& __v);
22350b57cec5SDimitry Andric    vector(size_type __n, const value_type& __v, const allocator_type& __a);
22360b57cec5SDimitry Andric    template <class _InputIterator>
22370b57cec5SDimitry Andric        vector(_InputIterator __first, _InputIterator __last,
2238480093f4SDimitry Andric               typename enable_if<__is_cpp17_input_iterator  <_InputIterator>::value &&
2239480093f4SDimitry Andric                                 !__is_cpp17_forward_iterator<_InputIterator>::value>::type* = 0);
22400b57cec5SDimitry Andric    template <class _InputIterator>
22410b57cec5SDimitry Andric        vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2242480093f4SDimitry Andric               typename enable_if<__is_cpp17_input_iterator  <_InputIterator>::value &&
2243480093f4SDimitry Andric                                 !__is_cpp17_forward_iterator<_InputIterator>::value>::type* = 0);
22440b57cec5SDimitry Andric    template <class _ForwardIterator>
22450b57cec5SDimitry Andric        vector(_ForwardIterator __first, _ForwardIterator __last,
2246480093f4SDimitry Andric               typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0);
22470b57cec5SDimitry Andric    template <class _ForwardIterator>
22480b57cec5SDimitry Andric        vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2249480093f4SDimitry Andric               typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0);
22500b57cec5SDimitry Andric
22510b57cec5SDimitry Andric    vector(const vector& __v);
22520b57cec5SDimitry Andric    vector(const vector& __v, const allocator_type& __a);
22530b57cec5SDimitry Andric    vector& operator=(const vector& __v);
22540b57cec5SDimitry Andric
22550b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
22560b57cec5SDimitry Andric    vector(initializer_list<value_type> __il);
22570b57cec5SDimitry Andric    vector(initializer_list<value_type> __il, const allocator_type& __a);
22580b57cec5SDimitry Andric
22590b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
22600b57cec5SDimitry Andric    vector(vector&& __v)
22610b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
22620b57cec5SDimitry Andric        _NOEXCEPT;
22630b57cec5SDimitry Andric#else
22640b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
22650b57cec5SDimitry Andric#endif
2266*fe6060f1SDimitry Andric    vector(vector&& __v, const __identity_t<allocator_type>& __a);
22670b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
22680b57cec5SDimitry Andric    vector& operator=(vector&& __v)
22690b57cec5SDimitry Andric        _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
22700b57cec5SDimitry Andric
22710b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
22720b57cec5SDimitry Andric    vector& operator=(initializer_list<value_type> __il)
22730b57cec5SDimitry Andric        {assign(__il.begin(), __il.end()); return *this;}
22740b57cec5SDimitry Andric
22750b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG
22760b57cec5SDimitry Andric
22770b57cec5SDimitry Andric    template <class _InputIterator>
22780b57cec5SDimitry Andric        typename enable_if
22790b57cec5SDimitry Andric        <
2280480093f4SDimitry Andric            __is_cpp17_input_iterator<_InputIterator>::value &&
2281480093f4SDimitry Andric           !__is_cpp17_forward_iterator<_InputIterator>::value,
22820b57cec5SDimitry Andric           void
22830b57cec5SDimitry Andric        >::type
22840b57cec5SDimitry Andric        assign(_InputIterator __first, _InputIterator __last);
22850b57cec5SDimitry Andric    template <class _ForwardIterator>
22860b57cec5SDimitry Andric        typename enable_if
22870b57cec5SDimitry Andric        <
2288480093f4SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value,
22890b57cec5SDimitry Andric           void
22900b57cec5SDimitry Andric        >::type
22910b57cec5SDimitry Andric        assign(_ForwardIterator __first, _ForwardIterator __last);
22920b57cec5SDimitry Andric
22930b57cec5SDimitry Andric    void assign(size_type __n, const value_type& __x);
22940b57cec5SDimitry Andric
22950b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
22960b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
22970b57cec5SDimitry Andric    void assign(initializer_list<value_type> __il)
22980b57cec5SDimitry Andric        {assign(__il.begin(), __il.end());}
22990b57cec5SDimitry Andric#endif
23000b57cec5SDimitry Andric
23010b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
23020b57cec5SDimitry Andric        {return allocator_type(this->__alloc());}
23030b57cec5SDimitry Andric
23040b57cec5SDimitry Andric    size_type max_size() const _NOEXCEPT;
23050b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23060b57cec5SDimitry Andric    size_type capacity() const _NOEXCEPT
23070b57cec5SDimitry Andric        {return __internal_cap_to_external(__cap());}
23080b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23090b57cec5SDimitry Andric    size_type size() const _NOEXCEPT
23100b57cec5SDimitry Andric        {return __size_;}
23110b57cec5SDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
23120b57cec5SDimitry Andric    bool empty() const _NOEXCEPT
23130b57cec5SDimitry Andric        {return __size_ == 0;}
23140b57cec5SDimitry Andric    void reserve(size_type __n);
23150b57cec5SDimitry Andric    void shrink_to_fit() _NOEXCEPT;
23160b57cec5SDimitry Andric
23170b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23180b57cec5SDimitry Andric    iterator begin() _NOEXCEPT
23190b57cec5SDimitry Andric        {return __make_iter(0);}
23200b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23210b57cec5SDimitry Andric    const_iterator begin() const _NOEXCEPT
23220b57cec5SDimitry Andric        {return __make_iter(0);}
23230b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23240b57cec5SDimitry Andric    iterator end() _NOEXCEPT
23250b57cec5SDimitry Andric        {return __make_iter(__size_);}
23260b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23270b57cec5SDimitry Andric    const_iterator end()   const _NOEXCEPT
23280b57cec5SDimitry Andric        {return __make_iter(__size_);}
23290b57cec5SDimitry Andric
23300b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23310b57cec5SDimitry Andric    reverse_iterator rbegin() _NOEXCEPT
23320b57cec5SDimitry Andric        {return       reverse_iterator(end());}
23330b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23340b57cec5SDimitry Andric    const_reverse_iterator rbegin() const _NOEXCEPT
23350b57cec5SDimitry Andric        {return const_reverse_iterator(end());}
23360b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23370b57cec5SDimitry Andric    reverse_iterator rend() _NOEXCEPT
23380b57cec5SDimitry Andric        {return       reverse_iterator(begin());}
23390b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23400b57cec5SDimitry Andric    const_reverse_iterator rend()   const _NOEXCEPT
23410b57cec5SDimitry Andric        {return const_reverse_iterator(begin());}
23420b57cec5SDimitry Andric
23430b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23440b57cec5SDimitry Andric    const_iterator         cbegin()  const _NOEXCEPT
23450b57cec5SDimitry Andric        {return __make_iter(0);}
23460b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23470b57cec5SDimitry Andric    const_iterator         cend()    const _NOEXCEPT
23480b57cec5SDimitry Andric        {return __make_iter(__size_);}
23490b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23500b57cec5SDimitry Andric    const_reverse_iterator crbegin() const _NOEXCEPT
23510b57cec5SDimitry Andric        {return rbegin();}
23520b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
23530b57cec5SDimitry Andric    const_reverse_iterator crend()   const _NOEXCEPT
23540b57cec5SDimitry Andric        {return rend();}
23550b57cec5SDimitry Andric
23560b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY reference       operator[](size_type __n)       {return __make_ref(__n);}
23570b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
23580b57cec5SDimitry Andric    reference       at(size_type __n);
23590b57cec5SDimitry Andric    const_reference at(size_type __n) const;
23600b57cec5SDimitry Andric
23610b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY reference       front()       {return __make_ref(0);}
23620b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
23630b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY reference       back()        {return __make_ref(__size_ - 1);}
23640b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY const_reference back()  const {return __make_ref(__size_ - 1);}
23650b57cec5SDimitry Andric
23660b57cec5SDimitry Andric    void push_back(const value_type& __x);
23670b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
23680b57cec5SDimitry Andric    template <class... _Args>
23690b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
23700b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY reference emplace_back(_Args&&... __args)
23710b57cec5SDimitry Andric#else
23720b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void      emplace_back(_Args&&... __args)
23730b57cec5SDimitry Andric#endif
23740b57cec5SDimitry Andric    {
23750b57cec5SDimitry Andric        push_back ( value_type ( _VSTD::forward<_Args>(__args)... ));
23760b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
23770b57cec5SDimitry Andric        return this->back();
23780b57cec5SDimitry Andric#endif
23790b57cec5SDimitry Andric    }
23800b57cec5SDimitry Andric#endif
23810b57cec5SDimitry Andric
23820b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
23830b57cec5SDimitry Andric
23840b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
23850b57cec5SDimitry Andric    template <class... _Args>
23860b57cec5SDimitry Andric   _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args)
23870b57cec5SDimitry Andric        { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); }
23880b57cec5SDimitry Andric#endif
23890b57cec5SDimitry Andric
23900b57cec5SDimitry Andric    iterator insert(const_iterator __position, const value_type& __x);
23910b57cec5SDimitry Andric    iterator insert(const_iterator __position, size_type __n, const value_type& __x);
23920b57cec5SDimitry Andric    iterator insert(const_iterator __position, size_type __n, const_reference __x);
23930b57cec5SDimitry Andric    template <class _InputIterator>
23940b57cec5SDimitry Andric        typename enable_if
23950b57cec5SDimitry Andric        <
2396480093f4SDimitry Andric             __is_cpp17_input_iterator  <_InputIterator>::value &&
2397480093f4SDimitry Andric            !__is_cpp17_forward_iterator<_InputIterator>::value,
23980b57cec5SDimitry Andric            iterator
23990b57cec5SDimitry Andric        >::type
24000b57cec5SDimitry Andric        insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
24010b57cec5SDimitry Andric    template <class _ForwardIterator>
24020b57cec5SDimitry Andric        typename enable_if
24030b57cec5SDimitry Andric        <
2404480093f4SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value,
24050b57cec5SDimitry Andric            iterator
24060b57cec5SDimitry Andric        >::type
24070b57cec5SDimitry Andric        insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
24080b57cec5SDimitry Andric
24090b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
24100b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
24110b57cec5SDimitry Andric    iterator insert(const_iterator __position, initializer_list<value_type> __il)
24120b57cec5SDimitry Andric        {return insert(__position, __il.begin(), __il.end());}
24130b57cec5SDimitry Andric#endif
24140b57cec5SDimitry Andric
24150b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
24160b57cec5SDimitry Andric    iterator erase(const_iterator __first, const_iterator __last);
24170b57cec5SDimitry Andric
24180b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
24190b57cec5SDimitry Andric    void clear() _NOEXCEPT {__size_ = 0;}
24200b57cec5SDimitry Andric
24210b57cec5SDimitry Andric    void swap(vector&)
24220b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
24230b57cec5SDimitry Andric        _NOEXCEPT;
24240b57cec5SDimitry Andric#else
24250b57cec5SDimitry Andric        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
24260b57cec5SDimitry Andric                    __is_nothrow_swappable<allocator_type>::value);
24270b57cec5SDimitry Andric#endif
24280b57cec5SDimitry Andric    static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); }
24290b57cec5SDimitry Andric
24300b57cec5SDimitry Andric    void resize(size_type __sz, value_type __x = false);
24310b57cec5SDimitry Andric    void flip() _NOEXCEPT;
24320b57cec5SDimitry Andric
24330b57cec5SDimitry Andric    bool __invariants() const;
24340b57cec5SDimitry Andric
24350b57cec5SDimitry Andricprivate:
24360b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
24370b57cec5SDimitry Andric    void __vallocate(size_type __n);
24380b57cec5SDimitry Andric    void __vdeallocate() _NOEXCEPT;
24390b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
24400b57cec5SDimitry Andric    static size_type __align_it(size_type __new_size) _NOEXCEPT
24410b57cec5SDimitry Andric        {return __new_size + (__bits_per_word-1) & ~((size_type)__bits_per_word-1);}
24420b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY  size_type __recommend(size_type __new_size) const;
24430b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
24440b57cec5SDimitry Andric    template <class _ForwardIterator>
24450b57cec5SDimitry Andric        typename enable_if
24460b57cec5SDimitry Andric        <
2447480093f4SDimitry Andric            __is_cpp17_forward_iterator<_ForwardIterator>::value,
24480b57cec5SDimitry Andric            void
24490b57cec5SDimitry Andric        >::type
24500b57cec5SDimitry Andric        __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
24510b57cec5SDimitry Andric    void __append(size_type __n, const_reference __x);
24520b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
24530b57cec5SDimitry Andric    reference __make_ref(size_type __pos) _NOEXCEPT
24540b57cec5SDimitry Andric        {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
24550b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
24560b57cec5SDimitry Andric    const_reference __make_ref(size_type __pos) const _NOEXCEPT
24570b57cec5SDimitry Andric        {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
24580b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
24590b57cec5SDimitry Andric    iterator __make_iter(size_type __pos) _NOEXCEPT
24600b57cec5SDimitry Andric        {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
24610b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
24620b57cec5SDimitry Andric    const_iterator __make_iter(size_type __pos) const _NOEXCEPT
24630b57cec5SDimitry Andric        {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
24640b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
24650b57cec5SDimitry Andric    iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
24660b57cec5SDimitry Andric        {return begin() + (__p - cbegin());}
24670b57cec5SDimitry Andric
24680b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
24690b57cec5SDimitry Andric    void __copy_assign_alloc(const vector& __v)
24700b57cec5SDimitry Andric        {__copy_assign_alloc(__v, integral_constant<bool,
24710b57cec5SDimitry Andric                      __storage_traits::propagate_on_container_copy_assignment::value>());}
24720b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
24730b57cec5SDimitry Andric    void __copy_assign_alloc(const vector& __c, true_type)
24740b57cec5SDimitry Andric        {
24750b57cec5SDimitry Andric            if (__alloc() != __c.__alloc())
24760b57cec5SDimitry Andric                __vdeallocate();
24770b57cec5SDimitry Andric            __alloc() = __c.__alloc();
24780b57cec5SDimitry Andric        }
24790b57cec5SDimitry Andric
24800b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
24810b57cec5SDimitry Andric    void __copy_assign_alloc(const vector&, false_type)
24820b57cec5SDimitry Andric        {}
24830b57cec5SDimitry Andric
24840b57cec5SDimitry Andric    void __move_assign(vector& __c, false_type);
24850b57cec5SDimitry Andric    void __move_assign(vector& __c, true_type)
24860b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
24870b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
24880b57cec5SDimitry Andric    void __move_assign_alloc(vector& __c)
24890b57cec5SDimitry Andric        _NOEXCEPT_(
24900b57cec5SDimitry Andric            !__storage_traits::propagate_on_container_move_assignment::value ||
24910b57cec5SDimitry Andric            is_nothrow_move_assignable<allocator_type>::value)
24920b57cec5SDimitry Andric        {__move_assign_alloc(__c, integral_constant<bool,
24930b57cec5SDimitry Andric                      __storage_traits::propagate_on_container_move_assignment::value>());}
24940b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
24950b57cec5SDimitry Andric    void __move_assign_alloc(vector& __c, true_type)
24960b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
24970b57cec5SDimitry Andric        {
24980b57cec5SDimitry Andric            __alloc() = _VSTD::move(__c.__alloc());
24990b57cec5SDimitry Andric        }
25000b57cec5SDimitry Andric
25010b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
25020b57cec5SDimitry Andric    void __move_assign_alloc(vector&, false_type)
25030b57cec5SDimitry Andric        _NOEXCEPT
25040b57cec5SDimitry Andric        {}
25050b57cec5SDimitry Andric
25060b57cec5SDimitry Andric    size_t __hash_code() const _NOEXCEPT;
25070b57cec5SDimitry Andric
25080b57cec5SDimitry Andric    friend class __bit_reference<vector>;
25090b57cec5SDimitry Andric    friend class __bit_const_reference<vector>;
25100b57cec5SDimitry Andric    friend class __bit_iterator<vector, false>;
25110b57cec5SDimitry Andric    friend class __bit_iterator<vector, true>;
25120b57cec5SDimitry Andric    friend struct __bit_array<vector>;
25130b57cec5SDimitry Andric    friend struct _LIBCPP_TEMPLATE_VIS hash<vector>;
25140b57cec5SDimitry Andric};
25150b57cec5SDimitry Andric
25160b57cec5SDimitry Andrictemplate <class _Allocator>
25170b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
25180b57cec5SDimitry Andricvoid
25190b57cec5SDimitry Andricvector<bool, _Allocator>::__invalidate_all_iterators()
25200b57cec5SDimitry Andric{
25210b57cec5SDimitry Andric}
25220b57cec5SDimitry Andric
25230b57cec5SDimitry Andric//  Allocate space for __n objects
25240b57cec5SDimitry Andric//  throws length_error if __n > max_size()
25250b57cec5SDimitry Andric//  throws (probably bad_alloc) if memory run out
25260b57cec5SDimitry Andric//  Precondition:  __begin_ == __end_ == __cap() == 0
25270b57cec5SDimitry Andric//  Precondition:  __n > 0
25280b57cec5SDimitry Andric//  Postcondition:  capacity() == __n
25290b57cec5SDimitry Andric//  Postcondition:  size() == 0
25300b57cec5SDimitry Andrictemplate <class _Allocator>
25310b57cec5SDimitry Andricvoid
25320b57cec5SDimitry Andricvector<bool, _Allocator>::__vallocate(size_type __n)
25330b57cec5SDimitry Andric{
25340b57cec5SDimitry Andric    if (__n > max_size())
25350b57cec5SDimitry Andric        this->__throw_length_error();
25360b57cec5SDimitry Andric    __n = __external_cap_to_internal(__n);
25370b57cec5SDimitry Andric    this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
25380b57cec5SDimitry Andric    this->__size_ = 0;
25390b57cec5SDimitry Andric    this->__cap() = __n;
25400b57cec5SDimitry Andric}
25410b57cec5SDimitry Andric
25420b57cec5SDimitry Andrictemplate <class _Allocator>
25430b57cec5SDimitry Andricvoid
25440b57cec5SDimitry Andricvector<bool, _Allocator>::__vdeallocate() _NOEXCEPT
25450b57cec5SDimitry Andric{
25460b57cec5SDimitry Andric    if (this->__begin_ != nullptr)
25470b57cec5SDimitry Andric    {
25480b57cec5SDimitry Andric        __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
25490b57cec5SDimitry Andric        __invalidate_all_iterators();
25500b57cec5SDimitry Andric        this->__begin_ = nullptr;
25510b57cec5SDimitry Andric        this->__size_ = this->__cap() = 0;
25520b57cec5SDimitry Andric    }
25530b57cec5SDimitry Andric}
25540b57cec5SDimitry Andric
25550b57cec5SDimitry Andrictemplate <class _Allocator>
25560b57cec5SDimitry Andrictypename vector<bool, _Allocator>::size_type
25570b57cec5SDimitry Andricvector<bool, _Allocator>::max_size() const _NOEXCEPT
25580b57cec5SDimitry Andric{
25590b57cec5SDimitry Andric    size_type __amax = __storage_traits::max_size(__alloc());
25600b57cec5SDimitry Andric    size_type __nmax = numeric_limits<size_type>::max() / 2;  // end() >= begin(), always
25610b57cec5SDimitry Andric    if (__nmax / __bits_per_word <= __amax)
25620b57cec5SDimitry Andric        return __nmax;
25630b57cec5SDimitry Andric    return __internal_cap_to_external(__amax);
25640b57cec5SDimitry Andric}
25650b57cec5SDimitry Andric
25660b57cec5SDimitry Andric//  Precondition:  __new_size > capacity()
25670b57cec5SDimitry Andrictemplate <class _Allocator>
25680b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
25690b57cec5SDimitry Andrictypename vector<bool, _Allocator>::size_type
25700b57cec5SDimitry Andricvector<bool, _Allocator>::__recommend(size_type __new_size) const
25710b57cec5SDimitry Andric{
25720b57cec5SDimitry Andric    const size_type __ms = max_size();
25730b57cec5SDimitry Andric    if (__new_size > __ms)
25740b57cec5SDimitry Andric        this->__throw_length_error();
25750b57cec5SDimitry Andric    const size_type __cap = capacity();
25760b57cec5SDimitry Andric    if (__cap >= __ms / 2)
25770b57cec5SDimitry Andric        return __ms;
25780b57cec5SDimitry Andric    return _VSTD::max(2 * __cap, __align_it(__new_size));
25790b57cec5SDimitry Andric}
25800b57cec5SDimitry Andric
25810b57cec5SDimitry Andric//  Default constructs __n objects starting at __end_
25820b57cec5SDimitry Andric//  Precondition:  __n > 0
25830b57cec5SDimitry Andric//  Precondition:  size() + __n <= capacity()
25840b57cec5SDimitry Andric//  Postcondition:  size() == size() + __n
25850b57cec5SDimitry Andrictemplate <class _Allocator>
25860b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
25870b57cec5SDimitry Andricvoid
25880b57cec5SDimitry Andricvector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
25890b57cec5SDimitry Andric{
25900b57cec5SDimitry Andric    size_type __old_size = this->__size_;
25910b57cec5SDimitry Andric    this->__size_ += __n;
25920b57cec5SDimitry Andric    if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word))
25930b57cec5SDimitry Andric    {
25940b57cec5SDimitry Andric        if (this->__size_ <= __bits_per_word)
25950b57cec5SDimitry Andric            this->__begin_[0] = __storage_type(0);
25960b57cec5SDimitry Andric        else
25970b57cec5SDimitry Andric            this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
25980b57cec5SDimitry Andric    }
25990b57cec5SDimitry Andric    _VSTD::fill_n(__make_iter(__old_size), __n, __x);
26000b57cec5SDimitry Andric}
26010b57cec5SDimitry Andric
26020b57cec5SDimitry Andrictemplate <class _Allocator>
26030b57cec5SDimitry Andrictemplate <class _ForwardIterator>
26040b57cec5SDimitry Andrictypename enable_if
26050b57cec5SDimitry Andric<
2606480093f4SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value,
26070b57cec5SDimitry Andric    void
26080b57cec5SDimitry Andric>::type
26090b57cec5SDimitry Andricvector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
26100b57cec5SDimitry Andric{
26110b57cec5SDimitry Andric    size_type __old_size = this->__size_;
26120b57cec5SDimitry Andric    this->__size_ += _VSTD::distance(__first, __last);
26130b57cec5SDimitry Andric    if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word))
26140b57cec5SDimitry Andric    {
26150b57cec5SDimitry Andric        if (this->__size_ <= __bits_per_word)
26160b57cec5SDimitry Andric            this->__begin_[0] = __storage_type(0);
26170b57cec5SDimitry Andric        else
26180b57cec5SDimitry Andric            this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
26190b57cec5SDimitry Andric    }
26200b57cec5SDimitry Andric    _VSTD::copy(__first, __last, __make_iter(__old_size));
26210b57cec5SDimitry Andric}
26220b57cec5SDimitry Andric
26230b57cec5SDimitry Andrictemplate <class _Allocator>
26240b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
26250b57cec5SDimitry Andricvector<bool, _Allocator>::vector()
26260b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
26270b57cec5SDimitry Andric    : __begin_(nullptr),
26280b57cec5SDimitry Andric      __size_(0),
2629480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
26300b57cec5SDimitry Andric{
26310b57cec5SDimitry Andric}
26320b57cec5SDimitry Andric
26330b57cec5SDimitry Andrictemplate <class _Allocator>
26340b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
26350b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const allocator_type& __a)
26360b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14
26370b57cec5SDimitry Andric        _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
26380b57cec5SDimitry Andric#else
26390b57cec5SDimitry Andric        _NOEXCEPT
26400b57cec5SDimitry Andric#endif
26410b57cec5SDimitry Andric    : __begin_(nullptr),
26420b57cec5SDimitry Andric      __size_(0),
26430b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
26440b57cec5SDimitry Andric{
26450b57cec5SDimitry Andric}
26460b57cec5SDimitry Andric
26470b57cec5SDimitry Andrictemplate <class _Allocator>
26480b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n)
26490b57cec5SDimitry Andric    : __begin_(nullptr),
26500b57cec5SDimitry Andric      __size_(0),
2651480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
26520b57cec5SDimitry Andric{
26530b57cec5SDimitry Andric    if (__n > 0)
26540b57cec5SDimitry Andric    {
26550b57cec5SDimitry Andric        __vallocate(__n);
26560b57cec5SDimitry Andric        __construct_at_end(__n, false);
26570b57cec5SDimitry Andric    }
26580b57cec5SDimitry Andric}
26590b57cec5SDimitry Andric
26600b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
26610b57cec5SDimitry Andrictemplate <class _Allocator>
26620b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
26630b57cec5SDimitry Andric    : __begin_(nullptr),
26640b57cec5SDimitry Andric      __size_(0),
26650b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
26660b57cec5SDimitry Andric{
26670b57cec5SDimitry Andric    if (__n > 0)
26680b57cec5SDimitry Andric    {
26690b57cec5SDimitry Andric        __vallocate(__n);
26700b57cec5SDimitry Andric        __construct_at_end(__n, false);
26710b57cec5SDimitry Andric    }
26720b57cec5SDimitry Andric}
26730b57cec5SDimitry Andric#endif
26740b57cec5SDimitry Andric
26750b57cec5SDimitry Andrictemplate <class _Allocator>
26760b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
26770b57cec5SDimitry Andric    : __begin_(nullptr),
26780b57cec5SDimitry Andric      __size_(0),
2679480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
26800b57cec5SDimitry Andric{
26810b57cec5SDimitry Andric    if (__n > 0)
26820b57cec5SDimitry Andric    {
26830b57cec5SDimitry Andric        __vallocate(__n);
26840b57cec5SDimitry Andric        __construct_at_end(__n, __x);
26850b57cec5SDimitry Andric    }
26860b57cec5SDimitry Andric}
26870b57cec5SDimitry Andric
26880b57cec5SDimitry Andrictemplate <class _Allocator>
26890b57cec5SDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
26900b57cec5SDimitry Andric    : __begin_(nullptr),
26910b57cec5SDimitry Andric      __size_(0),
26920b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
26930b57cec5SDimitry Andric{
26940b57cec5SDimitry Andric    if (__n > 0)
26950b57cec5SDimitry Andric    {
26960b57cec5SDimitry Andric        __vallocate(__n);
26970b57cec5SDimitry Andric        __construct_at_end(__n, __x);
26980b57cec5SDimitry Andric    }
26990b57cec5SDimitry Andric}
27000b57cec5SDimitry Andric
27010b57cec5SDimitry Andrictemplate <class _Allocator>
27020b57cec5SDimitry Andrictemplate <class _InputIterator>
27030b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2704480093f4SDimitry Andric       typename enable_if<__is_cpp17_input_iterator  <_InputIterator>::value &&
2705480093f4SDimitry Andric                         !__is_cpp17_forward_iterator<_InputIterator>::value>::type*)
27060b57cec5SDimitry Andric    : __begin_(nullptr),
27070b57cec5SDimitry Andric      __size_(0),
2708480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
27090b57cec5SDimitry Andric{
27100b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
27110b57cec5SDimitry Andric    try
27120b57cec5SDimitry Andric    {
27130b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
27140b57cec5SDimitry Andric        for (; __first != __last; ++__first)
27150b57cec5SDimitry Andric            push_back(*__first);
27160b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
27170b57cec5SDimitry Andric    }
27180b57cec5SDimitry Andric    catch (...)
27190b57cec5SDimitry Andric    {
27200b57cec5SDimitry Andric        if (__begin_ != nullptr)
27210b57cec5SDimitry Andric            __storage_traits::deallocate(__alloc(), __begin_, __cap());
27220b57cec5SDimitry Andric        __invalidate_all_iterators();
27230b57cec5SDimitry Andric        throw;
27240b57cec5SDimitry Andric    }
27250b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
27260b57cec5SDimitry Andric}
27270b57cec5SDimitry Andric
27280b57cec5SDimitry Andrictemplate <class _Allocator>
27290b57cec5SDimitry Andrictemplate <class _InputIterator>
27300b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2731480093f4SDimitry Andric       typename enable_if<__is_cpp17_input_iterator  <_InputIterator>::value &&
2732480093f4SDimitry Andric                         !__is_cpp17_forward_iterator<_InputIterator>::value>::type*)
27330b57cec5SDimitry Andric    : __begin_(nullptr),
27340b57cec5SDimitry Andric      __size_(0),
27350b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
27360b57cec5SDimitry Andric{
27370b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
27380b57cec5SDimitry Andric    try
27390b57cec5SDimitry Andric    {
27400b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
27410b57cec5SDimitry Andric        for (; __first != __last; ++__first)
27420b57cec5SDimitry Andric            push_back(*__first);
27430b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
27440b57cec5SDimitry Andric    }
27450b57cec5SDimitry Andric    catch (...)
27460b57cec5SDimitry Andric    {
27470b57cec5SDimitry Andric        if (__begin_ != nullptr)
27480b57cec5SDimitry Andric            __storage_traits::deallocate(__alloc(), __begin_, __cap());
27490b57cec5SDimitry Andric        __invalidate_all_iterators();
27500b57cec5SDimitry Andric        throw;
27510b57cec5SDimitry Andric    }
27520b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
27530b57cec5SDimitry Andric}
27540b57cec5SDimitry Andric
27550b57cec5SDimitry Andrictemplate <class _Allocator>
27560b57cec5SDimitry Andrictemplate <class _ForwardIterator>
27570b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2758480093f4SDimitry Andric                                typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*)
27590b57cec5SDimitry Andric    : __begin_(nullptr),
27600b57cec5SDimitry Andric      __size_(0),
2761480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
27620b57cec5SDimitry Andric{
27630b57cec5SDimitry Andric    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
27640b57cec5SDimitry Andric    if (__n > 0)
27650b57cec5SDimitry Andric    {
27660b57cec5SDimitry Andric        __vallocate(__n);
27670b57cec5SDimitry Andric        __construct_at_end(__first, __last);
27680b57cec5SDimitry Andric    }
27690b57cec5SDimitry Andric}
27700b57cec5SDimitry Andric
27710b57cec5SDimitry Andrictemplate <class _Allocator>
27720b57cec5SDimitry Andrictemplate <class _ForwardIterator>
27730b57cec5SDimitry Andricvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2774480093f4SDimitry Andric                                typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*)
27750b57cec5SDimitry Andric    : __begin_(nullptr),
27760b57cec5SDimitry Andric      __size_(0),
27770b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
27780b57cec5SDimitry Andric{
27790b57cec5SDimitry Andric    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
27800b57cec5SDimitry Andric    if (__n > 0)
27810b57cec5SDimitry Andric    {
27820b57cec5SDimitry Andric        __vallocate(__n);
27830b57cec5SDimitry Andric        __construct_at_end(__first, __last);
27840b57cec5SDimitry Andric    }
27850b57cec5SDimitry Andric}
27860b57cec5SDimitry Andric
27870b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
27880b57cec5SDimitry Andric
27890b57cec5SDimitry Andrictemplate <class _Allocator>
27900b57cec5SDimitry Andricvector<bool, _Allocator>::vector(initializer_list<value_type> __il)
27910b57cec5SDimitry Andric    : __begin_(nullptr),
27920b57cec5SDimitry Andric      __size_(0),
2793480093f4SDimitry Andric      __cap_alloc_(0, __default_init_tag())
27940b57cec5SDimitry Andric{
27950b57cec5SDimitry Andric    size_type __n = static_cast<size_type>(__il.size());
27960b57cec5SDimitry Andric    if (__n > 0)
27970b57cec5SDimitry Andric    {
27980b57cec5SDimitry Andric        __vallocate(__n);
27990b57cec5SDimitry Andric        __construct_at_end(__il.begin(), __il.end());
28000b57cec5SDimitry Andric    }
28010b57cec5SDimitry Andric}
28020b57cec5SDimitry Andric
28030b57cec5SDimitry Andrictemplate <class _Allocator>
28040b57cec5SDimitry Andricvector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
28050b57cec5SDimitry Andric    : __begin_(nullptr),
28060b57cec5SDimitry Andric      __size_(0),
28070b57cec5SDimitry Andric      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
28080b57cec5SDimitry Andric{
28090b57cec5SDimitry Andric    size_type __n = static_cast<size_type>(__il.size());
28100b57cec5SDimitry Andric    if (__n > 0)
28110b57cec5SDimitry Andric    {
28120b57cec5SDimitry Andric        __vallocate(__n);
28130b57cec5SDimitry Andric        __construct_at_end(__il.begin(), __il.end());
28140b57cec5SDimitry Andric    }
28150b57cec5SDimitry Andric}
28160b57cec5SDimitry Andric
28170b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
28180b57cec5SDimitry Andric
28190b57cec5SDimitry Andrictemplate <class _Allocator>
28200b57cec5SDimitry Andricvector<bool, _Allocator>::~vector()
28210b57cec5SDimitry Andric{
28220b57cec5SDimitry Andric    if (__begin_ != nullptr)
28230b57cec5SDimitry Andric        __storage_traits::deallocate(__alloc(), __begin_, __cap());
28240b57cec5SDimitry Andric    __invalidate_all_iterators();
28250b57cec5SDimitry Andric}
28260b57cec5SDimitry Andric
28270b57cec5SDimitry Andrictemplate <class _Allocator>
28280b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const vector& __v)
28290b57cec5SDimitry Andric    : __begin_(nullptr),
28300b57cec5SDimitry Andric      __size_(0),
28310b57cec5SDimitry Andric      __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
28320b57cec5SDimitry Andric{
28330b57cec5SDimitry Andric    if (__v.size() > 0)
28340b57cec5SDimitry Andric    {
28350b57cec5SDimitry Andric        __vallocate(__v.size());
28360b57cec5SDimitry Andric        __construct_at_end(__v.begin(), __v.end());
28370b57cec5SDimitry Andric    }
28380b57cec5SDimitry Andric}
28390b57cec5SDimitry Andric
28400b57cec5SDimitry Andrictemplate <class _Allocator>
28410b57cec5SDimitry Andricvector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
28420b57cec5SDimitry Andric    : __begin_(nullptr),
28430b57cec5SDimitry Andric      __size_(0),
28440b57cec5SDimitry Andric      __cap_alloc_(0, __a)
28450b57cec5SDimitry Andric{
28460b57cec5SDimitry Andric    if (__v.size() > 0)
28470b57cec5SDimitry Andric    {
28480b57cec5SDimitry Andric        __vallocate(__v.size());
28490b57cec5SDimitry Andric        __construct_at_end(__v.begin(), __v.end());
28500b57cec5SDimitry Andric    }
28510b57cec5SDimitry Andric}
28520b57cec5SDimitry Andric
28530b57cec5SDimitry Andrictemplate <class _Allocator>
28540b57cec5SDimitry Andricvector<bool, _Allocator>&
28550b57cec5SDimitry Andricvector<bool, _Allocator>::operator=(const vector& __v)
28560b57cec5SDimitry Andric{
28570b57cec5SDimitry Andric    if (this != &__v)
28580b57cec5SDimitry Andric    {
28590b57cec5SDimitry Andric        __copy_assign_alloc(__v);
28600b57cec5SDimitry Andric        if (__v.__size_)
28610b57cec5SDimitry Andric        {
28620b57cec5SDimitry Andric            if (__v.__size_ > capacity())
28630b57cec5SDimitry Andric            {
28640b57cec5SDimitry Andric                __vdeallocate();
28650b57cec5SDimitry Andric                __vallocate(__v.__size_);
28660b57cec5SDimitry Andric            }
28670b57cec5SDimitry Andric            _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
28680b57cec5SDimitry Andric        }
28690b57cec5SDimitry Andric        __size_ = __v.__size_;
28700b57cec5SDimitry Andric    }
28710b57cec5SDimitry Andric    return *this;
28720b57cec5SDimitry Andric}
28730b57cec5SDimitry Andric
28740b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
28750b57cec5SDimitry Andric
28760b57cec5SDimitry Andrictemplate <class _Allocator>
28770b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY vector<bool, _Allocator>::vector(vector&& __v)
28780b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14
28790b57cec5SDimitry Andric    _NOEXCEPT
28800b57cec5SDimitry Andric#else
28810b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
28820b57cec5SDimitry Andric#endif
28830b57cec5SDimitry Andric    : __begin_(__v.__begin_),
28840b57cec5SDimitry Andric      __size_(__v.__size_),
2885e8d8bef9SDimitry Andric      __cap_alloc_(_VSTD::move(__v.__cap_alloc_)) {
28860b57cec5SDimitry Andric    __v.__begin_ = nullptr;
28870b57cec5SDimitry Andric    __v.__size_ = 0;
28880b57cec5SDimitry Andric    __v.__cap() = 0;
28890b57cec5SDimitry Andric}
28900b57cec5SDimitry Andric
28910b57cec5SDimitry Andrictemplate <class _Allocator>
2892*fe6060f1SDimitry Andricvector<bool, _Allocator>::vector(vector&& __v, const __identity_t<allocator_type>& __a)
28930b57cec5SDimitry Andric    : __begin_(nullptr),
28940b57cec5SDimitry Andric      __size_(0),
28950b57cec5SDimitry Andric      __cap_alloc_(0, __a)
28960b57cec5SDimitry Andric{
28970b57cec5SDimitry Andric    if (__a == allocator_type(__v.__alloc()))
28980b57cec5SDimitry Andric    {
28990b57cec5SDimitry Andric        this->__begin_ = __v.__begin_;
29000b57cec5SDimitry Andric        this->__size_ = __v.__size_;
29010b57cec5SDimitry Andric        this->__cap() = __v.__cap();
29020b57cec5SDimitry Andric        __v.__begin_ = nullptr;
29030b57cec5SDimitry Andric        __v.__cap() = __v.__size_ = 0;
29040b57cec5SDimitry Andric    }
29050b57cec5SDimitry Andric    else if (__v.size() > 0)
29060b57cec5SDimitry Andric    {
29070b57cec5SDimitry Andric        __vallocate(__v.size());
29080b57cec5SDimitry Andric        __construct_at_end(__v.begin(), __v.end());
29090b57cec5SDimitry Andric    }
29100b57cec5SDimitry Andric}
29110b57cec5SDimitry Andric
29120b57cec5SDimitry Andrictemplate <class _Allocator>
29130b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
29140b57cec5SDimitry Andricvector<bool, _Allocator>&
29150b57cec5SDimitry Andricvector<bool, _Allocator>::operator=(vector&& __v)
29160b57cec5SDimitry Andric    _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
29170b57cec5SDimitry Andric{
29180b57cec5SDimitry Andric    __move_assign(__v, integral_constant<bool,
29190b57cec5SDimitry Andric          __storage_traits::propagate_on_container_move_assignment::value>());
29200b57cec5SDimitry Andric    return *this;
29210b57cec5SDimitry Andric}
29220b57cec5SDimitry Andric
29230b57cec5SDimitry Andrictemplate <class _Allocator>
29240b57cec5SDimitry Andricvoid
29250b57cec5SDimitry Andricvector<bool, _Allocator>::__move_assign(vector& __c, false_type)
29260b57cec5SDimitry Andric{
29270b57cec5SDimitry Andric    if (__alloc() != __c.__alloc())
29280b57cec5SDimitry Andric        assign(__c.begin(), __c.end());
29290b57cec5SDimitry Andric    else
29300b57cec5SDimitry Andric        __move_assign(__c, true_type());
29310b57cec5SDimitry Andric}
29320b57cec5SDimitry Andric
29330b57cec5SDimitry Andrictemplate <class _Allocator>
29340b57cec5SDimitry Andricvoid
29350b57cec5SDimitry Andricvector<bool, _Allocator>::__move_assign(vector& __c, true_type)
29360b57cec5SDimitry Andric    _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
29370b57cec5SDimitry Andric{
29380b57cec5SDimitry Andric    __vdeallocate();
29390b57cec5SDimitry Andric    __move_assign_alloc(__c);
29400b57cec5SDimitry Andric    this->__begin_ = __c.__begin_;
29410b57cec5SDimitry Andric    this->__size_ = __c.__size_;
29420b57cec5SDimitry Andric    this->__cap() = __c.__cap();
29430b57cec5SDimitry Andric    __c.__begin_ = nullptr;
29440b57cec5SDimitry Andric    __c.__cap() = __c.__size_ = 0;
29450b57cec5SDimitry Andric}
29460b57cec5SDimitry Andric
29470b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG
29480b57cec5SDimitry Andric
29490b57cec5SDimitry Andrictemplate <class _Allocator>
29500b57cec5SDimitry Andricvoid
29510b57cec5SDimitry Andricvector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
29520b57cec5SDimitry Andric{
29530b57cec5SDimitry Andric    __size_ = 0;
29540b57cec5SDimitry Andric    if (__n > 0)
29550b57cec5SDimitry Andric    {
29560b57cec5SDimitry Andric        size_type __c = capacity();
29570b57cec5SDimitry Andric        if (__n <= __c)
29580b57cec5SDimitry Andric            __size_ = __n;
29590b57cec5SDimitry Andric        else
29600b57cec5SDimitry Andric        {
29610b57cec5SDimitry Andric            vector __v(__alloc());
29620b57cec5SDimitry Andric            __v.reserve(__recommend(__n));
29630b57cec5SDimitry Andric            __v.__size_ = __n;
29640b57cec5SDimitry Andric            swap(__v);
29650b57cec5SDimitry Andric        }
29660b57cec5SDimitry Andric        _VSTD::fill_n(begin(), __n, __x);
29670b57cec5SDimitry Andric    }
29680b57cec5SDimitry Andric  __invalidate_all_iterators();
29690b57cec5SDimitry Andric}
29700b57cec5SDimitry Andric
29710b57cec5SDimitry Andrictemplate <class _Allocator>
29720b57cec5SDimitry Andrictemplate <class _InputIterator>
29730b57cec5SDimitry Andrictypename enable_if
29740b57cec5SDimitry Andric<
2975480093f4SDimitry Andric    __is_cpp17_input_iterator<_InputIterator>::value &&
2976480093f4SDimitry Andric   !__is_cpp17_forward_iterator<_InputIterator>::value,
29770b57cec5SDimitry Andric   void
29780b57cec5SDimitry Andric>::type
29790b57cec5SDimitry Andricvector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
29800b57cec5SDimitry Andric{
29810b57cec5SDimitry Andric    clear();
29820b57cec5SDimitry Andric    for (; __first != __last; ++__first)
29830b57cec5SDimitry Andric        push_back(*__first);
29840b57cec5SDimitry Andric}
29850b57cec5SDimitry Andric
29860b57cec5SDimitry Andrictemplate <class _Allocator>
29870b57cec5SDimitry Andrictemplate <class _ForwardIterator>
29880b57cec5SDimitry Andrictypename enable_if
29890b57cec5SDimitry Andric<
2990480093f4SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value,
29910b57cec5SDimitry Andric   void
29920b57cec5SDimitry Andric>::type
29930b57cec5SDimitry Andricvector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
29940b57cec5SDimitry Andric{
29950b57cec5SDimitry Andric    clear();
29960b57cec5SDimitry Andric    difference_type __ns = _VSTD::distance(__first, __last);
29970b57cec5SDimitry Andric    _LIBCPP_ASSERT(__ns >= 0, "invalid range specified");
29980b57cec5SDimitry Andric    const size_t __n = static_cast<size_type>(__ns);
29990b57cec5SDimitry Andric    if (__n)
30000b57cec5SDimitry Andric    {
30010b57cec5SDimitry Andric        if (__n > capacity())
30020b57cec5SDimitry Andric        {
30030b57cec5SDimitry Andric            __vdeallocate();
30040b57cec5SDimitry Andric            __vallocate(__n);
30050b57cec5SDimitry Andric        }
30060b57cec5SDimitry Andric        __construct_at_end(__first, __last);
30070b57cec5SDimitry Andric    }
30080b57cec5SDimitry Andric}
30090b57cec5SDimitry Andric
30100b57cec5SDimitry Andrictemplate <class _Allocator>
30110b57cec5SDimitry Andricvoid
30120b57cec5SDimitry Andricvector<bool, _Allocator>::reserve(size_type __n)
30130b57cec5SDimitry Andric{
30140b57cec5SDimitry Andric    if (__n > capacity())
30150b57cec5SDimitry Andric    {
30160b57cec5SDimitry Andric        vector __v(this->__alloc());
30170b57cec5SDimitry Andric        __v.__vallocate(__n);
30180b57cec5SDimitry Andric        __v.__construct_at_end(this->begin(), this->end());
30190b57cec5SDimitry Andric        swap(__v);
30200b57cec5SDimitry Andric        __invalidate_all_iterators();
30210b57cec5SDimitry Andric    }
30220b57cec5SDimitry Andric}
30230b57cec5SDimitry Andric
30240b57cec5SDimitry Andrictemplate <class _Allocator>
30250b57cec5SDimitry Andricvoid
30260b57cec5SDimitry Andricvector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
30270b57cec5SDimitry Andric{
30280b57cec5SDimitry Andric    if (__external_cap_to_internal(size()) > __cap())
30290b57cec5SDimitry Andric    {
30300b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
30310b57cec5SDimitry Andric        try
30320b57cec5SDimitry Andric        {
30330b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
30340b57cec5SDimitry Andric            vector(*this, allocator_type(__alloc())).swap(*this);
30350b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
30360b57cec5SDimitry Andric        }
30370b57cec5SDimitry Andric        catch (...)
30380b57cec5SDimitry Andric        {
30390b57cec5SDimitry Andric        }
30400b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
30410b57cec5SDimitry Andric    }
30420b57cec5SDimitry Andric}
30430b57cec5SDimitry Andric
30440b57cec5SDimitry Andrictemplate <class _Allocator>
30450b57cec5SDimitry Andrictypename vector<bool, _Allocator>::reference
30460b57cec5SDimitry Andricvector<bool, _Allocator>::at(size_type __n)
30470b57cec5SDimitry Andric{
30480b57cec5SDimitry Andric    if (__n >= size())
30490b57cec5SDimitry Andric        this->__throw_out_of_range();
30500b57cec5SDimitry Andric    return (*this)[__n];
30510b57cec5SDimitry Andric}
30520b57cec5SDimitry Andric
30530b57cec5SDimitry Andrictemplate <class _Allocator>
30540b57cec5SDimitry Andrictypename vector<bool, _Allocator>::const_reference
30550b57cec5SDimitry Andricvector<bool, _Allocator>::at(size_type __n) const
30560b57cec5SDimitry Andric{
30570b57cec5SDimitry Andric    if (__n >= size())
30580b57cec5SDimitry Andric        this->__throw_out_of_range();
30590b57cec5SDimitry Andric    return (*this)[__n];
30600b57cec5SDimitry Andric}
30610b57cec5SDimitry Andric
30620b57cec5SDimitry Andrictemplate <class _Allocator>
30630b57cec5SDimitry Andricvoid
30640b57cec5SDimitry Andricvector<bool, _Allocator>::push_back(const value_type& __x)
30650b57cec5SDimitry Andric{
30660b57cec5SDimitry Andric    if (this->__size_ == this->capacity())
30670b57cec5SDimitry Andric        reserve(__recommend(this->__size_ + 1));
30680b57cec5SDimitry Andric    ++this->__size_;
30690b57cec5SDimitry Andric    back() = __x;
30700b57cec5SDimitry Andric}
30710b57cec5SDimitry Andric
30720b57cec5SDimitry Andrictemplate <class _Allocator>
30730b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator
30740b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
30750b57cec5SDimitry Andric{
30760b57cec5SDimitry Andric    iterator __r;
30770b57cec5SDimitry Andric    if (size() < capacity())
30780b57cec5SDimitry Andric    {
30790b57cec5SDimitry Andric        const_iterator __old_end = end();
30800b57cec5SDimitry Andric        ++__size_;
30810b57cec5SDimitry Andric        _VSTD::copy_backward(__position, __old_end, end());
30820b57cec5SDimitry Andric        __r = __const_iterator_cast(__position);
30830b57cec5SDimitry Andric    }
30840b57cec5SDimitry Andric    else
30850b57cec5SDimitry Andric    {
30860b57cec5SDimitry Andric        vector __v(__alloc());
30870b57cec5SDimitry Andric        __v.reserve(__recommend(__size_ + 1));
30880b57cec5SDimitry Andric        __v.__size_ = __size_ + 1;
30890b57cec5SDimitry Andric        __r = _VSTD::copy(cbegin(), __position, __v.begin());
30900b57cec5SDimitry Andric        _VSTD::copy_backward(__position, cend(), __v.end());
30910b57cec5SDimitry Andric        swap(__v);
30920b57cec5SDimitry Andric    }
30930b57cec5SDimitry Andric    *__r = __x;
30940b57cec5SDimitry Andric    return __r;
30950b57cec5SDimitry Andric}
30960b57cec5SDimitry Andric
30970b57cec5SDimitry Andrictemplate <class _Allocator>
30980b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator
30990b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
31000b57cec5SDimitry Andric{
31010b57cec5SDimitry Andric    iterator __r;
31020b57cec5SDimitry Andric    size_type __c = capacity();
31030b57cec5SDimitry Andric    if (__n <= __c && size() <= __c - __n)
31040b57cec5SDimitry Andric    {
31050b57cec5SDimitry Andric        const_iterator __old_end = end();
31060b57cec5SDimitry Andric        __size_ += __n;
31070b57cec5SDimitry Andric        _VSTD::copy_backward(__position, __old_end, end());
31080b57cec5SDimitry Andric        __r = __const_iterator_cast(__position);
31090b57cec5SDimitry Andric    }
31100b57cec5SDimitry Andric    else
31110b57cec5SDimitry Andric    {
31120b57cec5SDimitry Andric        vector __v(__alloc());
31130b57cec5SDimitry Andric        __v.reserve(__recommend(__size_ + __n));
31140b57cec5SDimitry Andric        __v.__size_ = __size_ + __n;
31150b57cec5SDimitry Andric        __r = _VSTD::copy(cbegin(), __position, __v.begin());
31160b57cec5SDimitry Andric        _VSTD::copy_backward(__position, cend(), __v.end());
31170b57cec5SDimitry Andric        swap(__v);
31180b57cec5SDimitry Andric    }
31190b57cec5SDimitry Andric    _VSTD::fill_n(__r, __n, __x);
31200b57cec5SDimitry Andric    return __r;
31210b57cec5SDimitry Andric}
31220b57cec5SDimitry Andric
31230b57cec5SDimitry Andrictemplate <class _Allocator>
31240b57cec5SDimitry Andrictemplate <class _InputIterator>
31250b57cec5SDimitry Andrictypename enable_if
31260b57cec5SDimitry Andric<
3127480093f4SDimitry Andric     __is_cpp17_input_iterator  <_InputIterator>::value &&
3128480093f4SDimitry Andric    !__is_cpp17_forward_iterator<_InputIterator>::value,
31290b57cec5SDimitry Andric    typename vector<bool, _Allocator>::iterator
31300b57cec5SDimitry Andric>::type
31310b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
31320b57cec5SDimitry Andric{
31330b57cec5SDimitry Andric    difference_type __off = __position - begin();
31340b57cec5SDimitry Andric    iterator __p = __const_iterator_cast(__position);
31350b57cec5SDimitry Andric    iterator __old_end = end();
31360b57cec5SDimitry Andric    for (; size() != capacity() && __first != __last; ++__first)
31370b57cec5SDimitry Andric    {
31380b57cec5SDimitry Andric        ++this->__size_;
31390b57cec5SDimitry Andric        back() = *__first;
31400b57cec5SDimitry Andric    }
31410b57cec5SDimitry Andric    vector __v(__alloc());
31420b57cec5SDimitry Andric    if (__first != __last)
31430b57cec5SDimitry Andric    {
31440b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
31450b57cec5SDimitry Andric        try
31460b57cec5SDimitry Andric        {
31470b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
31480b57cec5SDimitry Andric            __v.assign(__first, __last);
31490b57cec5SDimitry Andric            difference_type __old_size = static_cast<difference_type>(__old_end - begin());
31500b57cec5SDimitry Andric            difference_type __old_p = __p - begin();
31510b57cec5SDimitry Andric            reserve(__recommend(size() + __v.size()));
31520b57cec5SDimitry Andric            __p = begin() + __old_p;
31530b57cec5SDimitry Andric            __old_end = begin() + __old_size;
31540b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS
31550b57cec5SDimitry Andric        }
31560b57cec5SDimitry Andric        catch (...)
31570b57cec5SDimitry Andric        {
31580b57cec5SDimitry Andric            erase(__old_end, end());
31590b57cec5SDimitry Andric            throw;
31600b57cec5SDimitry Andric        }
31610b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS
31620b57cec5SDimitry Andric    }
31630b57cec5SDimitry Andric    __p = _VSTD::rotate(__p, __old_end, end());
31640b57cec5SDimitry Andric    insert(__p, __v.begin(), __v.end());
31650b57cec5SDimitry Andric    return begin() + __off;
31660b57cec5SDimitry Andric}
31670b57cec5SDimitry Andric
31680b57cec5SDimitry Andrictemplate <class _Allocator>
31690b57cec5SDimitry Andrictemplate <class _ForwardIterator>
31700b57cec5SDimitry Andrictypename enable_if
31710b57cec5SDimitry Andric<
3172480093f4SDimitry Andric    __is_cpp17_forward_iterator<_ForwardIterator>::value,
31730b57cec5SDimitry Andric    typename vector<bool, _Allocator>::iterator
31740b57cec5SDimitry Andric>::type
31750b57cec5SDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
31760b57cec5SDimitry Andric{
31770b57cec5SDimitry Andric    const difference_type __n_signed = _VSTD::distance(__first, __last);
31780b57cec5SDimitry Andric    _LIBCPP_ASSERT(__n_signed >= 0, "invalid range specified");
31790b57cec5SDimitry Andric    const size_type __n = static_cast<size_type>(__n_signed);
31800b57cec5SDimitry Andric    iterator __r;
31810b57cec5SDimitry Andric    size_type __c = capacity();
31820b57cec5SDimitry Andric    if (__n <= __c && size() <= __c - __n)
31830b57cec5SDimitry Andric    {
31840b57cec5SDimitry Andric        const_iterator __old_end = end();
31850b57cec5SDimitry Andric        __size_ += __n;
31860b57cec5SDimitry Andric        _VSTD::copy_backward(__position, __old_end, end());
31870b57cec5SDimitry Andric        __r = __const_iterator_cast(__position);
31880b57cec5SDimitry Andric    }
31890b57cec5SDimitry Andric    else
31900b57cec5SDimitry Andric    {
31910b57cec5SDimitry Andric        vector __v(__alloc());
31920b57cec5SDimitry Andric        __v.reserve(__recommend(__size_ + __n));
31930b57cec5SDimitry Andric        __v.__size_ = __size_ + __n;
31940b57cec5SDimitry Andric        __r = _VSTD::copy(cbegin(), __position, __v.begin());
31950b57cec5SDimitry Andric        _VSTD::copy_backward(__position, cend(), __v.end());
31960b57cec5SDimitry Andric        swap(__v);
31970b57cec5SDimitry Andric    }
31980b57cec5SDimitry Andric    _VSTD::copy(__first, __last, __r);
31990b57cec5SDimitry Andric    return __r;
32000b57cec5SDimitry Andric}
32010b57cec5SDimitry Andric
32020b57cec5SDimitry Andrictemplate <class _Allocator>
32030b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
32040b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator
32050b57cec5SDimitry Andricvector<bool, _Allocator>::erase(const_iterator __position)
32060b57cec5SDimitry Andric{
32070b57cec5SDimitry Andric    iterator __r = __const_iterator_cast(__position);
32080b57cec5SDimitry Andric    _VSTD::copy(__position + 1, this->cend(), __r);
32090b57cec5SDimitry Andric    --__size_;
32100b57cec5SDimitry Andric    return __r;
32110b57cec5SDimitry Andric}
32120b57cec5SDimitry Andric
32130b57cec5SDimitry Andrictemplate <class _Allocator>
32140b57cec5SDimitry Andrictypename vector<bool, _Allocator>::iterator
32150b57cec5SDimitry Andricvector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
32160b57cec5SDimitry Andric{
32170b57cec5SDimitry Andric    iterator __r = __const_iterator_cast(__first);
32180b57cec5SDimitry Andric    difference_type __d = __last - __first;
32190b57cec5SDimitry Andric    _VSTD::copy(__last, this->cend(), __r);
32200b57cec5SDimitry Andric    __size_ -= __d;
32210b57cec5SDimitry Andric    return __r;
32220b57cec5SDimitry Andric}
32230b57cec5SDimitry Andric
32240b57cec5SDimitry Andrictemplate <class _Allocator>
32250b57cec5SDimitry Andricvoid
32260b57cec5SDimitry Andricvector<bool, _Allocator>::swap(vector& __x)
32270b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14
32280b57cec5SDimitry Andric    _NOEXCEPT
32290b57cec5SDimitry Andric#else
32300b57cec5SDimitry Andric    _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
32310b57cec5SDimitry Andric                __is_nothrow_swappable<allocator_type>::value)
32320b57cec5SDimitry Andric#endif
32330b57cec5SDimitry Andric{
32340b57cec5SDimitry Andric    _VSTD::swap(this->__begin_, __x.__begin_);
32350b57cec5SDimitry Andric    _VSTD::swap(this->__size_, __x.__size_);
32360b57cec5SDimitry Andric    _VSTD::swap(this->__cap(), __x.__cap());
3237e8d8bef9SDimitry Andric    _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(),
32380b57cec5SDimitry Andric        integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
32390b57cec5SDimitry Andric}
32400b57cec5SDimitry Andric
32410b57cec5SDimitry Andrictemplate <class _Allocator>
32420b57cec5SDimitry Andricvoid
32430b57cec5SDimitry Andricvector<bool, _Allocator>::resize(size_type __sz, value_type __x)
32440b57cec5SDimitry Andric{
32450b57cec5SDimitry Andric    size_type __cs = size();
32460b57cec5SDimitry Andric    if (__cs < __sz)
32470b57cec5SDimitry Andric    {
32480b57cec5SDimitry Andric        iterator __r;
32490b57cec5SDimitry Andric        size_type __c = capacity();
32500b57cec5SDimitry Andric        size_type __n = __sz - __cs;
32510b57cec5SDimitry Andric        if (__n <= __c && __cs <= __c - __n)
32520b57cec5SDimitry Andric        {
32530b57cec5SDimitry Andric            __r = end();
32540b57cec5SDimitry Andric            __size_ += __n;
32550b57cec5SDimitry Andric        }
32560b57cec5SDimitry Andric        else
32570b57cec5SDimitry Andric        {
32580b57cec5SDimitry Andric            vector __v(__alloc());
32590b57cec5SDimitry Andric            __v.reserve(__recommend(__size_ + __n));
32600b57cec5SDimitry Andric            __v.__size_ = __size_ + __n;
32610b57cec5SDimitry Andric            __r = _VSTD::copy(cbegin(), cend(), __v.begin());
32620b57cec5SDimitry Andric            swap(__v);
32630b57cec5SDimitry Andric        }
32640b57cec5SDimitry Andric        _VSTD::fill_n(__r, __n, __x);
32650b57cec5SDimitry Andric    }
32660b57cec5SDimitry Andric    else
32670b57cec5SDimitry Andric        __size_ = __sz;
32680b57cec5SDimitry Andric}
32690b57cec5SDimitry Andric
32700b57cec5SDimitry Andrictemplate <class _Allocator>
32710b57cec5SDimitry Andricvoid
32720b57cec5SDimitry Andricvector<bool, _Allocator>::flip() _NOEXCEPT
32730b57cec5SDimitry Andric{
32740b57cec5SDimitry Andric    // do middle whole words
32750b57cec5SDimitry Andric    size_type __n = __size_;
32760b57cec5SDimitry Andric    __storage_pointer __p = __begin_;
32770b57cec5SDimitry Andric    for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
32780b57cec5SDimitry Andric        *__p = ~*__p;
32790b57cec5SDimitry Andric    // do last partial word
32800b57cec5SDimitry Andric    if (__n > 0)
32810b57cec5SDimitry Andric    {
32820b57cec5SDimitry Andric        __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
32830b57cec5SDimitry Andric        __storage_type __b = *__p & __m;
32840b57cec5SDimitry Andric        *__p &= ~__m;
32850b57cec5SDimitry Andric        *__p |= ~__b & __m;
32860b57cec5SDimitry Andric    }
32870b57cec5SDimitry Andric}
32880b57cec5SDimitry Andric
32890b57cec5SDimitry Andrictemplate <class _Allocator>
32900b57cec5SDimitry Andricbool
32910b57cec5SDimitry Andricvector<bool, _Allocator>::__invariants() const
32920b57cec5SDimitry Andric{
32930b57cec5SDimitry Andric    if (this->__begin_ == nullptr)
32940b57cec5SDimitry Andric    {
32950b57cec5SDimitry Andric        if (this->__size_ != 0 || this->__cap() != 0)
32960b57cec5SDimitry Andric            return false;
32970b57cec5SDimitry Andric    }
32980b57cec5SDimitry Andric    else
32990b57cec5SDimitry Andric    {
33000b57cec5SDimitry Andric        if (this->__cap() == 0)
33010b57cec5SDimitry Andric            return false;
33020b57cec5SDimitry Andric        if (this->__size_ > this->capacity())
33030b57cec5SDimitry Andric            return false;
33040b57cec5SDimitry Andric    }
33050b57cec5SDimitry Andric    return true;
33060b57cec5SDimitry Andric}
33070b57cec5SDimitry Andric
33080b57cec5SDimitry Andrictemplate <class _Allocator>
33090b57cec5SDimitry Andricsize_t
33100b57cec5SDimitry Andricvector<bool, _Allocator>::__hash_code() const _NOEXCEPT
33110b57cec5SDimitry Andric{
33120b57cec5SDimitry Andric    size_t __h = 0;
33130b57cec5SDimitry Andric    // do middle whole words
33140b57cec5SDimitry Andric    size_type __n = __size_;
33150b57cec5SDimitry Andric    __storage_pointer __p = __begin_;
33160b57cec5SDimitry Andric    for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
33170b57cec5SDimitry Andric        __h ^= *__p;
33180b57cec5SDimitry Andric    // do last partial word
33190b57cec5SDimitry Andric    if (__n > 0)
33200b57cec5SDimitry Andric    {
33210b57cec5SDimitry Andric        const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
33220b57cec5SDimitry Andric        __h ^= *__p & __m;
33230b57cec5SDimitry Andric    }
33240b57cec5SDimitry Andric    return __h;
33250b57cec5SDimitry Andric}
33260b57cec5SDimitry Andric
33270b57cec5SDimitry Andrictemplate <class _Allocator>
33280b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
33290b57cec5SDimitry Andric    : public unary_function<vector<bool, _Allocator>, size_t>
33300b57cec5SDimitry Andric{
33310b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
33320b57cec5SDimitry Andric    size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
33330b57cec5SDimitry Andric        {return __vec.__hash_code();}
33340b57cec5SDimitry Andric};
33350b57cec5SDimitry Andric
33360b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
33370b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
33380b57cec5SDimitry Andricbool
33390b57cec5SDimitry Andricoperator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
33400b57cec5SDimitry Andric{
33410b57cec5SDimitry Andric    const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
33420b57cec5SDimitry Andric    return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
33430b57cec5SDimitry Andric}
33440b57cec5SDimitry Andric
33450b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
33460b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
33470b57cec5SDimitry Andricbool
33480b57cec5SDimitry Andricoperator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
33490b57cec5SDimitry Andric{
33500b57cec5SDimitry Andric    return !(__x == __y);
33510b57cec5SDimitry Andric}
33520b57cec5SDimitry Andric
33530b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
33540b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
33550b57cec5SDimitry Andricbool
33560b57cec5SDimitry Andricoperator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
33570b57cec5SDimitry Andric{
33580b57cec5SDimitry Andric    return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
33590b57cec5SDimitry Andric}
33600b57cec5SDimitry Andric
33610b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
33620b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
33630b57cec5SDimitry Andricbool
33640b57cec5SDimitry Andricoperator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
33650b57cec5SDimitry Andric{
33660b57cec5SDimitry Andric    return __y < __x;
33670b57cec5SDimitry Andric}
33680b57cec5SDimitry Andric
33690b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
33700b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
33710b57cec5SDimitry Andricbool
33720b57cec5SDimitry Andricoperator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
33730b57cec5SDimitry Andric{
33740b57cec5SDimitry Andric    return !(__x < __y);
33750b57cec5SDimitry Andric}
33760b57cec5SDimitry Andric
33770b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
33780b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
33790b57cec5SDimitry Andricbool
33800b57cec5SDimitry Andricoperator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
33810b57cec5SDimitry Andric{
33820b57cec5SDimitry Andric    return !(__y < __x);
33830b57cec5SDimitry Andric}
33840b57cec5SDimitry Andric
33850b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator>
33860b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY
33870b57cec5SDimitry Andricvoid
33880b57cec5SDimitry Andricswap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
33890b57cec5SDimitry Andric    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
33900b57cec5SDimitry Andric{
33910b57cec5SDimitry Andric    __x.swap(__y);
33920b57cec5SDimitry Andric}
33930b57cec5SDimitry Andric
33940b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17
33950b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Up>
33965ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type
33975ffd83dbSDimitry Andricerase(vector<_Tp, _Allocator>& __c, const _Up& __v) {
33985ffd83dbSDimitry Andric  auto __old_size = __c.size();
33995ffd83dbSDimitry Andric  __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end());
34005ffd83dbSDimitry Andric  return __old_size - __c.size();
34015ffd83dbSDimitry Andric}
34020b57cec5SDimitry Andric
34030b57cec5SDimitry Andrictemplate <class _Tp, class _Allocator, class _Predicate>
34045ffd83dbSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type
34055ffd83dbSDimitry Andricerase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) {
34065ffd83dbSDimitry Andric  auto __old_size = __c.size();
34075ffd83dbSDimitry Andric  __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end());
34085ffd83dbSDimitry Andric  return __old_size - __c.size();
34095ffd83dbSDimitry Andric}
34100b57cec5SDimitry Andric#endif
34110b57cec5SDimitry Andric
34120b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
34130b57cec5SDimitry Andric
34140b57cec5SDimitry Andric_LIBCPP_POP_MACROS
34150b57cec5SDimitry Andric
34160b57cec5SDimitry Andric#endif // _LIBCPP_VECTOR
3417