xref: /freebsd/contrib/llvm-project/libcxx/include/__cxx03/vector (revision 700637cbb5e582861067a11aaca4d053546871d2)
1*700637cbSDimitry Andric// -*- C++ -*-
2*700637cbSDimitry Andric//===----------------------------------------------------------------------===//
3*700637cbSDimitry Andric//
4*700637cbSDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5*700637cbSDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
6*700637cbSDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7*700637cbSDimitry Andric//
8*700637cbSDimitry Andric//===----------------------------------------------------------------------===//
9*700637cbSDimitry Andric
10*700637cbSDimitry Andric#ifndef _LIBCPP___CXX03_VECTOR
11*700637cbSDimitry Andric#define _LIBCPP___CXX03_VECTOR
12*700637cbSDimitry Andric
13*700637cbSDimitry Andric// clang-format off
14*700637cbSDimitry Andric
15*700637cbSDimitry Andric/*
16*700637cbSDimitry Andric    vector synopsis
17*700637cbSDimitry Andric
18*700637cbSDimitry Andricnamespace std
19*700637cbSDimitry Andric{
20*700637cbSDimitry Andric
21*700637cbSDimitry Andrictemplate <class T, class Allocator = allocator<T> >
22*700637cbSDimitry Andricclass vector
23*700637cbSDimitry Andric{
24*700637cbSDimitry Andricpublic:
25*700637cbSDimitry Andric    typedef T                                        value_type;
26*700637cbSDimitry Andric    typedef Allocator                                allocator_type;
27*700637cbSDimitry Andric    typedef typename allocator_type::reference       reference;
28*700637cbSDimitry Andric    typedef typename allocator_type::const_reference const_reference;
29*700637cbSDimitry Andric    typedef implementation-defined                   iterator;
30*700637cbSDimitry Andric    typedef implementation-defined                   const_iterator;
31*700637cbSDimitry Andric    typedef typename allocator_type::size_type       size_type;
32*700637cbSDimitry Andric    typedef typename allocator_type::difference_type difference_type;
33*700637cbSDimitry Andric    typedef typename allocator_type::pointer         pointer;
34*700637cbSDimitry Andric    typedef typename allocator_type::const_pointer   const_pointer;
35*700637cbSDimitry Andric    typedef std::reverse_iterator<iterator>          reverse_iterator;
36*700637cbSDimitry Andric    typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
37*700637cbSDimitry Andric
38*700637cbSDimitry Andric    vector()
39*700637cbSDimitry Andric        noexcept(is_nothrow_default_constructible<allocator_type>::value);
40*700637cbSDimitry Andric    explicit vector(const allocator_type&);
41*700637cbSDimitry Andric    explicit vector(size_type n);
42*700637cbSDimitry Andric    explicit vector(size_type n, const allocator_type&); // C++14
43*700637cbSDimitry Andric    vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
44*700637cbSDimitry Andric    template <class InputIterator>
45*700637cbSDimitry Andric        vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
46*700637cbSDimitry Andric    template<container-compatible-range<T> R>
47*700637cbSDimitry Andric      constexpr vector(from_range_t, R&& rg, const Allocator& = Allocator()); // C++23
48*700637cbSDimitry Andric    vector(const vector& x);
49*700637cbSDimitry Andric    vector(vector&& x)
50*700637cbSDimitry Andric        noexcept(is_nothrow_move_constructible<allocator_type>::value);
51*700637cbSDimitry Andric    vector(initializer_list<value_type> il);
52*700637cbSDimitry Andric    vector(initializer_list<value_type> il, const allocator_type& a);
53*700637cbSDimitry Andric    ~vector();
54*700637cbSDimitry Andric    vector& operator=(const vector& x);
55*700637cbSDimitry Andric    vector& operator=(vector&& x)
56*700637cbSDimitry Andric        noexcept(
57*700637cbSDimitry Andric             allocator_type::propagate_on_container_move_assignment::value ||
58*700637cbSDimitry Andric             allocator_type::is_always_equal::value); // C++17
59*700637cbSDimitry Andric    vector& operator=(initializer_list<value_type> il);
60*700637cbSDimitry Andric    template <class InputIterator>
61*700637cbSDimitry Andric        void assign(InputIterator first, InputIterator last);
62*700637cbSDimitry Andric    template<container-compatible-range<T> R>
63*700637cbSDimitry Andric      constexpr void assign_range(R&& rg); // C++23
64*700637cbSDimitry Andric    void assign(size_type n, const value_type& u);
65*700637cbSDimitry Andric    void assign(initializer_list<value_type> il);
66*700637cbSDimitry Andric
67*700637cbSDimitry Andric    allocator_type get_allocator() const noexcept;
68*700637cbSDimitry Andric
69*700637cbSDimitry Andric    iterator               begin() noexcept;
70*700637cbSDimitry Andric    const_iterator         begin()   const noexcept;
71*700637cbSDimitry Andric    iterator               end() noexcept;
72*700637cbSDimitry Andric    const_iterator         end()     const noexcept;
73*700637cbSDimitry Andric
74*700637cbSDimitry Andric    reverse_iterator       rbegin() noexcept;
75*700637cbSDimitry Andric    const_reverse_iterator rbegin()  const noexcept;
76*700637cbSDimitry Andric    reverse_iterator       rend() noexcept;
77*700637cbSDimitry Andric    const_reverse_iterator rend()    const noexcept;
78*700637cbSDimitry Andric
79*700637cbSDimitry Andric    const_iterator         cbegin()  const noexcept;
80*700637cbSDimitry Andric    const_iterator         cend()    const noexcept;
81*700637cbSDimitry Andric    const_reverse_iterator crbegin() const noexcept;
82*700637cbSDimitry Andric    const_reverse_iterator crend()   const noexcept;
83*700637cbSDimitry Andric
84*700637cbSDimitry Andric    size_type size() const noexcept;
85*700637cbSDimitry Andric    size_type max_size() const noexcept;
86*700637cbSDimitry Andric    size_type capacity() const noexcept;
87*700637cbSDimitry Andric    bool empty() const noexcept;
88*700637cbSDimitry Andric    void reserve(size_type n);
89*700637cbSDimitry Andric    void shrink_to_fit() noexcept;
90*700637cbSDimitry Andric
91*700637cbSDimitry Andric    reference       operator[](size_type n);
92*700637cbSDimitry Andric    const_reference operator[](size_type n) const;
93*700637cbSDimitry Andric    reference       at(size_type n);
94*700637cbSDimitry Andric    const_reference at(size_type n) const;
95*700637cbSDimitry Andric
96*700637cbSDimitry Andric    reference       front();
97*700637cbSDimitry Andric    const_reference front() const;
98*700637cbSDimitry Andric    reference       back();
99*700637cbSDimitry Andric    const_reference back() const;
100*700637cbSDimitry Andric
101*700637cbSDimitry Andric    value_type*       data() noexcept;
102*700637cbSDimitry Andric    const value_type* data() const noexcept;
103*700637cbSDimitry Andric
104*700637cbSDimitry Andric    void push_back(const value_type& x);
105*700637cbSDimitry Andric    void push_back(value_type&& x);
106*700637cbSDimitry Andric    template <class... Args>
107*700637cbSDimitry Andric        reference emplace_back(Args&&... args); // reference in C++17
108*700637cbSDimitry Andric    template<container-compatible-range<T> R>
109*700637cbSDimitry Andric      constexpr void append_range(R&& rg); // C++23
110*700637cbSDimitry Andric    void pop_back();
111*700637cbSDimitry Andric
112*700637cbSDimitry Andric    template <class... Args> iterator emplace(const_iterator position, Args&&... args);
113*700637cbSDimitry Andric    iterator insert(const_iterator position, const value_type& x);
114*700637cbSDimitry Andric    iterator insert(const_iterator position, value_type&& x);
115*700637cbSDimitry Andric    iterator insert(const_iterator position, size_type n, const value_type& x);
116*700637cbSDimitry Andric    template <class InputIterator>
117*700637cbSDimitry Andric        iterator insert(const_iterator position, InputIterator first, InputIterator last);
118*700637cbSDimitry Andric    template<container-compatible-range<T> R>
119*700637cbSDimitry Andric      constexpr iterator insert_range(const_iterator position, R&& rg); // C++23
120*700637cbSDimitry Andric    iterator insert(const_iterator position, initializer_list<value_type> il);
121*700637cbSDimitry Andric
122*700637cbSDimitry Andric    iterator erase(const_iterator position);
123*700637cbSDimitry Andric    iterator erase(const_iterator first, const_iterator last);
124*700637cbSDimitry Andric
125*700637cbSDimitry Andric    void clear() noexcept;
126*700637cbSDimitry Andric
127*700637cbSDimitry Andric    void resize(size_type sz);
128*700637cbSDimitry Andric    void resize(size_type sz, const value_type& c);
129*700637cbSDimitry Andric
130*700637cbSDimitry Andric    void swap(vector&)
131*700637cbSDimitry Andric        noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
132*700637cbSDimitry Andric                 allocator_traits<allocator_type>::is_always_equal::value);  // C++17
133*700637cbSDimitry Andric
134*700637cbSDimitry Andric    bool __invariants() const;
135*700637cbSDimitry Andric};
136*700637cbSDimitry Andric
137*700637cbSDimitry Andrictemplate <class Allocator = allocator<T> >
138*700637cbSDimitry Andricclass vector<bool, Allocator>
139*700637cbSDimitry Andric{
140*700637cbSDimitry Andricpublic:
141*700637cbSDimitry Andric    typedef bool                                     value_type;
142*700637cbSDimitry Andric    typedef Allocator                                allocator_type;
143*700637cbSDimitry Andric    typedef implementation-defined                   iterator;
144*700637cbSDimitry Andric    typedef implementation-defined                   const_iterator;
145*700637cbSDimitry Andric    typedef typename allocator_type::size_type       size_type;
146*700637cbSDimitry Andric    typedef typename allocator_type::difference_type difference_type;
147*700637cbSDimitry Andric    typedef iterator                                 pointer;
148*700637cbSDimitry Andric    typedef const_iterator                           const_pointer;
149*700637cbSDimitry Andric    typedef std::reverse_iterator<iterator>          reverse_iterator;
150*700637cbSDimitry Andric    typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
151*700637cbSDimitry Andric
152*700637cbSDimitry Andric    class reference
153*700637cbSDimitry Andric    {
154*700637cbSDimitry Andric    public:
155*700637cbSDimitry Andric        reference(const reference&) noexcept;
156*700637cbSDimitry Andric        operator bool() const noexcept;
157*700637cbSDimitry Andric        reference& operator=(bool x) noexcept;
158*700637cbSDimitry Andric        reference& operator=(const reference& x) noexcept;
159*700637cbSDimitry Andric        iterator operator&() const noexcept;
160*700637cbSDimitry Andric        void flip() noexcept;
161*700637cbSDimitry Andric    };
162*700637cbSDimitry Andric
163*700637cbSDimitry Andric    class const_reference
164*700637cbSDimitry Andric    {
165*700637cbSDimitry Andric    public:
166*700637cbSDimitry Andric        const_reference(const reference&) noexcept;
167*700637cbSDimitry Andric        operator bool() const noexcept;
168*700637cbSDimitry Andric        const_iterator operator&() const noexcept;
169*700637cbSDimitry Andric    };
170*700637cbSDimitry Andric
171*700637cbSDimitry Andric    vector()
172*700637cbSDimitry Andric        noexcept(is_nothrow_default_constructible<allocator_type>::value);
173*700637cbSDimitry Andric    explicit vector(const allocator_type&);
174*700637cbSDimitry Andric    explicit vector(size_type n, const allocator_type& a = allocator_type()); // C++14
175*700637cbSDimitry Andric    vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
176*700637cbSDimitry Andric    template <class InputIterator>
177*700637cbSDimitry Andric        vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
178*700637cbSDimitry Andric    template<container-compatible-range<bool> R>
179*700637cbSDimitry Andric      constexpr vector(from_range_t, R&& rg, const Allocator& = Allocator());
180*700637cbSDimitry Andric    vector(const vector& x);
181*700637cbSDimitry Andric    vector(vector&& x)
182*700637cbSDimitry Andric        noexcept(is_nothrow_move_constructible<allocator_type>::value);
183*700637cbSDimitry Andric    vector(initializer_list<value_type> il);
184*700637cbSDimitry Andric    vector(initializer_list<value_type> il, const allocator_type& a);
185*700637cbSDimitry Andric    ~vector();
186*700637cbSDimitry Andric    vector& operator=(const vector& x);
187*700637cbSDimitry Andric    vector& operator=(vector&& x)
188*700637cbSDimitry Andric        noexcept(
189*700637cbSDimitry Andric             allocator_type::propagate_on_container_move_assignment::value ||
190*700637cbSDimitry Andric             allocator_type::is_always_equal::value); // C++17
191*700637cbSDimitry Andric    vector& operator=(initializer_list<value_type> il);
192*700637cbSDimitry Andric    template <class InputIterator>
193*700637cbSDimitry Andric        void assign(InputIterator first, InputIterator last);
194*700637cbSDimitry Andric    template<container-compatible-range<T> R>
195*700637cbSDimitry Andric      constexpr void assign_range(R&& rg); // C++23
196*700637cbSDimitry Andric    void assign(size_type n, const value_type& u);
197*700637cbSDimitry Andric    void assign(initializer_list<value_type> il);
198*700637cbSDimitry Andric
199*700637cbSDimitry Andric    allocator_type get_allocator() const noexcept;
200*700637cbSDimitry Andric
201*700637cbSDimitry Andric    iterator               begin() noexcept;
202*700637cbSDimitry Andric    const_iterator         begin()   const noexcept;
203*700637cbSDimitry Andric    iterator               end() noexcept;
204*700637cbSDimitry Andric    const_iterator         end()     const noexcept;
205*700637cbSDimitry Andric
206*700637cbSDimitry Andric    reverse_iterator       rbegin() noexcept;
207*700637cbSDimitry Andric    const_reverse_iterator rbegin()  const noexcept;
208*700637cbSDimitry Andric    reverse_iterator       rend() noexcept;
209*700637cbSDimitry Andric    const_reverse_iterator rend()    const noexcept;
210*700637cbSDimitry Andric
211*700637cbSDimitry Andric    const_iterator         cbegin()  const noexcept;
212*700637cbSDimitry Andric    const_iterator         cend()    const noexcept;
213*700637cbSDimitry Andric    const_reverse_iterator crbegin() const noexcept;
214*700637cbSDimitry Andric    const_reverse_iterator crend()   const noexcept;
215*700637cbSDimitry Andric
216*700637cbSDimitry Andric    size_type size() const noexcept;
217*700637cbSDimitry Andric    size_type max_size() const noexcept;
218*700637cbSDimitry Andric    size_type capacity() const noexcept;
219*700637cbSDimitry Andric    bool empty() const noexcept;
220*700637cbSDimitry Andric    void reserve(size_type n);
221*700637cbSDimitry Andric    void shrink_to_fit() noexcept;
222*700637cbSDimitry Andric
223*700637cbSDimitry Andric    reference       operator[](size_type n);
224*700637cbSDimitry Andric    const_reference operator[](size_type n) const;
225*700637cbSDimitry Andric    reference       at(size_type n);
226*700637cbSDimitry Andric    const_reference at(size_type n) const;
227*700637cbSDimitry Andric
228*700637cbSDimitry Andric    reference       front();
229*700637cbSDimitry Andric    const_reference front() const;
230*700637cbSDimitry Andric    reference       back();
231*700637cbSDimitry Andric    const_reference back() const;
232*700637cbSDimitry Andric
233*700637cbSDimitry Andric    void push_back(const value_type& x);
234*700637cbSDimitry Andric    template <class... Args> reference emplace_back(Args&&... args);  // C++14; reference in C++17
235*700637cbSDimitry Andric    template<container-compatible-range<T> R>
236*700637cbSDimitry Andric      constexpr void append_range(R&& rg); // C++23
237*700637cbSDimitry Andric    void pop_back();
238*700637cbSDimitry Andric
239*700637cbSDimitry Andric    template <class... Args> iterator emplace(const_iterator position, Args&&... args);  // C++14
240*700637cbSDimitry Andric    iterator insert(const_iterator position, const value_type& x);
241*700637cbSDimitry Andric    iterator insert(const_iterator position, size_type n, const value_type& x);
242*700637cbSDimitry Andric    template <class InputIterator>
243*700637cbSDimitry Andric        iterator insert(const_iterator position, InputIterator first, InputIterator last);
244*700637cbSDimitry Andric    template<container-compatible-range<T> R>
245*700637cbSDimitry Andric      constexpr iterator insert_range(const_iterator position, R&& rg); // C++23
246*700637cbSDimitry Andric    iterator insert(const_iterator position, initializer_list<value_type> il);
247*700637cbSDimitry Andric
248*700637cbSDimitry Andric    iterator erase(const_iterator position);
249*700637cbSDimitry Andric    iterator erase(const_iterator first, const_iterator last);
250*700637cbSDimitry Andric
251*700637cbSDimitry Andric    void clear() noexcept;
252*700637cbSDimitry Andric
253*700637cbSDimitry Andric    void resize(size_type sz);
254*700637cbSDimitry Andric    void resize(size_type sz, value_type x);
255*700637cbSDimitry Andric
256*700637cbSDimitry Andric    void swap(vector&)
257*700637cbSDimitry Andric        noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
258*700637cbSDimitry Andric                 allocator_traits<allocator_type>::is_always_equal::value);  // C++17
259*700637cbSDimitry Andric    void flip() noexcept;
260*700637cbSDimitry Andric
261*700637cbSDimitry Andric    bool __invariants() const;
262*700637cbSDimitry Andric};
263*700637cbSDimitry Andric
264*700637cbSDimitry Andrictemplate <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
265*700637cbSDimitry Andric   vector(InputIterator, InputIterator, Allocator = Allocator())
266*700637cbSDimitry Andric   -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17
267*700637cbSDimitry Andric
268*700637cbSDimitry Andrictemplate<ranges::input_range R, class Allocator = allocator<ranges::range_value_t<R>>>
269*700637cbSDimitry Andric  vector(from_range_t, R&&, Allocator = Allocator())
270*700637cbSDimitry Andric    -> vector<ranges::range_value_t<R>, Allocator>; // C++23
271*700637cbSDimitry Andric
272*700637cbSDimitry Andrictemplate <class Allocator> struct hash<std::vector<bool, Allocator>>;
273*700637cbSDimitry Andric
274*700637cbSDimitry Andrictemplate <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y);   // constexpr since C++20
275*700637cbSDimitry Andrictemplate <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);   // removed in C++20
276*700637cbSDimitry Andrictemplate <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y);   // removed in C++20
277*700637cbSDimitry Andrictemplate <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y);   // removed in C++20
278*700637cbSDimitry Andrictemplate <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);   // removed in C++20
279*700637cbSDimitry Andrictemplate <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);   // removed in C++20
280*700637cbSDimitry Andrictemplate <class T, class Allocator> constexpr
281*700637cbSDimitry Andric  constexpr synth-three-way-result<T> operator<=>(const vector<T, Allocator>& x,
282*700637cbSDimitry Andric                                                  const vector<T, Allocator>& y);                                  // since C++20
283*700637cbSDimitry Andric
284*700637cbSDimitry Andrictemplate <class T, class Allocator>
285*700637cbSDimitry Andricvoid swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
286*700637cbSDimitry Andric    noexcept(noexcept(x.swap(y)));
287*700637cbSDimitry Andric
288*700637cbSDimitry Andrictemplate <class T, class Allocator, class U>
289*700637cbSDimitry Andrictypename vector<T, Allocator>::size_type
290*700637cbSDimitry Andricerase(vector<T, Allocator>& c, const U& value);       // since C++20
291*700637cbSDimitry Andrictemplate <class T, class Allocator, class Predicate>
292*700637cbSDimitry Andrictypename vector<T, Allocator>::size_type
293*700637cbSDimitry Andricerase_if(vector<T, Allocator>& c, Predicate pred);    // since C++20
294*700637cbSDimitry Andric
295*700637cbSDimitry Andric
296*700637cbSDimitry Andrictemplate<class T>
297*700637cbSDimitry Andric inline constexpr bool is-vector-bool-reference = see below;        // exposition only, since C++23
298*700637cbSDimitry Andric
299*700637cbSDimitry Andrictemplate<class T, class charT> requires is-vector-bool-reference<T> // Since C++23
300*700637cbSDimitry Andric struct formatter<T, charT>;
301*700637cbSDimitry Andric
302*700637cbSDimitry Andric}  // std
303*700637cbSDimitry Andric
304*700637cbSDimitry Andric*/
305*700637cbSDimitry Andric
306*700637cbSDimitry Andric// clang-format on
307*700637cbSDimitry Andric
308*700637cbSDimitry Andric#include <__cxx03/__algorithm/copy.h>
309*700637cbSDimitry Andric#include <__cxx03/__algorithm/equal.h>
310*700637cbSDimitry Andric#include <__cxx03/__algorithm/fill_n.h>
311*700637cbSDimitry Andric#include <__cxx03/__algorithm/iterator_operations.h>
312*700637cbSDimitry Andric#include <__cxx03/__algorithm/lexicographical_compare.h>
313*700637cbSDimitry Andric#include <__cxx03/__algorithm/remove.h>
314*700637cbSDimitry Andric#include <__cxx03/__algorithm/remove_if.h>
315*700637cbSDimitry Andric#include <__cxx03/__algorithm/rotate.h>
316*700637cbSDimitry Andric#include <__cxx03/__algorithm/unwrap_iter.h>
317*700637cbSDimitry Andric#include <__cxx03/__assert>
318*700637cbSDimitry Andric#include <__cxx03/__bit_reference>
319*700637cbSDimitry Andric#include <__cxx03/__config>
320*700637cbSDimitry Andric#include <__cxx03/__debug_utils/sanitizers.h>
321*700637cbSDimitry Andric#include <__cxx03/__functional/hash.h>
322*700637cbSDimitry Andric#include <__cxx03/__functional/unary_function.h>
323*700637cbSDimitry Andric#include <__cxx03/__fwd/vector.h>
324*700637cbSDimitry Andric#include <__cxx03/__iterator/advance.h>
325*700637cbSDimitry Andric#include <__cxx03/__iterator/bounded_iter.h>
326*700637cbSDimitry Andric#include <__cxx03/__iterator/distance.h>
327*700637cbSDimitry Andric#include <__cxx03/__iterator/iterator_traits.h>
328*700637cbSDimitry Andric#include <__cxx03/__iterator/reverse_iterator.h>
329*700637cbSDimitry Andric#include <__cxx03/__iterator/wrap_iter.h>
330*700637cbSDimitry Andric#include <__cxx03/__memory/addressof.h>
331*700637cbSDimitry Andric#include <__cxx03/__memory/allocate_at_least.h>
332*700637cbSDimitry Andric#include <__cxx03/__memory/allocator_traits.h>
333*700637cbSDimitry Andric#include <__cxx03/__memory/pointer_traits.h>
334*700637cbSDimitry Andric#include <__cxx03/__memory/swap_allocator.h>
335*700637cbSDimitry Andric#include <__cxx03/__memory/temp_value.h>
336*700637cbSDimitry Andric#include <__cxx03/__memory/uninitialized_algorithms.h>
337*700637cbSDimitry Andric#include <__cxx03/__split_buffer>
338*700637cbSDimitry Andric#include <__cxx03/__type_traits/is_allocator.h>
339*700637cbSDimitry Andric#include <__cxx03/__type_traits/is_constructible.h>
340*700637cbSDimitry Andric#include <__cxx03/__type_traits/is_nothrow_assignable.h>
341*700637cbSDimitry Andric#include <__cxx03/__type_traits/noexcept_move_assign_container.h>
342*700637cbSDimitry Andric#include <__cxx03/__type_traits/type_identity.h>
343*700637cbSDimitry Andric#include <__cxx03/__utility/exception_guard.h>
344*700637cbSDimitry Andric#include <__cxx03/__utility/forward.h>
345*700637cbSDimitry Andric#include <__cxx03/__utility/is_pointer_in_range.h>
346*700637cbSDimitry Andric#include <__cxx03/__utility/move.h>
347*700637cbSDimitry Andric#include <__cxx03/__utility/pair.h>
348*700637cbSDimitry Andric#include <__cxx03/__utility/swap.h>
349*700637cbSDimitry Andric#include <__cxx03/climits>
350*700637cbSDimitry Andric#include <__cxx03/cstring>
351*700637cbSDimitry Andric#include <__cxx03/limits>
352*700637cbSDimitry Andric#include <__cxx03/stdexcept>
353*700637cbSDimitry Andric#include <__cxx03/version>
354*700637cbSDimitry Andric
355*700637cbSDimitry Andric// standard-mandated includes
356*700637cbSDimitry Andric
357*700637cbSDimitry Andric// [iterator.range]
358*700637cbSDimitry Andric#include <__cxx03/__iterator/access.h>
359*700637cbSDimitry Andric
360*700637cbSDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
361*700637cbSDimitry Andric#  pragma GCC system_header
362*700637cbSDimitry Andric#endif
363*700637cbSDimitry Andric
364*700637cbSDimitry Andric_LIBCPP_PUSH_MACROS
365*700637cbSDimitry Andric#include <__cxx03/__undef_macros>
366*700637cbSDimitry Andric
367*700637cbSDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
368*700637cbSDimitry Andric
369*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator /* = allocator<_Tp> */>
370*700637cbSDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector {
371*700637cbSDimitry Andricprivate:
372*700637cbSDimitry Andric  typedef allocator<_Tp> __default_allocator_type;
373*700637cbSDimitry Andric
374*700637cbSDimitry Andricpublic:
375*700637cbSDimitry Andric  typedef vector __self;
376*700637cbSDimitry Andric  typedef _Tp value_type;
377*700637cbSDimitry Andric  typedef _Allocator allocator_type;
378*700637cbSDimitry Andric  typedef allocator_traits<allocator_type> __alloc_traits;
379*700637cbSDimitry Andric  typedef value_type& reference;
380*700637cbSDimitry Andric  typedef const value_type& const_reference;
381*700637cbSDimitry Andric  typedef typename __alloc_traits::size_type size_type;
382*700637cbSDimitry Andric  typedef typename __alloc_traits::difference_type difference_type;
383*700637cbSDimitry Andric  typedef typename __alloc_traits::pointer pointer;
384*700637cbSDimitry Andric  typedef typename __alloc_traits::const_pointer const_pointer;
385*700637cbSDimitry Andric#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR
386*700637cbSDimitry Andric  // Users might provide custom allocators, and prior to C++20 we have no existing way to detect whether the allocator's
387*700637cbSDimitry Andric  // pointer type is contiguous (though it has to be by the Standard). Using the wrapper type ensures the iterator is
388*700637cbSDimitry Andric  // considered contiguous.
389*700637cbSDimitry Andric  typedef __bounded_iter<__wrap_iter<pointer>> iterator;
390*700637cbSDimitry Andric  typedef __bounded_iter<__wrap_iter<const_pointer>> const_iterator;
391*700637cbSDimitry Andric#else
392*700637cbSDimitry Andric  typedef __wrap_iter<pointer> iterator;
393*700637cbSDimitry Andric  typedef __wrap_iter<const_pointer> const_iterator;
394*700637cbSDimitry Andric#endif
395*700637cbSDimitry Andric  typedef std::reverse_iterator<iterator> reverse_iterator;
396*700637cbSDimitry Andric  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
397*700637cbSDimitry Andric
398*700637cbSDimitry Andric  // A vector containers the following members which may be trivially relocatable:
399*700637cbSDimitry Andric  // - pointer: may be trivially relocatable, so it's checked
400*700637cbSDimitry Andric  // - allocator_type: may be trivially relocatable, so it's checked
401*700637cbSDimitry Andric  // vector doesn't contain any self-references, so it's trivially relocatable if its members are.
402*700637cbSDimitry Andric  using __trivially_relocatable = __conditional_t<
403*700637cbSDimitry Andric      __libcpp_is_trivially_relocatable<pointer>::value && __libcpp_is_trivially_relocatable<allocator_type>::value,
404*700637cbSDimitry Andric      vector,
405*700637cbSDimitry Andric      void>;
406*700637cbSDimitry Andric
407*700637cbSDimitry Andric  static_assert(__check_valid_allocator<allocator_type>::value, "");
408*700637cbSDimitry Andric  static_assert(is_same<typename allocator_type::value_type, value_type>::value,
409*700637cbSDimitry Andric                "Allocator::value_type must be same type as value_type");
410*700637cbSDimitry Andric
411*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector() {}
412*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit vector(const allocator_type& __a) : __end_cap_(nullptr, __a) {}
413*700637cbSDimitry Andric
414*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n) {
415*700637cbSDimitry Andric    auto __guard = std::__make_exception_guard(__destroy_vector(*this));
416*700637cbSDimitry Andric    if (__n > 0) {
417*700637cbSDimitry Andric      __vallocate(__n);
418*700637cbSDimitry Andric      __construct_at_end(__n);
419*700637cbSDimitry Andric    }
420*700637cbSDimitry Andric    __guard.__complete();
421*700637cbSDimitry Andric  }
422*700637cbSDimitry Andric
423*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector(size_type __n, const value_type& __x) {
424*700637cbSDimitry Andric    auto __guard = std::__make_exception_guard(__destroy_vector(*this));
425*700637cbSDimitry Andric    if (__n > 0) {
426*700637cbSDimitry Andric      __vallocate(__n);
427*700637cbSDimitry Andric      __construct_at_end(__n, __x);
428*700637cbSDimitry Andric    }
429*700637cbSDimitry Andric    __guard.__complete();
430*700637cbSDimitry Andric  }
431*700637cbSDimitry Andric
432*700637cbSDimitry Andric  template <__enable_if_t<__is_allocator<_Allocator>::value, int> = 0>
433*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector(size_type __n, const value_type& __x, const allocator_type& __a)
434*700637cbSDimitry Andric      : __end_cap_(nullptr, __a) {
435*700637cbSDimitry Andric    if (__n > 0) {
436*700637cbSDimitry Andric      __vallocate(__n);
437*700637cbSDimitry Andric      __construct_at_end(__n, __x);
438*700637cbSDimitry Andric    }
439*700637cbSDimitry Andric  }
440*700637cbSDimitry Andric
441*700637cbSDimitry Andric  template <class _InputIterator,
442*700637cbSDimitry Andric            __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
443*700637cbSDimitry Andric                              is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,
444*700637cbSDimitry Andric                          int> = 0>
445*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector(_InputIterator __first, _InputIterator __last);
446*700637cbSDimitry Andric  template <class _InputIterator,
447*700637cbSDimitry Andric            __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
448*700637cbSDimitry Andric                              is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,
449*700637cbSDimitry Andric                          int> = 0>
450*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
451*700637cbSDimitry Andric
452*700637cbSDimitry Andric  template <
453*700637cbSDimitry Andric      class _ForwardIterator,
454*700637cbSDimitry Andric      __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
455*700637cbSDimitry Andric                        is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
456*700637cbSDimitry Andric                    int> = 0>
457*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector(_ForwardIterator __first, _ForwardIterator __last);
458*700637cbSDimitry Andric
459*700637cbSDimitry Andric  template <
460*700637cbSDimitry Andric      class _ForwardIterator,
461*700637cbSDimitry Andric      __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
462*700637cbSDimitry Andric                        is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
463*700637cbSDimitry Andric                    int> = 0>
464*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a);
465*700637cbSDimitry Andric
466*700637cbSDimitry Andricprivate:
467*700637cbSDimitry Andric  class __destroy_vector {
468*700637cbSDimitry Andric  public:
469*700637cbSDimitry Andric    _LIBCPP_HIDE_FROM_ABI __destroy_vector(vector& __vec) : __vec_(__vec) {}
470*700637cbSDimitry Andric
471*700637cbSDimitry Andric    _LIBCPP_HIDE_FROM_ABI void operator()() {
472*700637cbSDimitry Andric      if (__vec_.__begin_ != nullptr) {
473*700637cbSDimitry Andric        __vec_.__clear();
474*700637cbSDimitry Andric        __vec_.__annotate_delete();
475*700637cbSDimitry Andric        __alloc_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.capacity());
476*700637cbSDimitry Andric      }
477*700637cbSDimitry Andric    }
478*700637cbSDimitry Andric
479*700637cbSDimitry Andric  private:
480*700637cbSDimitry Andric    vector& __vec_;
481*700637cbSDimitry Andric  };
482*700637cbSDimitry Andric
483*700637cbSDimitry Andricpublic:
484*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI ~vector() { __destroy_vector (*this)(); }
485*700637cbSDimitry Andric
486*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector(const vector& __x);
487*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector(const vector& __x, const __type_identity_t<allocator_type>& __a);
488*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector& operator=(const vector& __x);
489*700637cbSDimitry Andric
490*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector(vector&& __x);
491*700637cbSDimitry Andric
492*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector(vector&& __x, const __type_identity_t<allocator_type>& __a);
493*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector& operator=(vector&& __x);
494*700637cbSDimitry Andric
495*700637cbSDimitry Andric  template <class _InputIterator,
496*700637cbSDimitry Andric            __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
497*700637cbSDimitry Andric                              is_constructible<value_type, typename iterator_traits<_InputIterator>::reference>::value,
498*700637cbSDimitry Andric                          int> = 0>
499*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void assign(_InputIterator __first, _InputIterator __last);
500*700637cbSDimitry Andric  template <
501*700637cbSDimitry Andric      class _ForwardIterator,
502*700637cbSDimitry Andric      __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
503*700637cbSDimitry Andric                        is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
504*700637cbSDimitry Andric                    int> = 0>
505*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void assign(_ForwardIterator __first, _ForwardIterator __last);
506*700637cbSDimitry Andric
507*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const_reference __u);
508*700637cbSDimitry Andric
509*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT { return this->__alloc(); }
510*700637cbSDimitry Andric
511*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT;
512*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT;
513*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT;
514*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT;
515*700637cbSDimitry Andric
516*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT { return reverse_iterator(end()); }
517*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(end()); }
518*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() _NOEXCEPT { return reverse_iterator(begin()); }
519*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(begin()); }
520*700637cbSDimitry Andric
521*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return begin(); }
522*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return end(); }
523*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT { return rbegin(); }
524*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
525*700637cbSDimitry Andric
526*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT {
527*700637cbSDimitry Andric    return static_cast<size_type>(this->__end_ - this->__begin_);
528*700637cbSDimitry Andric  }
529*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type capacity() const _NOEXCEPT {
530*700637cbSDimitry Andric    return static_cast<size_type>(__end_cap() - this->__begin_);
531*700637cbSDimitry Andric  }
532*700637cbSDimitry Andric  _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return this->__begin_ == this->__end_; }
533*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT;
534*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void reserve(size_type __n);
535*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void shrink_to_fit() _NOEXCEPT;
536*700637cbSDimitry Andric
537*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reference operator[](size_type __n) _NOEXCEPT;
538*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference operator[](size_type __n) const _NOEXCEPT;
539*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reference at(size_type __n);
540*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __n) const;
541*700637cbSDimitry Andric
542*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reference front() _NOEXCEPT {
543*700637cbSDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "front() called on an empty vector");
544*700637cbSDimitry Andric    return *this->__begin_;
545*700637cbSDimitry Andric  }
546*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference front() const _NOEXCEPT {
547*700637cbSDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "front() called on an empty vector");
548*700637cbSDimitry Andric    return *this->__begin_;
549*700637cbSDimitry Andric  }
550*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reference back() _NOEXCEPT {
551*700637cbSDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "back() called on an empty vector");
552*700637cbSDimitry Andric    return *(this->__end_ - 1);
553*700637cbSDimitry Andric  }
554*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference back() const _NOEXCEPT {
555*700637cbSDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "back() called on an empty vector");
556*700637cbSDimitry Andric    return *(this->__end_ - 1);
557*700637cbSDimitry Andric  }
558*700637cbSDimitry Andric
559*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI value_type* data() _NOEXCEPT { return std::__to_address(this->__begin_); }
560*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const value_type* data() const _NOEXCEPT { return std::__to_address(this->__begin_); }
561*700637cbSDimitry Andric
562*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void push_back(const_reference __x);
563*700637cbSDimitry Andric
564*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __x);
565*700637cbSDimitry Andric
566*700637cbSDimitry Andric  template <class... _Args>
567*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void emplace_back(_Args&&... __args);
568*700637cbSDimitry Andric
569*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void pop_back();
570*700637cbSDimitry Andric
571*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, const_reference __x);
572*700637cbSDimitry Andric
573*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, value_type&& __x);
574*700637cbSDimitry Andric  template <class... _Args>
575*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __position, _Args&&... __args);
576*700637cbSDimitry Andric
577*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, size_type __n, const_reference __x);
578*700637cbSDimitry Andric
579*700637cbSDimitry Andric  template <class _InputIterator,
580*700637cbSDimitry Andric            __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
581*700637cbSDimitry Andric                              is_constructible< value_type, typename iterator_traits<_InputIterator>::reference>::value,
582*700637cbSDimitry Andric                          int> = 0>
583*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
584*700637cbSDimitry Andric
585*700637cbSDimitry Andric  template <
586*700637cbSDimitry Andric      class _ForwardIterator,
587*700637cbSDimitry Andric      __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
588*700637cbSDimitry Andric                        is_constructible< value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
589*700637cbSDimitry Andric                    int> = 0>
590*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
591*700637cbSDimitry Andric
592*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __position);
593*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last);
594*700637cbSDimitry Andric
595*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT {
596*700637cbSDimitry Andric    size_type __old_size = size();
597*700637cbSDimitry Andric    __clear();
598*700637cbSDimitry Andric    __annotate_shrink(__old_size);
599*700637cbSDimitry Andric  }
600*700637cbSDimitry Andric
601*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz);
602*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz, const_reference __x);
603*700637cbSDimitry Andric
604*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void swap(vector&);
605*700637cbSDimitry Andric
606*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool __invariants() const;
607*700637cbSDimitry Andric
608*700637cbSDimitry Andricprivate:
609*700637cbSDimitry Andric  pointer __begin_ = nullptr;
610*700637cbSDimitry Andric  pointer __end_   = nullptr;
611*700637cbSDimitry Andric  __compressed_pair<pointer, allocator_type> __end_cap_ =
612*700637cbSDimitry Andric      __compressed_pair<pointer, allocator_type>(nullptr, __default_init_tag());
613*700637cbSDimitry Andric
614*700637cbSDimitry Andric  //  Allocate space for __n objects
615*700637cbSDimitry Andric  //  throws length_error if __n > max_size()
616*700637cbSDimitry Andric  //  throws (probably bad_alloc) if memory run out
617*700637cbSDimitry Andric  //  Precondition:  __begin_ == __end_ == __end_cap() == 0
618*700637cbSDimitry Andric  //  Precondition:  __n > 0
619*700637cbSDimitry Andric  //  Postcondition:  capacity() >= __n
620*700637cbSDimitry Andric  //  Postcondition:  size() == 0
621*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) {
622*700637cbSDimitry Andric    if (__n > max_size())
623*700637cbSDimitry Andric      __throw_length_error();
624*700637cbSDimitry Andric    auto __allocation = std::__allocate_at_least(__alloc(), __n);
625*700637cbSDimitry Andric    __begin_          = __allocation.ptr;
626*700637cbSDimitry Andric    __end_            = __allocation.ptr;
627*700637cbSDimitry Andric    __end_cap()       = __begin_ + __allocation.count;
628*700637cbSDimitry Andric    __annotate_new(0);
629*700637cbSDimitry Andric  }
630*700637cbSDimitry Andric
631*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __vdeallocate() _NOEXCEPT;
632*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type __recommend(size_type __new_size) const;
633*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __construct_at_end(size_type __n);
634*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __construct_at_end(size_type __n, const_reference __x);
635*700637cbSDimitry Andric
636*700637cbSDimitry Andric  template <class _InputIterator, class _Sentinel>
637*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __init_with_size(_InputIterator __first, _Sentinel __last, size_type __n) {
638*700637cbSDimitry Andric    auto __guard = std::__make_exception_guard(__destroy_vector(*this));
639*700637cbSDimitry Andric
640*700637cbSDimitry Andric    if (__n > 0) {
641*700637cbSDimitry Andric      __vallocate(__n);
642*700637cbSDimitry Andric      __construct_at_end(__first, __last, __n);
643*700637cbSDimitry Andric    }
644*700637cbSDimitry Andric
645*700637cbSDimitry Andric    __guard.__complete();
646*700637cbSDimitry Andric  }
647*700637cbSDimitry Andric
648*700637cbSDimitry Andric  template <class _InputIterator, class _Sentinel>
649*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __init_with_sentinel(_InputIterator __first, _Sentinel __last) {
650*700637cbSDimitry Andric    auto __guard = std::__make_exception_guard(__destroy_vector(*this));
651*700637cbSDimitry Andric
652*700637cbSDimitry Andric    for (; __first != __last; ++__first)
653*700637cbSDimitry Andric      emplace_back(*__first);
654*700637cbSDimitry Andric
655*700637cbSDimitry Andric    __guard.__complete();
656*700637cbSDimitry Andric  }
657*700637cbSDimitry Andric
658*700637cbSDimitry Andric  template <class _Iterator, class _Sentinel>
659*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __assign_with_sentinel(_Iterator __first, _Sentinel __last);
660*700637cbSDimitry Andric
661*700637cbSDimitry Andric  template <class _ForwardIterator, class _Sentinel>
662*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __n);
663*700637cbSDimitry Andric
664*700637cbSDimitry Andric  template <class _InputIterator, class _Sentinel>
665*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator
666*700637cbSDimitry Andric  __insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last);
667*700637cbSDimitry Andric
668*700637cbSDimitry Andric  template <class _Iterator, class _Sentinel>
669*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator
670*700637cbSDimitry Andric  __insert_with_size(const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n);
671*700637cbSDimitry Andric
672*700637cbSDimitry Andric  template <class _InputIterator, class _Sentinel>
673*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n);
674*700637cbSDimitry Andric
675*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __append(size_type __n);
676*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __append(size_type __n, const_reference __x);
677*700637cbSDimitry Andric
678*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator __make_iter(pointer __p) _NOEXCEPT {
679*700637cbSDimitry Andric#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR
680*700637cbSDimitry Andric    // Bound the iterator according to the capacity, rather than the size.
681*700637cbSDimitry Andric    //
682*700637cbSDimitry Andric    // Vector guarantees that iterators stay valid as long as no reallocation occurs even if new elements are inserted
683*700637cbSDimitry Andric    // into the container; for these cases, we need to make sure that the newly-inserted elements can be accessed
684*700637cbSDimitry Andric    // through the bounded iterator without failing checks. The downside is that the bounded iterator won't catch
685*700637cbSDimitry Andric    // access that is logically out-of-bounds, i.e., goes beyond the size, but is still within the capacity. With the
686*700637cbSDimitry Andric    // current implementation, there is no connection between a bounded iterator and its associated container, so we
687*700637cbSDimitry Andric    // don't have a way to update existing valid iterators when the container is resized and thus have to go with
688*700637cbSDimitry Andric    // a laxer approach.
689*700637cbSDimitry Andric    return std::__make_bounded_iter(
690*700637cbSDimitry Andric        std::__wrap_iter<pointer>(__p),
691*700637cbSDimitry Andric        std::__wrap_iter<pointer>(this->__begin_),
692*700637cbSDimitry Andric        std::__wrap_iter<pointer>(this->__end_cap()));
693*700637cbSDimitry Andric#else
694*700637cbSDimitry Andric    return iterator(__p);
695*700637cbSDimitry Andric#endif // _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR
696*700637cbSDimitry Andric  }
697*700637cbSDimitry Andric
698*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator __make_iter(const_pointer __p) const _NOEXCEPT {
699*700637cbSDimitry Andric#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR
700*700637cbSDimitry Andric    // Bound the iterator according to the capacity, rather than the size.
701*700637cbSDimitry Andric    return std::__make_bounded_iter(
702*700637cbSDimitry Andric        std::__wrap_iter<const_pointer>(__p),
703*700637cbSDimitry Andric        std::__wrap_iter<const_pointer>(this->__begin_),
704*700637cbSDimitry Andric        std::__wrap_iter<const_pointer>(this->__end_cap()));
705*700637cbSDimitry Andric#else
706*700637cbSDimitry Andric    return const_iterator(__p);
707*700637cbSDimitry Andric#endif // _LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR
708*700637cbSDimitry Andric  }
709*700637cbSDimitry Andric
710*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
711*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pointer
712*700637cbSDimitry Andric  __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
713*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __move_range(pointer __from_s, pointer __from_e, pointer __to);
714*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, true_type);
715*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, false_type);
716*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __destruct_at_end(pointer __new_last) _NOEXCEPT {
717*700637cbSDimitry Andric    size_type __old_size = size();
718*700637cbSDimitry Andric    __base_destruct_at_end(__new_last);
719*700637cbSDimitry Andric    __annotate_shrink(__old_size);
720*700637cbSDimitry Andric  }
721*700637cbSDimitry Andric
722*700637cbSDimitry Andric  template <class _Up>
723*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI inline pointer __push_back_slow_path(_Up&& __x);
724*700637cbSDimitry Andric
725*700637cbSDimitry Andric  template <class... _Args>
726*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI inline pointer __emplace_back_slow_path(_Args&&... __args);
727*700637cbSDimitry Andric
728*700637cbSDimitry Andric  // The following functions are no-ops outside of AddressSanitizer mode.
729*700637cbSDimitry Andric  // We call annotations for every allocator, unless explicitly disabled.
730*700637cbSDimitry Andric  //
731*700637cbSDimitry Andric  // To disable annotations for a particular allocator, change value of
732*700637cbSDimitry Andric  // __asan_annotate_container_with_allocator to false.
733*700637cbSDimitry Andric  // For more details, see the "Using libc++" documentation page or
734*700637cbSDimitry Andric  // the documentation for __sanitizer_annotate_contiguous_container.
735*700637cbSDimitry Andric
736*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __annotate_contiguous_container(const void* __old_mid, const void* __new_mid) const {
737*700637cbSDimitry Andric    std::__annotate_contiguous_container<_Allocator>(data(), data() + capacity(), __old_mid, __new_mid);
738*700637cbSDimitry Andric  }
739*700637cbSDimitry Andric
740*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __annotate_new(size_type __current_size) const _NOEXCEPT {
741*700637cbSDimitry Andric    (void)__current_size;
742*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
743*700637cbSDimitry Andric    __annotate_contiguous_container(data() + capacity(), data() + __current_size);
744*700637cbSDimitry Andric#endif
745*700637cbSDimitry Andric  }
746*700637cbSDimitry Andric
747*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __annotate_delete() const _NOEXCEPT {
748*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
749*700637cbSDimitry Andric    __annotate_contiguous_container(data() + size(), data() + capacity());
750*700637cbSDimitry Andric#endif
751*700637cbSDimitry Andric  }
752*700637cbSDimitry Andric
753*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __annotate_increase(size_type __n) const _NOEXCEPT {
754*700637cbSDimitry Andric    (void)__n;
755*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
756*700637cbSDimitry Andric    __annotate_contiguous_container(data() + size(), data() + size() + __n);
757*700637cbSDimitry Andric#endif
758*700637cbSDimitry Andric  }
759*700637cbSDimitry Andric
760*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __annotate_shrink(size_type __old_size) const _NOEXCEPT {
761*700637cbSDimitry Andric    (void)__old_size;
762*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
763*700637cbSDimitry Andric    __annotate_contiguous_container(data() + __old_size, data() + size());
764*700637cbSDimitry Andric#endif
765*700637cbSDimitry Andric  }
766*700637cbSDimitry Andric
767*700637cbSDimitry Andric  struct _ConstructTransaction {
768*700637cbSDimitry Andric    _LIBCPP_HIDE_FROM_ABI explicit _ConstructTransaction(vector& __v, size_type __n)
769*700637cbSDimitry Andric        : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) {
770*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
771*700637cbSDimitry Andric      __v_.__annotate_increase(__n);
772*700637cbSDimitry Andric#endif
773*700637cbSDimitry Andric    }
774*700637cbSDimitry Andric
775*700637cbSDimitry Andric    _LIBCPP_HIDE_FROM_ABI ~_ConstructTransaction() {
776*700637cbSDimitry Andric      __v_.__end_ = __pos_;
777*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_ASAN
778*700637cbSDimitry Andric      if (__pos_ != __new_end_) {
779*700637cbSDimitry Andric        __v_.__annotate_shrink(__new_end_ - __v_.__begin_);
780*700637cbSDimitry Andric      }
781*700637cbSDimitry Andric#endif
782*700637cbSDimitry Andric    }
783*700637cbSDimitry Andric
784*700637cbSDimitry Andric    vector& __v_;
785*700637cbSDimitry Andric    pointer __pos_;
786*700637cbSDimitry Andric    const_pointer const __new_end_;
787*700637cbSDimitry Andric
788*700637cbSDimitry Andric    _ConstructTransaction(_ConstructTransaction const&)            = delete;
789*700637cbSDimitry Andric    _ConstructTransaction& operator=(_ConstructTransaction const&) = delete;
790*700637cbSDimitry Andric  };
791*700637cbSDimitry Andric
792*700637cbSDimitry Andric  template <class... _Args>
793*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __construct_one_at_end(_Args&&... __args) {
794*700637cbSDimitry Andric    _ConstructTransaction __tx(*this, 1);
795*700637cbSDimitry Andric    __alloc_traits::construct(this->__alloc(), std::__to_address(__tx.__pos_), std::forward<_Args>(__args)...);
796*700637cbSDimitry Andric    ++__tx.__pos_;
797*700637cbSDimitry Andric  }
798*700637cbSDimitry Andric
799*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI allocator_type& __alloc() _NOEXCEPT { return this->__end_cap_.second(); }
800*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const allocator_type& __alloc() const _NOEXCEPT { return this->__end_cap_.second(); }
801*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pointer& __end_cap() _NOEXCEPT { return this->__end_cap_.first(); }
802*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const pointer& __end_cap() const _NOEXCEPT { return this->__end_cap_.first(); }
803*700637cbSDimitry Andric
804*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __clear() _NOEXCEPT { __base_destruct_at_end(this->__begin_); }
805*700637cbSDimitry Andric
806*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __base_destruct_at_end(pointer __new_last) _NOEXCEPT {
807*700637cbSDimitry Andric    pointer __soon_to_be_end = this->__end_;
808*700637cbSDimitry Andric    while (__new_last != __soon_to_be_end)
809*700637cbSDimitry Andric      __alloc_traits::destroy(__alloc(), std::__to_address(--__soon_to_be_end));
810*700637cbSDimitry Andric    this->__end_ = __new_last;
811*700637cbSDimitry Andric  }
812*700637cbSDimitry Andric
813*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const vector& __c) {
814*700637cbSDimitry Andric    __copy_assign_alloc(__c, integral_constant<bool, __alloc_traits::propagate_on_container_copy_assignment::value>());
815*700637cbSDimitry Andric  }
816*700637cbSDimitry Andric
817*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector& __c) {
818*700637cbSDimitry Andric    __move_assign_alloc(__c, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>());
819*700637cbSDimitry Andric  }
820*700637cbSDimitry Andric
821*700637cbSDimitry Andric  _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_length_error() const { std::__throw_length_error("vector"); }
822*700637cbSDimitry Andric
823*700637cbSDimitry Andric  _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range() const { std::__throw_out_of_range("vector"); }
824*700637cbSDimitry Andric
825*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const vector& __c, true_type) {
826*700637cbSDimitry Andric    if (__alloc() != __c.__alloc()) {
827*700637cbSDimitry Andric      __clear();
828*700637cbSDimitry Andric      __annotate_delete();
829*700637cbSDimitry Andric      __alloc_traits::deallocate(__alloc(), this->__begin_, capacity());
830*700637cbSDimitry Andric      this->__begin_ = this->__end_ = __end_cap() = nullptr;
831*700637cbSDimitry Andric    }
832*700637cbSDimitry Andric    __alloc() = __c.__alloc();
833*700637cbSDimitry Andric  }
834*700637cbSDimitry Andric
835*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const vector&, false_type) {}
836*700637cbSDimitry Andric
837*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector& __c, true_type) { __alloc() = std::move(__c.__alloc()); }
838*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector&, false_type) _NOEXCEPT {}
839*700637cbSDimitry Andric};
840*700637cbSDimitry Andric
841*700637cbSDimitry Andric// __swap_out_circular_buffer relocates the objects in [__begin_, __end_) into the front of __v and swaps the buffers of
842*700637cbSDimitry Andric// *this and __v. It is assumed that __v provides space for exactly (__end_ - __begin_) objects in the front. This
843*700637cbSDimitry Andric// function has a strong exception guarantee.
844*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
845*700637cbSDimitry Andricvoid vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v) {
846*700637cbSDimitry Andric  __annotate_delete();
847*700637cbSDimitry Andric  auto __new_begin = __v.__begin_ - (__end_ - __begin_);
848*700637cbSDimitry Andric  std::__uninitialized_allocator_relocate(
849*700637cbSDimitry Andric      __alloc(), std::__to_address(__begin_), std::__to_address(__end_), std::__to_address(__new_begin));
850*700637cbSDimitry Andric  __v.__begin_ = __new_begin;
851*700637cbSDimitry Andric  __end_       = __begin_; // All the objects have been destroyed by relocating them.
852*700637cbSDimitry Andric  std::swap(this->__begin_, __v.__begin_);
853*700637cbSDimitry Andric  std::swap(this->__end_, __v.__end_);
854*700637cbSDimitry Andric  std::swap(this->__end_cap(), __v.__end_cap());
855*700637cbSDimitry Andric  __v.__first_ = __v.__begin_;
856*700637cbSDimitry Andric  __annotate_new(size());
857*700637cbSDimitry Andric}
858*700637cbSDimitry Andric
859*700637cbSDimitry Andric// __swap_out_circular_buffer relocates the objects in [__begin_, __p) into the front of __v, the objects in
860*700637cbSDimitry Andric// [__p, __end_) into the back of __v and swaps the buffers of *this and __v. It is assumed that __v provides space for
861*700637cbSDimitry Andric// exactly (__p - __begin_) objects in the front and space for at least (__end_ - __p) objects in the back. This
862*700637cbSDimitry Andric// function has a strong exception guarantee if __begin_ == __p || __end_ == __p.
863*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
864*700637cbSDimitry Andrictypename vector<_Tp, _Allocator>::pointer
865*700637cbSDimitry Andricvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p) {
866*700637cbSDimitry Andric  __annotate_delete();
867*700637cbSDimitry Andric  pointer __ret = __v.__begin_;
868*700637cbSDimitry Andric
869*700637cbSDimitry Andric  // Relocate [__p, __end_) first to avoid having a hole in [__begin_, __end_)
870*700637cbSDimitry Andric  // in case something in [__begin_, __p) throws.
871*700637cbSDimitry Andric  std::__uninitialized_allocator_relocate(
872*700637cbSDimitry Andric      __alloc(), std::__to_address(__p), std::__to_address(__end_), std::__to_address(__v.__end_));
873*700637cbSDimitry Andric  __v.__end_ += (__end_ - __p);
874*700637cbSDimitry Andric  __end_           = __p; // The objects in [__p, __end_) have been destroyed by relocating them.
875*700637cbSDimitry Andric  auto __new_begin = __v.__begin_ - (__p - __begin_);
876*700637cbSDimitry Andric
877*700637cbSDimitry Andric  std::__uninitialized_allocator_relocate(
878*700637cbSDimitry Andric      __alloc(), std::__to_address(__begin_), std::__to_address(__p), std::__to_address(__new_begin));
879*700637cbSDimitry Andric  __v.__begin_ = __new_begin;
880*700637cbSDimitry Andric  __end_       = __begin_; // All the objects have been destroyed by relocating them.
881*700637cbSDimitry Andric
882*700637cbSDimitry Andric  std::swap(this->__begin_, __v.__begin_);
883*700637cbSDimitry Andric  std::swap(this->__end_, __v.__end_);
884*700637cbSDimitry Andric  std::swap(this->__end_cap(), __v.__end_cap());
885*700637cbSDimitry Andric  __v.__first_ = __v.__begin_;
886*700637cbSDimitry Andric  __annotate_new(size());
887*700637cbSDimitry Andric  return __ret;
888*700637cbSDimitry Andric}
889*700637cbSDimitry Andric
890*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
891*700637cbSDimitry Andricvoid vector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT {
892*700637cbSDimitry Andric  if (this->__begin_ != nullptr) {
893*700637cbSDimitry Andric    clear();
894*700637cbSDimitry Andric    __annotate_delete();
895*700637cbSDimitry Andric    __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
896*700637cbSDimitry Andric    this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
897*700637cbSDimitry Andric  }
898*700637cbSDimitry Andric}
899*700637cbSDimitry Andric
900*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
901*700637cbSDimitry Andrictypename vector<_Tp, _Allocator>::size_type vector<_Tp, _Allocator>::max_size() const _NOEXCEPT {
902*700637cbSDimitry Andric  return std::min<size_type>(__alloc_traits::max_size(this->__alloc()), numeric_limits<difference_type>::max());
903*700637cbSDimitry Andric}
904*700637cbSDimitry Andric
905*700637cbSDimitry Andric//  Precondition:  __new_size > capacity()
906*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
907*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
908*700637cbSDimitry Andricvector<_Tp, _Allocator>::__recommend(size_type __new_size) const {
909*700637cbSDimitry Andric  const size_type __ms = max_size();
910*700637cbSDimitry Andric  if (__new_size > __ms)
911*700637cbSDimitry Andric    this->__throw_length_error();
912*700637cbSDimitry Andric  const size_type __cap = capacity();
913*700637cbSDimitry Andric  if (__cap >= __ms / 2)
914*700637cbSDimitry Andric    return __ms;
915*700637cbSDimitry Andric  return std::max<size_type>(2 * __cap, __new_size);
916*700637cbSDimitry Andric}
917*700637cbSDimitry Andric
918*700637cbSDimitry Andric//  Default constructs __n objects starting at __end_
919*700637cbSDimitry Andric//  throws if construction throws
920*700637cbSDimitry Andric//  Precondition:  __n > 0
921*700637cbSDimitry Andric//  Precondition:  size() + __n <= capacity()
922*700637cbSDimitry Andric//  Postcondition:  size() == size() + __n
923*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
924*700637cbSDimitry Andricvoid vector<_Tp, _Allocator>::__construct_at_end(size_type __n) {
925*700637cbSDimitry Andric  _ConstructTransaction __tx(*this, __n);
926*700637cbSDimitry Andric  const_pointer __new_end = __tx.__new_end_;
927*700637cbSDimitry Andric  for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
928*700637cbSDimitry Andric    __alloc_traits::construct(this->__alloc(), std::__to_address(__pos));
929*700637cbSDimitry Andric  }
930*700637cbSDimitry Andric}
931*700637cbSDimitry Andric
932*700637cbSDimitry Andric//  Copy constructs __n objects starting at __end_ from __x
933*700637cbSDimitry Andric//  throws if construction throws
934*700637cbSDimitry Andric//  Precondition:  __n > 0
935*700637cbSDimitry Andric//  Precondition:  size() + __n <= capacity()
936*700637cbSDimitry Andric//  Postcondition:  size() == old size() + __n
937*700637cbSDimitry Andric//  Postcondition:  [i] == __x for all i in [size() - __n, __n)
938*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
939*700637cbSDimitry Andricinline void vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) {
940*700637cbSDimitry Andric  _ConstructTransaction __tx(*this, __n);
941*700637cbSDimitry Andric  const_pointer __new_end = __tx.__new_end_;
942*700637cbSDimitry Andric  for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) {
943*700637cbSDimitry Andric    __alloc_traits::construct(this->__alloc(), std::__to_address(__pos), __x);
944*700637cbSDimitry Andric  }
945*700637cbSDimitry Andric}
946*700637cbSDimitry Andric
947*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
948*700637cbSDimitry Andrictemplate <class _InputIterator, class _Sentinel>
949*700637cbSDimitry Andricvoid vector<_Tp, _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) {
950*700637cbSDimitry Andric  _ConstructTransaction __tx(*this, __n);
951*700637cbSDimitry Andric  __tx.__pos_ = std::__uninitialized_allocator_copy(__alloc(), __first, __last, __tx.__pos_);
952*700637cbSDimitry Andric}
953*700637cbSDimitry Andric
954*700637cbSDimitry Andric//  Default constructs __n objects starting at __end_
955*700637cbSDimitry Andric//  throws if construction throws
956*700637cbSDimitry Andric//  Postcondition:  size() == size() + __n
957*700637cbSDimitry Andric//  Exception safety: strong.
958*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
959*700637cbSDimitry Andricvoid vector<_Tp, _Allocator>::__append(size_type __n) {
960*700637cbSDimitry Andric  if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
961*700637cbSDimitry Andric    this->__construct_at_end(__n);
962*700637cbSDimitry Andric  else {
963*700637cbSDimitry Andric    allocator_type& __a = this->__alloc();
964*700637cbSDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
965*700637cbSDimitry Andric    __v.__construct_at_end(__n);
966*700637cbSDimitry Andric    __swap_out_circular_buffer(__v);
967*700637cbSDimitry Andric  }
968*700637cbSDimitry Andric}
969*700637cbSDimitry Andric
970*700637cbSDimitry Andric//  Default constructs __n objects starting at __end_
971*700637cbSDimitry Andric//  throws if construction throws
972*700637cbSDimitry Andric//  Postcondition:  size() == size() + __n
973*700637cbSDimitry Andric//  Exception safety: strong.
974*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
975*700637cbSDimitry Andricvoid vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x) {
976*700637cbSDimitry Andric  if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
977*700637cbSDimitry Andric    this->__construct_at_end(__n, __x);
978*700637cbSDimitry Andric  else {
979*700637cbSDimitry Andric    allocator_type& __a = this->__alloc();
980*700637cbSDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
981*700637cbSDimitry Andric    __v.__construct_at_end(__n, __x);
982*700637cbSDimitry Andric    __swap_out_circular_buffer(__v);
983*700637cbSDimitry Andric  }
984*700637cbSDimitry Andric}
985*700637cbSDimitry Andric
986*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
987*700637cbSDimitry Andrictemplate <class _InputIterator,
988*700637cbSDimitry Andric          __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
989*700637cbSDimitry Andric                            is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
990*700637cbSDimitry Andric                        int> >
991*700637cbSDimitry Andricvector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last) {
992*700637cbSDimitry Andric  __init_with_sentinel(__first, __last);
993*700637cbSDimitry Andric}
994*700637cbSDimitry Andric
995*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
996*700637cbSDimitry Andrictemplate <class _InputIterator,
997*700637cbSDimitry Andric          __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
998*700637cbSDimitry Andric                            is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
999*700637cbSDimitry Andric                        int> >
1000*700637cbSDimitry Andricvector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a)
1001*700637cbSDimitry Andric    : __end_cap_(nullptr, __a) {
1002*700637cbSDimitry Andric  __init_with_sentinel(__first, __last);
1003*700637cbSDimitry Andric}
1004*700637cbSDimitry Andric
1005*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1006*700637cbSDimitry Andrictemplate <class _ForwardIterator,
1007*700637cbSDimitry Andric          __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
1008*700637cbSDimitry Andric                            is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
1009*700637cbSDimitry Andric                        int> >
1010*700637cbSDimitry Andricvector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last) {
1011*700637cbSDimitry Andric  size_type __n = static_cast<size_type>(std::distance(__first, __last));
1012*700637cbSDimitry Andric  __init_with_size(__first, __last, __n);
1013*700637cbSDimitry Andric}
1014*700637cbSDimitry Andric
1015*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1016*700637cbSDimitry Andrictemplate <class _ForwardIterator,
1017*700637cbSDimitry Andric          __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
1018*700637cbSDimitry Andric                            is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
1019*700637cbSDimitry Andric                        int> >
1020*700637cbSDimitry Andricvector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a)
1021*700637cbSDimitry Andric    : __end_cap_(nullptr, __a) {
1022*700637cbSDimitry Andric  size_type __n = static_cast<size_type>(std::distance(__first, __last));
1023*700637cbSDimitry Andric  __init_with_size(__first, __last, __n);
1024*700637cbSDimitry Andric}
1025*700637cbSDimitry Andric
1026*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1027*700637cbSDimitry Andricvector<_Tp, _Allocator>::vector(const vector& __x)
1028*700637cbSDimitry Andric    : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc())) {
1029*700637cbSDimitry Andric  __init_with_size(__x.__begin_, __x.__end_, __x.size());
1030*700637cbSDimitry Andric}
1031*700637cbSDimitry Andric
1032*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1033*700637cbSDimitry Andricvector<_Tp, _Allocator>::vector(const vector& __x, const __type_identity_t<allocator_type>& __a)
1034*700637cbSDimitry Andric    : __end_cap_(nullptr, __a) {
1035*700637cbSDimitry Andric  __init_with_size(__x.__begin_, __x.__end_, __x.size());
1036*700637cbSDimitry Andric}
1037*700637cbSDimitry Andric
1038*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1039*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>::vector(vector&& __x)
1040*700637cbSDimitry Andric    : __end_cap_(nullptr, std::move(__x.__alloc())) {
1041*700637cbSDimitry Andric  this->__begin_    = __x.__begin_;
1042*700637cbSDimitry Andric  this->__end_      = __x.__end_;
1043*700637cbSDimitry Andric  this->__end_cap() = __x.__end_cap();
1044*700637cbSDimitry Andric  __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1045*700637cbSDimitry Andric}
1046*700637cbSDimitry Andric
1047*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1048*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>::vector(vector&& __x, const __type_identity_t<allocator_type>& __a)
1049*700637cbSDimitry Andric    : __end_cap_(nullptr, __a) {
1050*700637cbSDimitry Andric  if (__a == __x.__alloc()) {
1051*700637cbSDimitry Andric    this->__begin_    = __x.__begin_;
1052*700637cbSDimitry Andric    this->__end_      = __x.__end_;
1053*700637cbSDimitry Andric    this->__end_cap() = __x.__end_cap();
1054*700637cbSDimitry Andric    __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1055*700637cbSDimitry Andric  } else {
1056*700637cbSDimitry Andric    typedef move_iterator<iterator> _Ip;
1057*700637cbSDimitry Andric    auto __guard = std::__make_exception_guard(__destroy_vector(*this));
1058*700637cbSDimitry Andric    assign(_Ip(__x.begin()), _Ip(__x.end()));
1059*700637cbSDimitry Andric    __guard.__complete();
1060*700637cbSDimitry Andric  }
1061*700637cbSDimitry Andric}
1062*700637cbSDimitry Andric
1063*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1064*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>& vector<_Tp, _Allocator>::operator=(vector&& __x) {
1065*700637cbSDimitry Andric  __move_assign(__x, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>());
1066*700637cbSDimitry Andric  return *this;
1067*700637cbSDimitry Andric}
1068*700637cbSDimitry Andric
1069*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1070*700637cbSDimitry Andricvoid vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type) {
1071*700637cbSDimitry Andric  if (__alloc() != __c.__alloc()) {
1072*700637cbSDimitry Andric    typedef move_iterator<iterator> _Ip;
1073*700637cbSDimitry Andric    assign(_Ip(__c.begin()), _Ip(__c.end()));
1074*700637cbSDimitry Andric  } else
1075*700637cbSDimitry Andric    __move_assign(__c, true_type());
1076*700637cbSDimitry Andric}
1077*700637cbSDimitry Andric
1078*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1079*700637cbSDimitry Andricvoid vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type) {
1080*700637cbSDimitry Andric  __vdeallocate();
1081*700637cbSDimitry Andric  __move_assign_alloc(__c); // this can throw
1082*700637cbSDimitry Andric  this->__begin_    = __c.__begin_;
1083*700637cbSDimitry Andric  this->__end_      = __c.__end_;
1084*700637cbSDimitry Andric  this->__end_cap() = __c.__end_cap();
1085*700637cbSDimitry Andric  __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
1086*700637cbSDimitry Andric}
1087*700637cbSDimitry Andric
1088*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1089*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI vector<_Tp, _Allocator>& vector<_Tp, _Allocator>::operator=(const vector& __x) {
1090*700637cbSDimitry Andric  if (this != std::addressof(__x)) {
1091*700637cbSDimitry Andric    __copy_assign_alloc(__x);
1092*700637cbSDimitry Andric    assign(__x.__begin_, __x.__end_);
1093*700637cbSDimitry Andric  }
1094*700637cbSDimitry Andric  return *this;
1095*700637cbSDimitry Andric}
1096*700637cbSDimitry Andric
1097*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1098*700637cbSDimitry Andrictemplate <class _InputIterator,
1099*700637cbSDimitry Andric          __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
1100*700637cbSDimitry Andric                            is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
1101*700637cbSDimitry Andric                        int> >
1102*700637cbSDimitry Andricvoid vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last) {
1103*700637cbSDimitry Andric  __assign_with_sentinel(__first, __last);
1104*700637cbSDimitry Andric}
1105*700637cbSDimitry Andric
1106*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1107*700637cbSDimitry Andrictemplate <class _Iterator, class _Sentinel>
1108*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI void vector<_Tp, _Allocator>::__assign_with_sentinel(_Iterator __first, _Sentinel __last) {
1109*700637cbSDimitry Andric  clear();
1110*700637cbSDimitry Andric  for (; __first != __last; ++__first)
1111*700637cbSDimitry Andric    emplace_back(*__first);
1112*700637cbSDimitry Andric}
1113*700637cbSDimitry Andric
1114*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1115*700637cbSDimitry Andrictemplate <class _ForwardIterator,
1116*700637cbSDimitry Andric          __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
1117*700637cbSDimitry Andric                            is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
1118*700637cbSDimitry Andric                        int> >
1119*700637cbSDimitry Andricvoid vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) {
1120*700637cbSDimitry Andric  __assign_with_size(__first, __last, std::distance(__first, __last));
1121*700637cbSDimitry Andric}
1122*700637cbSDimitry Andric
1123*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1124*700637cbSDimitry Andrictemplate <class _ForwardIterator, class _Sentinel>
1125*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI void
1126*700637cbSDimitry Andricvector<_Tp, _Allocator>::__assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __n) {
1127*700637cbSDimitry Andric  size_type __new_size = static_cast<size_type>(__n);
1128*700637cbSDimitry Andric  if (__new_size <= capacity()) {
1129*700637cbSDimitry Andric    if (__new_size > size()) {
1130*700637cbSDimitry Andric      _ForwardIterator __mid = std::next(__first, size());
1131*700637cbSDimitry Andric      std::copy(__first, __mid, this->__begin_);
1132*700637cbSDimitry Andric      __construct_at_end(__mid, __last, __new_size - size());
1133*700637cbSDimitry Andric    } else {
1134*700637cbSDimitry Andric      pointer __m = std::__copy<_ClassicAlgPolicy>(__first, __last, this->__begin_).second;
1135*700637cbSDimitry Andric      this->__destruct_at_end(__m);
1136*700637cbSDimitry Andric    }
1137*700637cbSDimitry Andric  } else {
1138*700637cbSDimitry Andric    __vdeallocate();
1139*700637cbSDimitry Andric    __vallocate(__recommend(__new_size));
1140*700637cbSDimitry Andric    __construct_at_end(__first, __last, __new_size);
1141*700637cbSDimitry Andric  }
1142*700637cbSDimitry Andric}
1143*700637cbSDimitry Andric
1144*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1145*700637cbSDimitry Andricvoid vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u) {
1146*700637cbSDimitry Andric  if (__n <= capacity()) {
1147*700637cbSDimitry Andric    size_type __s = size();
1148*700637cbSDimitry Andric    std::fill_n(this->__begin_, std::min(__n, __s), __u);
1149*700637cbSDimitry Andric    if (__n > __s)
1150*700637cbSDimitry Andric      __construct_at_end(__n - __s, __u);
1151*700637cbSDimitry Andric    else
1152*700637cbSDimitry Andric      this->__destruct_at_end(this->__begin_ + __n);
1153*700637cbSDimitry Andric  } else {
1154*700637cbSDimitry Andric    __vdeallocate();
1155*700637cbSDimitry Andric    __vallocate(__recommend(static_cast<size_type>(__n)));
1156*700637cbSDimitry Andric    __construct_at_end(__n, __u);
1157*700637cbSDimitry Andric  }
1158*700637cbSDimitry Andric}
1159*700637cbSDimitry Andric
1160*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1161*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator vector<_Tp, _Allocator>::begin() _NOEXCEPT {
1162*700637cbSDimitry Andric  return __make_iter(this->__begin_);
1163*700637cbSDimitry Andric}
1164*700637cbSDimitry Andric
1165*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1166*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::const_iterator
1167*700637cbSDimitry Andricvector<_Tp, _Allocator>::begin() const _NOEXCEPT {
1168*700637cbSDimitry Andric  return __make_iter(this->__begin_);
1169*700637cbSDimitry Andric}
1170*700637cbSDimitry Andric
1171*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1172*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator vector<_Tp, _Allocator>::end() _NOEXCEPT {
1173*700637cbSDimitry Andric  return __make_iter(this->__end_);
1174*700637cbSDimitry Andric}
1175*700637cbSDimitry Andric
1176*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1177*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::const_iterator
1178*700637cbSDimitry Andricvector<_Tp, _Allocator>::end() const _NOEXCEPT {
1179*700637cbSDimitry Andric  return __make_iter(this->__end_);
1180*700637cbSDimitry Andric}
1181*700637cbSDimitry Andric
1182*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1183*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::reference
1184*700637cbSDimitry Andricvector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT {
1185*700637cbSDimitry Andric  _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < size(), "vector[] index out of bounds");
1186*700637cbSDimitry Andric  return this->__begin_[__n];
1187*700637cbSDimitry Andric}
1188*700637cbSDimitry Andric
1189*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1190*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::const_reference
1191*700637cbSDimitry Andricvector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT {
1192*700637cbSDimitry Andric  _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n < size(), "vector[] index out of bounds");
1193*700637cbSDimitry Andric  return this->__begin_[__n];
1194*700637cbSDimitry Andric}
1195*700637cbSDimitry Andric
1196*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1197*700637cbSDimitry Andrictypename vector<_Tp, _Allocator>::reference vector<_Tp, _Allocator>::at(size_type __n) {
1198*700637cbSDimitry Andric  if (__n >= size())
1199*700637cbSDimitry Andric    this->__throw_out_of_range();
1200*700637cbSDimitry Andric  return this->__begin_[__n];
1201*700637cbSDimitry Andric}
1202*700637cbSDimitry Andric
1203*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1204*700637cbSDimitry Andrictypename vector<_Tp, _Allocator>::const_reference vector<_Tp, _Allocator>::at(size_type __n) const {
1205*700637cbSDimitry Andric  if (__n >= size())
1206*700637cbSDimitry Andric    this->__throw_out_of_range();
1207*700637cbSDimitry Andric  return this->__begin_[__n];
1208*700637cbSDimitry Andric}
1209*700637cbSDimitry Andric
1210*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1211*700637cbSDimitry Andricvoid vector<_Tp, _Allocator>::reserve(size_type __n) {
1212*700637cbSDimitry Andric  if (__n > capacity()) {
1213*700637cbSDimitry Andric    if (__n > max_size())
1214*700637cbSDimitry Andric      this->__throw_length_error();
1215*700637cbSDimitry Andric    allocator_type& __a = this->__alloc();
1216*700637cbSDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
1217*700637cbSDimitry Andric    __swap_out_circular_buffer(__v);
1218*700637cbSDimitry Andric  }
1219*700637cbSDimitry Andric}
1220*700637cbSDimitry Andric
1221*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1222*700637cbSDimitry Andricvoid vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT {
1223*700637cbSDimitry Andric  if (capacity() > size()) {
1224*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1225*700637cbSDimitry Andric    try {
1226*700637cbSDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1227*700637cbSDimitry Andric      allocator_type& __a = this->__alloc();
1228*700637cbSDimitry Andric      __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
1229*700637cbSDimitry Andric      // The Standard mandates shrink_to_fit() does not increase the capacity.
1230*700637cbSDimitry Andric      // With equal capacity keep the existing buffer. This avoids extra work
1231*700637cbSDimitry Andric      // due to swapping the elements.
1232*700637cbSDimitry Andric      if (__v.capacity() < capacity())
1233*700637cbSDimitry Andric        __swap_out_circular_buffer(__v);
1234*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1235*700637cbSDimitry Andric    } catch (...) {
1236*700637cbSDimitry Andric    }
1237*700637cbSDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1238*700637cbSDimitry Andric  }
1239*700637cbSDimitry Andric}
1240*700637cbSDimitry Andric
1241*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1242*700637cbSDimitry Andrictemplate <class _Up>
1243*700637cbSDimitry Andrictypename vector<_Tp, _Allocator>::pointer vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x) {
1244*700637cbSDimitry Andric  allocator_type& __a = this->__alloc();
1245*700637cbSDimitry Andric  __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1246*700637cbSDimitry Andric  // __v.push_back(std::forward<_Up>(__x));
1247*700637cbSDimitry Andric  __alloc_traits::construct(__a, std::__to_address(__v.__end_), std::forward<_Up>(__x));
1248*700637cbSDimitry Andric  __v.__end_++;
1249*700637cbSDimitry Andric  __swap_out_circular_buffer(__v);
1250*700637cbSDimitry Andric  return this->__end_;
1251*700637cbSDimitry Andric}
1252*700637cbSDimitry Andric
1253*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1254*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void vector<_Tp, _Allocator>::push_back(const_reference __x) {
1255*700637cbSDimitry Andric  pointer __end = this->__end_;
1256*700637cbSDimitry Andric  if (__end < this->__end_cap()) {
1257*700637cbSDimitry Andric    __construct_one_at_end(__x);
1258*700637cbSDimitry Andric    ++__end;
1259*700637cbSDimitry Andric  } else {
1260*700637cbSDimitry Andric    __end = __push_back_slow_path(__x);
1261*700637cbSDimitry Andric  }
1262*700637cbSDimitry Andric  this->__end_ = __end;
1263*700637cbSDimitry Andric}
1264*700637cbSDimitry Andric
1265*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1266*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void vector<_Tp, _Allocator>::push_back(value_type&& __x) {
1267*700637cbSDimitry Andric  pointer __end = this->__end_;
1268*700637cbSDimitry Andric  if (__end < this->__end_cap()) {
1269*700637cbSDimitry Andric    __construct_one_at_end(std::move(__x));
1270*700637cbSDimitry Andric    ++__end;
1271*700637cbSDimitry Andric  } else {
1272*700637cbSDimitry Andric    __end = __push_back_slow_path(std::move(__x));
1273*700637cbSDimitry Andric  }
1274*700637cbSDimitry Andric  this->__end_ = __end;
1275*700637cbSDimitry Andric}
1276*700637cbSDimitry Andric
1277*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1278*700637cbSDimitry Andrictemplate <class... _Args>
1279*700637cbSDimitry Andrictypename vector<_Tp, _Allocator>::pointer vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args) {
1280*700637cbSDimitry Andric  allocator_type& __a = this->__alloc();
1281*700637cbSDimitry Andric  __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1282*700637cbSDimitry Andric  //    __v.emplace_back(std::forward<_Args>(__args)...);
1283*700637cbSDimitry Andric  __alloc_traits::construct(__a, std::__to_address(__v.__end_), std::forward<_Args>(__args)...);
1284*700637cbSDimitry Andric  __v.__end_++;
1285*700637cbSDimitry Andric  __swap_out_circular_buffer(__v);
1286*700637cbSDimitry Andric  return this->__end_;
1287*700637cbSDimitry Andric}
1288*700637cbSDimitry Andric
1289*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1290*700637cbSDimitry Andrictemplate <class... _Args>
1291*700637cbSDimitry Andricinline void vector<_Tp, _Allocator>::emplace_back(_Args&&... __args) {
1292*700637cbSDimitry Andric  pointer __end = this->__end_;
1293*700637cbSDimitry Andric  if (__end < this->__end_cap()) {
1294*700637cbSDimitry Andric    __construct_one_at_end(std::forward<_Args>(__args)...);
1295*700637cbSDimitry Andric    ++__end;
1296*700637cbSDimitry Andric  } else {
1297*700637cbSDimitry Andric    __end = __emplace_back_slow_path(std::forward<_Args>(__args)...);
1298*700637cbSDimitry Andric  }
1299*700637cbSDimitry Andric  this->__end_ = __end;
1300*700637cbSDimitry Andric}
1301*700637cbSDimitry Andric
1302*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1303*700637cbSDimitry Andricinline void vector<_Tp, _Allocator>::pop_back() {
1304*700637cbSDimitry Andric  _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "vector::pop_back called on an empty vector");
1305*700637cbSDimitry Andric  this->__destruct_at_end(this->__end_ - 1);
1306*700637cbSDimitry Andric}
1307*700637cbSDimitry Andric
1308*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1309*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator
1310*700637cbSDimitry Andricvector<_Tp, _Allocator>::erase(const_iterator __position) {
1311*700637cbSDimitry Andric  _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
1312*700637cbSDimitry Andric      __position != end(), "vector::erase(iterator) called with a non-dereferenceable iterator");
1313*700637cbSDimitry Andric  difference_type __ps = __position - cbegin();
1314*700637cbSDimitry Andric  pointer __p          = this->__begin_ + __ps;
1315*700637cbSDimitry Andric  this->__destruct_at_end(std::move(__p + 1, this->__end_, __p));
1316*700637cbSDimitry Andric  return __make_iter(__p);
1317*700637cbSDimitry Andric}
1318*700637cbSDimitry Andric
1319*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1320*700637cbSDimitry Andrictypename vector<_Tp, _Allocator>::iterator
1321*700637cbSDimitry Andricvector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) {
1322*700637cbSDimitry Andric  _LIBCPP_ASSERT_VALID_INPUT_RANGE(__first <= __last, "vector::erase(first, last) called with invalid range");
1323*700637cbSDimitry Andric  pointer __p = this->__begin_ + (__first - begin());
1324*700637cbSDimitry Andric  if (__first != __last) {
1325*700637cbSDimitry Andric    this->__destruct_at_end(std::move(__p + (__last - __first), this->__end_, __p));
1326*700637cbSDimitry Andric  }
1327*700637cbSDimitry Andric  return __make_iter(__p);
1328*700637cbSDimitry Andric}
1329*700637cbSDimitry Andric
1330*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1331*700637cbSDimitry Andricvoid vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to) {
1332*700637cbSDimitry Andric  pointer __old_last  = this->__end_;
1333*700637cbSDimitry Andric  difference_type __n = __old_last - __to;
1334*700637cbSDimitry Andric  {
1335*700637cbSDimitry Andric    pointer __i = __from_s + __n;
1336*700637cbSDimitry Andric    _ConstructTransaction __tx(*this, __from_e - __i);
1337*700637cbSDimitry Andric    for (pointer __pos = __tx.__pos_; __i < __from_e; ++__i, (void)++__pos, __tx.__pos_ = __pos) {
1338*700637cbSDimitry Andric      __alloc_traits::construct(this->__alloc(), std::__to_address(__pos), std::move(*__i));
1339*700637cbSDimitry Andric    }
1340*700637cbSDimitry Andric  }
1341*700637cbSDimitry Andric  std::move_backward(__from_s, __from_s + __n, __old_last);
1342*700637cbSDimitry Andric}
1343*700637cbSDimitry Andric
1344*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1345*700637cbSDimitry Andrictypename vector<_Tp, _Allocator>::iterator
1346*700637cbSDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) {
1347*700637cbSDimitry Andric  pointer __p = this->__begin_ + (__position - begin());
1348*700637cbSDimitry Andric  if (this->__end_ < this->__end_cap()) {
1349*700637cbSDimitry Andric    if (__p == this->__end_) {
1350*700637cbSDimitry Andric      __construct_one_at_end(__x);
1351*700637cbSDimitry Andric    } else {
1352*700637cbSDimitry Andric      __move_range(__p, this->__end_, __p + 1);
1353*700637cbSDimitry Andric      const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1354*700637cbSDimitry Andric      if (std::__is_pointer_in_range(std::__to_address(__p), std::__to_address(__end_), std::addressof(__x)))
1355*700637cbSDimitry Andric        ++__xr;
1356*700637cbSDimitry Andric      *__p = *__xr;
1357*700637cbSDimitry Andric    }
1358*700637cbSDimitry Andric  } else {
1359*700637cbSDimitry Andric    allocator_type& __a = this->__alloc();
1360*700637cbSDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1361*700637cbSDimitry Andric    __v.push_back(__x);
1362*700637cbSDimitry Andric    __p = __swap_out_circular_buffer(__v, __p);
1363*700637cbSDimitry Andric  }
1364*700637cbSDimitry Andric  return __make_iter(__p);
1365*700637cbSDimitry Andric}
1366*700637cbSDimitry Andric
1367*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1368*700637cbSDimitry Andrictypename vector<_Tp, _Allocator>::iterator
1369*700637cbSDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) {
1370*700637cbSDimitry Andric  pointer __p = this->__begin_ + (__position - begin());
1371*700637cbSDimitry Andric  if (this->__end_ < this->__end_cap()) {
1372*700637cbSDimitry Andric    if (__p == this->__end_) {
1373*700637cbSDimitry Andric      __construct_one_at_end(std::move(__x));
1374*700637cbSDimitry Andric    } else {
1375*700637cbSDimitry Andric      __move_range(__p, this->__end_, __p + 1);
1376*700637cbSDimitry Andric      *__p = std::move(__x);
1377*700637cbSDimitry Andric    }
1378*700637cbSDimitry Andric  } else {
1379*700637cbSDimitry Andric    allocator_type& __a = this->__alloc();
1380*700637cbSDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1381*700637cbSDimitry Andric    __v.push_back(std::move(__x));
1382*700637cbSDimitry Andric    __p = __swap_out_circular_buffer(__v, __p);
1383*700637cbSDimitry Andric  }
1384*700637cbSDimitry Andric  return __make_iter(__p);
1385*700637cbSDimitry Andric}
1386*700637cbSDimitry Andric
1387*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1388*700637cbSDimitry Andrictemplate <class... _Args>
1389*700637cbSDimitry Andrictypename vector<_Tp, _Allocator>::iterator
1390*700637cbSDimitry Andricvector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) {
1391*700637cbSDimitry Andric  pointer __p = this->__begin_ + (__position - begin());
1392*700637cbSDimitry Andric  if (this->__end_ < this->__end_cap()) {
1393*700637cbSDimitry Andric    if (__p == this->__end_) {
1394*700637cbSDimitry Andric      __construct_one_at_end(std::forward<_Args>(__args)...);
1395*700637cbSDimitry Andric    } else {
1396*700637cbSDimitry Andric      __temp_value<value_type, _Allocator> __tmp(this->__alloc(), std::forward<_Args>(__args)...);
1397*700637cbSDimitry Andric      __move_range(__p, this->__end_, __p + 1);
1398*700637cbSDimitry Andric      *__p = std::move(__tmp.get());
1399*700637cbSDimitry Andric    }
1400*700637cbSDimitry Andric  } else {
1401*700637cbSDimitry Andric    allocator_type& __a = this->__alloc();
1402*700637cbSDimitry Andric    __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1403*700637cbSDimitry Andric    __v.emplace_back(std::forward<_Args>(__args)...);
1404*700637cbSDimitry Andric    __p = __swap_out_circular_buffer(__v, __p);
1405*700637cbSDimitry Andric  }
1406*700637cbSDimitry Andric  return __make_iter(__p);
1407*700637cbSDimitry Andric}
1408*700637cbSDimitry Andric
1409*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1410*700637cbSDimitry Andrictypename vector<_Tp, _Allocator>::iterator
1411*700637cbSDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x) {
1412*700637cbSDimitry Andric  pointer __p = this->__begin_ + (__position - begin());
1413*700637cbSDimitry Andric  if (__n > 0) {
1414*700637cbSDimitry Andric    // We can't compare unrelated pointers inside constant expressions
1415*700637cbSDimitry Andric    if (!__libcpp_is_constant_evaluated() && __n <= static_cast<size_type>(this->__end_cap() - this->__end_)) {
1416*700637cbSDimitry Andric      size_type __old_n  = __n;
1417*700637cbSDimitry Andric      pointer __old_last = this->__end_;
1418*700637cbSDimitry Andric      if (__n > static_cast<size_type>(this->__end_ - __p)) {
1419*700637cbSDimitry Andric        size_type __cx = __n - (this->__end_ - __p);
1420*700637cbSDimitry Andric        __construct_at_end(__cx, __x);
1421*700637cbSDimitry Andric        __n -= __cx;
1422*700637cbSDimitry Andric      }
1423*700637cbSDimitry Andric      if (__n > 0) {
1424*700637cbSDimitry Andric        __move_range(__p, __old_last, __p + __old_n);
1425*700637cbSDimitry Andric        const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1426*700637cbSDimitry Andric        if (__p <= __xr && __xr < this->__end_)
1427*700637cbSDimitry Andric          __xr += __old_n;
1428*700637cbSDimitry Andric        std::fill_n(__p, __n, *__xr);
1429*700637cbSDimitry Andric      }
1430*700637cbSDimitry Andric    } else {
1431*700637cbSDimitry Andric      allocator_type& __a = this->__alloc();
1432*700637cbSDimitry Andric      __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1433*700637cbSDimitry Andric      __v.__construct_at_end(__n, __x);
1434*700637cbSDimitry Andric      __p = __swap_out_circular_buffer(__v, __p);
1435*700637cbSDimitry Andric    }
1436*700637cbSDimitry Andric  }
1437*700637cbSDimitry Andric  return __make_iter(__p);
1438*700637cbSDimitry Andric}
1439*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1440*700637cbSDimitry Andrictemplate <class _InputIterator,
1441*700637cbSDimitry Andric          __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value &&
1442*700637cbSDimitry Andric                            is_constructible<_Tp, typename iterator_traits<_InputIterator>::reference>::value,
1443*700637cbSDimitry Andric                        int> >
1444*700637cbSDimitry Andrictypename vector<_Tp, _Allocator>::iterator
1445*700637cbSDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) {
1446*700637cbSDimitry Andric  return __insert_with_sentinel(__position, __first, __last);
1447*700637cbSDimitry Andric}
1448*700637cbSDimitry Andric
1449*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1450*700637cbSDimitry Andrictemplate <class _InputIterator, class _Sentinel>
1451*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator
1452*700637cbSDimitry Andricvector<_Tp, _Allocator>::__insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last) {
1453*700637cbSDimitry Andric  difference_type __off = __position - begin();
1454*700637cbSDimitry Andric  pointer __p           = this->__begin_ + __off;
1455*700637cbSDimitry Andric  allocator_type& __a   = this->__alloc();
1456*700637cbSDimitry Andric  pointer __old_last    = this->__end_;
1457*700637cbSDimitry Andric  for (; this->__end_ != this->__end_cap() && __first != __last; ++__first) {
1458*700637cbSDimitry Andric    __construct_one_at_end(*__first);
1459*700637cbSDimitry Andric  }
1460*700637cbSDimitry Andric  __split_buffer<value_type, allocator_type&> __v(__a);
1461*700637cbSDimitry Andric  if (__first != __last) {
1462*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1463*700637cbSDimitry Andric    try {
1464*700637cbSDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1465*700637cbSDimitry Andric      __v.__construct_at_end_with_sentinel(std::move(__first), std::move(__last));
1466*700637cbSDimitry Andric      difference_type __old_size = __old_last - this->__begin_;
1467*700637cbSDimitry Andric      difference_type __old_p    = __p - this->__begin_;
1468*700637cbSDimitry Andric      reserve(__recommend(size() + __v.size()));
1469*700637cbSDimitry Andric      __p        = this->__begin_ + __old_p;
1470*700637cbSDimitry Andric      __old_last = this->__begin_ + __old_size;
1471*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1472*700637cbSDimitry Andric    } catch (...) {
1473*700637cbSDimitry Andric      erase(__make_iter(__old_last), end());
1474*700637cbSDimitry Andric      throw;
1475*700637cbSDimitry Andric    }
1476*700637cbSDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1477*700637cbSDimitry Andric  }
1478*700637cbSDimitry Andric  __p = std::rotate(__p, __old_last, this->__end_);
1479*700637cbSDimitry Andric  insert(__make_iter(__p), std::make_move_iterator(__v.begin()), std::make_move_iterator(__v.end()));
1480*700637cbSDimitry Andric  return begin() + __off;
1481*700637cbSDimitry Andric}
1482*700637cbSDimitry Andric
1483*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1484*700637cbSDimitry Andrictemplate <class _ForwardIterator,
1485*700637cbSDimitry Andric          __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value &&
1486*700637cbSDimitry Andric                            is_constructible<_Tp, typename iterator_traits<_ForwardIterator>::reference>::value,
1487*700637cbSDimitry Andric                        int> >
1488*700637cbSDimitry Andrictypename vector<_Tp, _Allocator>::iterator
1489*700637cbSDimitry Andricvector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) {
1490*700637cbSDimitry Andric  return __insert_with_size(__position, __first, __last, std::distance(__first, __last));
1491*700637cbSDimitry Andric}
1492*700637cbSDimitry Andric
1493*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1494*700637cbSDimitry Andrictemplate <class _Iterator, class _Sentinel>
1495*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator vector<_Tp, _Allocator>::__insert_with_size(
1496*700637cbSDimitry Andric    const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n) {
1497*700637cbSDimitry Andric  auto __insertion_size = __n;
1498*700637cbSDimitry Andric  pointer __p           = this->__begin_ + (__position - begin());
1499*700637cbSDimitry Andric  if (__n > 0) {
1500*700637cbSDimitry Andric    if (__n <= this->__end_cap() - this->__end_) {
1501*700637cbSDimitry Andric      size_type __old_n    = __n;
1502*700637cbSDimitry Andric      pointer __old_last   = this->__end_;
1503*700637cbSDimitry Andric      _Iterator __m        = std::next(__first, __n);
1504*700637cbSDimitry Andric      difference_type __dx = this->__end_ - __p;
1505*700637cbSDimitry Andric      if (__n > __dx) {
1506*700637cbSDimitry Andric        __m                    = __first;
1507*700637cbSDimitry Andric        difference_type __diff = this->__end_ - __p;
1508*700637cbSDimitry Andric        std::advance(__m, __diff);
1509*700637cbSDimitry Andric        __construct_at_end(__m, __last, __n - __diff);
1510*700637cbSDimitry Andric        __n = __dx;
1511*700637cbSDimitry Andric      }
1512*700637cbSDimitry Andric      if (__n > 0) {
1513*700637cbSDimitry Andric        __move_range(__p, __old_last, __p + __old_n);
1514*700637cbSDimitry Andric        std::copy(__first, __m, __p);
1515*700637cbSDimitry Andric      }
1516*700637cbSDimitry Andric    } else {
1517*700637cbSDimitry Andric      allocator_type& __a = this->__alloc();
1518*700637cbSDimitry Andric      __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1519*700637cbSDimitry Andric      __v.__construct_at_end_with_size(__first, __insertion_size);
1520*700637cbSDimitry Andric      __p = __swap_out_circular_buffer(__v, __p);
1521*700637cbSDimitry Andric    }
1522*700637cbSDimitry Andric  }
1523*700637cbSDimitry Andric  return __make_iter(__p);
1524*700637cbSDimitry Andric}
1525*700637cbSDimitry Andric
1526*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1527*700637cbSDimitry Andricvoid vector<_Tp, _Allocator>::resize(size_type __sz) {
1528*700637cbSDimitry Andric  size_type __cs = size();
1529*700637cbSDimitry Andric  if (__cs < __sz)
1530*700637cbSDimitry Andric    this->__append(__sz - __cs);
1531*700637cbSDimitry Andric  else if (__cs > __sz)
1532*700637cbSDimitry Andric    this->__destruct_at_end(this->__begin_ + __sz);
1533*700637cbSDimitry Andric}
1534*700637cbSDimitry Andric
1535*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1536*700637cbSDimitry Andricvoid vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x) {
1537*700637cbSDimitry Andric  size_type __cs = size();
1538*700637cbSDimitry Andric  if (__cs < __sz)
1539*700637cbSDimitry Andric    this->__append(__sz - __cs, __x);
1540*700637cbSDimitry Andric  else if (__cs > __sz)
1541*700637cbSDimitry Andric    this->__destruct_at_end(this->__begin_ + __sz);
1542*700637cbSDimitry Andric}
1543*700637cbSDimitry Andric
1544*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1545*700637cbSDimitry Andricvoid vector<_Tp, _Allocator>::swap(vector& __x) {
1546*700637cbSDimitry Andric  _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
1547*700637cbSDimitry Andric      __alloc_traits::propagate_on_container_swap::value || this->__alloc() == __x.__alloc(),
1548*700637cbSDimitry Andric      "vector::swap: Either propagate_on_container_swap must be true"
1549*700637cbSDimitry Andric      " or the allocators must compare equal");
1550*700637cbSDimitry Andric  std::swap(this->__begin_, __x.__begin_);
1551*700637cbSDimitry Andric  std::swap(this->__end_, __x.__end_);
1552*700637cbSDimitry Andric  std::swap(this->__end_cap(), __x.__end_cap());
1553*700637cbSDimitry Andric  std::__swap_allocator(
1554*700637cbSDimitry Andric      this->__alloc(), __x.__alloc(), integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
1555*700637cbSDimitry Andric}
1556*700637cbSDimitry Andric
1557*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
1558*700637cbSDimitry Andricbool vector<_Tp, _Allocator>::__invariants() const {
1559*700637cbSDimitry Andric  if (this->__begin_ == nullptr) {
1560*700637cbSDimitry Andric    if (this->__end_ != nullptr || this->__end_cap() != nullptr)
1561*700637cbSDimitry Andric      return false;
1562*700637cbSDimitry Andric  } else {
1563*700637cbSDimitry Andric    if (this->__begin_ > this->__end_)
1564*700637cbSDimitry Andric      return false;
1565*700637cbSDimitry Andric    if (this->__begin_ == this->__end_cap())
1566*700637cbSDimitry Andric      return false;
1567*700637cbSDimitry Andric    if (this->__end_ > this->__end_cap())
1568*700637cbSDimitry Andric      return false;
1569*700637cbSDimitry Andric  }
1570*700637cbSDimitry Andric  return true;
1571*700637cbSDimitry Andric}
1572*700637cbSDimitry Andric
1573*700637cbSDimitry Andric// vector<bool>
1574*700637cbSDimitry Andric
1575*700637cbSDimitry Andrictemplate <class _Allocator>
1576*700637cbSDimitry Andricclass vector<bool, _Allocator>;
1577*700637cbSDimitry Andric
1578*700637cbSDimitry Andrictemplate <class _Allocator>
1579*700637cbSDimitry Andricstruct hash<vector<bool, _Allocator> >;
1580*700637cbSDimitry Andric
1581*700637cbSDimitry Andrictemplate <class _Allocator>
1582*700637cbSDimitry Andricstruct __has_storage_type<vector<bool, _Allocator> > {
1583*700637cbSDimitry Andric  static const bool value = true;
1584*700637cbSDimitry Andric};
1585*700637cbSDimitry Andric
1586*700637cbSDimitry Andrictemplate <class _Allocator>
1587*700637cbSDimitry Andricclass _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> {
1588*700637cbSDimitry Andricpublic:
1589*700637cbSDimitry Andric  typedef vector __self;
1590*700637cbSDimitry Andric  typedef bool value_type;
1591*700637cbSDimitry Andric  typedef _Allocator allocator_type;
1592*700637cbSDimitry Andric  typedef allocator_traits<allocator_type> __alloc_traits;
1593*700637cbSDimitry Andric  typedef typename __alloc_traits::size_type size_type;
1594*700637cbSDimitry Andric  typedef typename __alloc_traits::difference_type difference_type;
1595*700637cbSDimitry Andric  typedef size_type __storage_type;
1596*700637cbSDimitry Andric  typedef __bit_iterator<vector, false> pointer;
1597*700637cbSDimitry Andric  typedef __bit_iterator<vector, true> const_pointer;
1598*700637cbSDimitry Andric  typedef pointer iterator;
1599*700637cbSDimitry Andric  typedef const_pointer const_iterator;
1600*700637cbSDimitry Andric  typedef std::reverse_iterator<iterator> reverse_iterator;
1601*700637cbSDimitry Andric  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
1602*700637cbSDimitry Andric
1603*700637cbSDimitry Andricprivate:
1604*700637cbSDimitry Andric  typedef __rebind_alloc<__alloc_traits, __storage_type> __storage_allocator;
1605*700637cbSDimitry Andric  typedef allocator_traits<__storage_allocator> __storage_traits;
1606*700637cbSDimitry Andric  typedef typename __storage_traits::pointer __storage_pointer;
1607*700637cbSDimitry Andric  typedef typename __storage_traits::const_pointer __const_storage_pointer;
1608*700637cbSDimitry Andric
1609*700637cbSDimitry Andric  __storage_pointer __begin_;
1610*700637cbSDimitry Andric  size_type __size_;
1611*700637cbSDimitry Andric  __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
1612*700637cbSDimitry Andric
1613*700637cbSDimitry Andricpublic:
1614*700637cbSDimitry Andric  typedef __bit_reference<vector> reference;
1615*700637cbSDimitry Andric#ifdef _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
1616*700637cbSDimitry Andric  using const_reference = bool;
1617*700637cbSDimitry Andric#else
1618*700637cbSDimitry Andric  typedef __bit_const_reference<vector> const_reference;
1619*700637cbSDimitry Andric#endif
1620*700637cbSDimitry Andric
1621*700637cbSDimitry Andricprivate:
1622*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type& __cap() _NOEXCEPT { return __cap_alloc_.first(); }
1623*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const size_type& __cap() const _NOEXCEPT { return __cap_alloc_.first(); }
1624*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __storage_allocator& __alloc() _NOEXCEPT { return __cap_alloc_.second(); }
1625*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const __storage_allocator& __alloc() const _NOEXCEPT { return __cap_alloc_.second(); }
1626*700637cbSDimitry Andric
1627*700637cbSDimitry Andric  static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
1628*700637cbSDimitry Andric
1629*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT {
1630*700637cbSDimitry Andric    return __n * __bits_per_word;
1631*700637cbSDimitry Andric  }
1632*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT {
1633*700637cbSDimitry Andric    return (__n - 1) / __bits_per_word + 1;
1634*700637cbSDimitry Andric  }
1635*700637cbSDimitry Andric
1636*700637cbSDimitry Andricpublic:
1637*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector();
1638*700637cbSDimitry Andric
1639*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit vector(const allocator_type& __a);
1640*700637cbSDimitry Andric
1641*700637cbSDimitry Andricprivate:
1642*700637cbSDimitry Andric  class __destroy_vector {
1643*700637cbSDimitry Andric  public:
1644*700637cbSDimitry Andric    _LIBCPP_HIDE_FROM_ABI __destroy_vector(vector& __vec) : __vec_(__vec) {}
1645*700637cbSDimitry Andric
1646*700637cbSDimitry Andric    _LIBCPP_HIDE_FROM_ABI void operator()() {
1647*700637cbSDimitry Andric      if (__vec_.__begin_ != nullptr)
1648*700637cbSDimitry Andric        __storage_traits::deallocate(__vec_.__alloc(), __vec_.__begin_, __vec_.__cap());
1649*700637cbSDimitry Andric    }
1650*700637cbSDimitry Andric
1651*700637cbSDimitry Andric  private:
1652*700637cbSDimitry Andric    vector& __vec_;
1653*700637cbSDimitry Andric  };
1654*700637cbSDimitry Andric
1655*700637cbSDimitry Andricpublic:
1656*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI ~vector() { __destroy_vector (*this)(); }
1657*700637cbSDimitry Andric
1658*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit vector(size_type __n);
1659*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector(size_type __n, const value_type& __v);
1660*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector(size_type __n, const value_type& __v, const allocator_type& __a);
1661*700637cbSDimitry Andric  template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
1662*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector(_InputIterator __first, _InputIterator __last);
1663*700637cbSDimitry Andric  template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
1664*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
1665*700637cbSDimitry Andric  template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
1666*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector(_ForwardIterator __first, _ForwardIterator __last);
1667*700637cbSDimitry Andric  template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
1668*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a);
1669*700637cbSDimitry Andric
1670*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector(const vector& __v);
1671*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector(const vector& __v, const allocator_type& __a);
1672*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector& operator=(const vector& __v);
1673*700637cbSDimitry Andric
1674*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector(vector&& __v);
1675*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector(vector&& __v, const __type_identity_t<allocator_type>& __a);
1676*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI vector& operator=(vector&& __v);
1677*700637cbSDimitry Andric
1678*700637cbSDimitry Andric  template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
1679*700637cbSDimitry Andric  void _LIBCPP_HIDE_FROM_ABI assign(_InputIterator __first, _InputIterator __last);
1680*700637cbSDimitry Andric  template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
1681*700637cbSDimitry Andric  void _LIBCPP_HIDE_FROM_ABI assign(_ForwardIterator __first, _ForwardIterator __last);
1682*700637cbSDimitry Andric
1683*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const value_type& __x);
1684*700637cbSDimitry Andric
1685*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT { return allocator_type(this->__alloc()); }
1686*700637cbSDimitry Andric
1687*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT;
1688*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type capacity() const _NOEXCEPT { return __internal_cap_to_external(__cap()); }
1689*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __size_; }
1690*700637cbSDimitry Andric  _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __size_ == 0; }
1691*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void reserve(size_type __n);
1692*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void shrink_to_fit() _NOEXCEPT;
1693*700637cbSDimitry Andric
1694*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __make_iter(0); }
1695*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __make_iter(0); }
1696*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return __make_iter(__size_); }
1697*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return __make_iter(__size_); }
1698*700637cbSDimitry Andric
1699*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT { return reverse_iterator(end()); }
1700*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(end()); }
1701*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() _NOEXCEPT { return reverse_iterator(begin()); }
1702*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(begin()); }
1703*700637cbSDimitry Andric
1704*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return __make_iter(0); }
1705*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return __make_iter(__size_); }
1706*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT { return rbegin(); }
1707*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return rend(); }
1708*700637cbSDimitry Andric
1709*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reference operator[](size_type __n) { return __make_ref(__n); }
1710*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference operator[](size_type __n) const { return __make_ref(__n); }
1711*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reference at(size_type __n);
1712*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __n) const;
1713*700637cbSDimitry Andric
1714*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reference front() { return __make_ref(0); }
1715*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference front() const { return __make_ref(0); }
1716*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reference back() { return __make_ref(__size_ - 1); }
1717*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference back() const { return __make_ref(__size_ - 1); }
1718*700637cbSDimitry Andric
1719*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void push_back(const value_type& __x);
1720*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void pop_back() { --__size_; }
1721*700637cbSDimitry Andric
1722*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, const value_type& __x);
1723*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, size_type __n, const value_type& __x);
1724*700637cbSDimitry Andric  template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
1725*700637cbSDimitry Andric  iterator _LIBCPP_HIDE_FROM_ABI insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
1726*700637cbSDimitry Andric  template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
1727*700637cbSDimitry Andric  iterator _LIBCPP_HIDE_FROM_ABI insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
1728*700637cbSDimitry Andric
1729*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __position);
1730*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __first, const_iterator __last);
1731*700637cbSDimitry Andric
1732*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __size_ = 0; }
1733*700637cbSDimitry Andric
1734*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void swap(vector&);
1735*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI static void swap(reference __x, reference __y) _NOEXCEPT { std::swap(__x, __y); }
1736*700637cbSDimitry Andric
1737*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz, value_type __x = false);
1738*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void flip() _NOEXCEPT;
1739*700637cbSDimitry Andric
1740*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool __invariants() const;
1741*700637cbSDimitry Andric
1742*700637cbSDimitry Andricprivate:
1743*700637cbSDimitry Andric  _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_length_error() const { std::__throw_length_error("vector"); }
1744*700637cbSDimitry Andric
1745*700637cbSDimitry Andric  _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI void __throw_out_of_range() const { std::__throw_out_of_range("vector"); }
1746*700637cbSDimitry Andric
1747*700637cbSDimitry Andric  template <class _InputIterator, class _Sentinel>
1748*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __init_with_size(_InputIterator __first, _Sentinel __last, size_type __n) {
1749*700637cbSDimitry Andric    auto __guard = std::__make_exception_guard(__destroy_vector(*this));
1750*700637cbSDimitry Andric
1751*700637cbSDimitry Andric    if (__n > 0) {
1752*700637cbSDimitry Andric      __vallocate(__n);
1753*700637cbSDimitry Andric      __construct_at_end(std::move(__first), std::move(__last), __n);
1754*700637cbSDimitry Andric    }
1755*700637cbSDimitry Andric
1756*700637cbSDimitry Andric    __guard.__complete();
1757*700637cbSDimitry Andric  }
1758*700637cbSDimitry Andric
1759*700637cbSDimitry Andric  template <class _InputIterator, class _Sentinel>
1760*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __init_with_sentinel(_InputIterator __first, _Sentinel __last) {
1761*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1762*700637cbSDimitry Andric    try {
1763*700637cbSDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1764*700637cbSDimitry Andric      for (; __first != __last; ++__first)
1765*700637cbSDimitry Andric        push_back(*__first);
1766*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
1767*700637cbSDimitry Andric    } catch (...) {
1768*700637cbSDimitry Andric      if (__begin_ != nullptr)
1769*700637cbSDimitry Andric        __storage_traits::deallocate(__alloc(), __begin_, __cap());
1770*700637cbSDimitry Andric      throw;
1771*700637cbSDimitry Andric    }
1772*700637cbSDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
1773*700637cbSDimitry Andric  }
1774*700637cbSDimitry Andric
1775*700637cbSDimitry Andric  template <class _Iterator, class _Sentinel>
1776*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __assign_with_sentinel(_Iterator __first, _Sentinel __last);
1777*700637cbSDimitry Andric
1778*700637cbSDimitry Andric  template <class _ForwardIterator, class _Sentinel>
1779*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __ns);
1780*700637cbSDimitry Andric
1781*700637cbSDimitry Andric  template <class _InputIterator, class _Sentinel>
1782*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator
1783*700637cbSDimitry Andric  __insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last);
1784*700637cbSDimitry Andric
1785*700637cbSDimitry Andric  template <class _Iterator, class _Sentinel>
1786*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator
1787*700637cbSDimitry Andric  __insert_with_size(const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n);
1788*700637cbSDimitry Andric
1789*700637cbSDimitry Andric  //  Allocate space for __n objects
1790*700637cbSDimitry Andric  //  throws length_error if __n > max_size()
1791*700637cbSDimitry Andric  //  throws (probably bad_alloc) if memory run out
1792*700637cbSDimitry Andric  //  Precondition:  __begin_ == __end_ == __cap() == 0
1793*700637cbSDimitry Andric  //  Precondition:  __n > 0
1794*700637cbSDimitry Andric  //  Postcondition:  capacity() >= __n
1795*700637cbSDimitry Andric  //  Postcondition:  size() == 0
1796*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __vallocate(size_type __n) {
1797*700637cbSDimitry Andric    if (__n > max_size())
1798*700637cbSDimitry Andric      __throw_length_error();
1799*700637cbSDimitry Andric    auto __allocation = std::__allocate_at_least(__alloc(), __external_cap_to_internal(__n));
1800*700637cbSDimitry Andric    __begin_          = __allocation.ptr;
1801*700637cbSDimitry Andric    __size_           = 0;
1802*700637cbSDimitry Andric    __cap()           = __allocation.count;
1803*700637cbSDimitry Andric    if (__libcpp_is_constant_evaluated()) {
1804*700637cbSDimitry Andric      for (size_type __i = 0; __i != __cap(); ++__i)
1805*700637cbSDimitry Andric        std::__construct_at(std::__to_address(__begin_) + __i);
1806*700637cbSDimitry Andric    }
1807*700637cbSDimitry Andric  }
1808*700637cbSDimitry Andric
1809*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __vdeallocate() _NOEXCEPT;
1810*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI static size_type __align_it(size_type __new_size) _NOEXCEPT {
1811*700637cbSDimitry Andric    return (__new_size + (__bits_per_word - 1)) & ~((size_type)__bits_per_word - 1);
1812*700637cbSDimitry Andric  }
1813*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type __recommend(size_type __new_size) const;
1814*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __construct_at_end(size_type __n, bool __x);
1815*700637cbSDimitry Andric  template <class _InputIterator, class _Sentinel>
1816*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n);
1817*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __append(size_type __n, const_reference __x);
1818*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reference __make_ref(size_type __pos) _NOEXCEPT {
1819*700637cbSDimitry Andric    return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
1820*700637cbSDimitry Andric  }
1821*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference __make_ref(size_type __pos) const _NOEXCEPT {
1822*700637cbSDimitry Andric    return __bit_const_reference<vector>(
1823*700637cbSDimitry Andric        __begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);
1824*700637cbSDimitry Andric  }
1825*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator __make_iter(size_type __pos) _NOEXCEPT {
1826*700637cbSDimitry Andric    return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));
1827*700637cbSDimitry Andric  }
1828*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator __make_iter(size_type __pos) const _NOEXCEPT {
1829*700637cbSDimitry Andric    return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));
1830*700637cbSDimitry Andric  }
1831*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT {
1832*700637cbSDimitry Andric    return begin() + (__p - cbegin());
1833*700637cbSDimitry Andric  }
1834*700637cbSDimitry Andric
1835*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const vector& __v) {
1836*700637cbSDimitry Andric    __copy_assign_alloc(
1837*700637cbSDimitry Andric        __v, integral_constant<bool, __storage_traits::propagate_on_container_copy_assignment::value>());
1838*700637cbSDimitry Andric  }
1839*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const vector& __c, true_type) {
1840*700637cbSDimitry Andric    if (__alloc() != __c.__alloc())
1841*700637cbSDimitry Andric      __vdeallocate();
1842*700637cbSDimitry Andric    __alloc() = __c.__alloc();
1843*700637cbSDimitry Andric  }
1844*700637cbSDimitry Andric
1845*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const vector&, false_type) {}
1846*700637cbSDimitry Andric
1847*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, false_type);
1848*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __move_assign(vector& __c, true_type);
1849*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector& __c) {
1850*700637cbSDimitry Andric    __move_assign_alloc(
1851*700637cbSDimitry Andric        __c, integral_constant<bool, __storage_traits::propagate_on_container_move_assignment::value>());
1852*700637cbSDimitry Andric  }
1853*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector& __c, true_type) { __alloc() = std::move(__c.__alloc()); }
1854*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(vector&, false_type) _NOEXCEPT {}
1855*700637cbSDimitry Andric
1856*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_t __hash_code() const _NOEXCEPT;
1857*700637cbSDimitry Andric
1858*700637cbSDimitry Andric  friend class __bit_reference<vector>;
1859*700637cbSDimitry Andric  friend class __bit_const_reference<vector>;
1860*700637cbSDimitry Andric  friend class __bit_iterator<vector, false>;
1861*700637cbSDimitry Andric  friend class __bit_iterator<vector, true>;
1862*700637cbSDimitry Andric  friend struct __bit_array<vector>;
1863*700637cbSDimitry Andric  friend struct _LIBCPP_TEMPLATE_VIS hash<vector>;
1864*700637cbSDimitry Andric};
1865*700637cbSDimitry Andric
1866*700637cbSDimitry Andrictemplate <class _Allocator>
1867*700637cbSDimitry Andricvoid vector<bool, _Allocator>::__vdeallocate() _NOEXCEPT {
1868*700637cbSDimitry Andric  if (this->__begin_ != nullptr) {
1869*700637cbSDimitry Andric    __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
1870*700637cbSDimitry Andric    this->__begin_ = nullptr;
1871*700637cbSDimitry Andric    this->__size_ = this->__cap() = 0;
1872*700637cbSDimitry Andric  }
1873*700637cbSDimitry Andric}
1874*700637cbSDimitry Andric
1875*700637cbSDimitry Andrictemplate <class _Allocator>
1876*700637cbSDimitry Andrictypename vector<bool, _Allocator>::size_type vector<bool, _Allocator>::max_size() const _NOEXCEPT {
1877*700637cbSDimitry Andric  size_type __amax = __storage_traits::max_size(__alloc());
1878*700637cbSDimitry Andric  size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
1879*700637cbSDimitry Andric  if (__nmax / __bits_per_word <= __amax)
1880*700637cbSDimitry Andric    return __nmax;
1881*700637cbSDimitry Andric  return __internal_cap_to_external(__amax);
1882*700637cbSDimitry Andric}
1883*700637cbSDimitry Andric
1884*700637cbSDimitry Andric//  Precondition:  __new_size > capacity()
1885*700637cbSDimitry Andrictemplate <class _Allocator>
1886*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI typename vector<bool, _Allocator>::size_type
1887*700637cbSDimitry Andricvector<bool, _Allocator>::__recommend(size_type __new_size) const {
1888*700637cbSDimitry Andric  const size_type __ms = max_size();
1889*700637cbSDimitry Andric  if (__new_size > __ms)
1890*700637cbSDimitry Andric    this->__throw_length_error();
1891*700637cbSDimitry Andric  const size_type __cap = capacity();
1892*700637cbSDimitry Andric  if (__cap >= __ms / 2)
1893*700637cbSDimitry Andric    return __ms;
1894*700637cbSDimitry Andric  return std::max(2 * __cap, __align_it(__new_size));
1895*700637cbSDimitry Andric}
1896*700637cbSDimitry Andric
1897*700637cbSDimitry Andric//  Default constructs __n objects starting at __end_
1898*700637cbSDimitry Andric//  Precondition:  __n > 0
1899*700637cbSDimitry Andric//  Precondition:  size() + __n <= capacity()
1900*700637cbSDimitry Andric//  Postcondition:  size() == size() + __n
1901*700637cbSDimitry Andrictemplate <class _Allocator>
1902*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x) {
1903*700637cbSDimitry Andric  size_type __old_size = this->__size_;
1904*700637cbSDimitry Andric  this->__size_ += __n;
1905*700637cbSDimitry Andric  if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) {
1906*700637cbSDimitry Andric    if (this->__size_ <= __bits_per_word)
1907*700637cbSDimitry Andric      this->__begin_[0] = __storage_type(0);
1908*700637cbSDimitry Andric    else
1909*700637cbSDimitry Andric      this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
1910*700637cbSDimitry Andric  }
1911*700637cbSDimitry Andric  std::fill_n(__make_iter(__old_size), __n, __x);
1912*700637cbSDimitry Andric}
1913*700637cbSDimitry Andric
1914*700637cbSDimitry Andrictemplate <class _Allocator>
1915*700637cbSDimitry Andrictemplate <class _InputIterator, class _Sentinel>
1916*700637cbSDimitry Andricvoid vector<bool, _Allocator>::__construct_at_end(_InputIterator __first, _Sentinel __last, size_type __n) {
1917*700637cbSDimitry Andric  size_type __old_size = this->__size_;
1918*700637cbSDimitry Andric  this->__size_ += __n;
1919*700637cbSDimitry Andric  if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) {
1920*700637cbSDimitry Andric    if (this->__size_ <= __bits_per_word)
1921*700637cbSDimitry Andric      this->__begin_[0] = __storage_type(0);
1922*700637cbSDimitry Andric    else
1923*700637cbSDimitry Andric      this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
1924*700637cbSDimitry Andric  }
1925*700637cbSDimitry Andric  std::__copy<_ClassicAlgPolicy>(__first, __last, __make_iter(__old_size));
1926*700637cbSDimitry Andric}
1927*700637cbSDimitry Andric
1928*700637cbSDimitry Andrictemplate <class _Allocator>
1929*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI vector<bool, _Allocator>::vector()
1930*700637cbSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) {}
1931*700637cbSDimitry Andric
1932*700637cbSDimitry Andrictemplate <class _Allocator>
1933*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI vector<bool, _Allocator>::vector(const allocator_type& __a)
1934*700637cbSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) {}
1935*700637cbSDimitry Andric
1936*700637cbSDimitry Andrictemplate <class _Allocator>
1937*700637cbSDimitry Andricvector<bool, _Allocator>::vector(size_type __n) : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) {
1938*700637cbSDimitry Andric  if (__n > 0) {
1939*700637cbSDimitry Andric    __vallocate(__n);
1940*700637cbSDimitry Andric    __construct_at_end(__n, false);
1941*700637cbSDimitry Andric  }
1942*700637cbSDimitry Andric}
1943*700637cbSDimitry Andric
1944*700637cbSDimitry Andrictemplate <class _Allocator>
1945*700637cbSDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
1946*700637cbSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) {
1947*700637cbSDimitry Andric  if (__n > 0) {
1948*700637cbSDimitry Andric    __vallocate(__n);
1949*700637cbSDimitry Andric    __construct_at_end(__n, __x);
1950*700637cbSDimitry Andric  }
1951*700637cbSDimitry Andric}
1952*700637cbSDimitry Andric
1953*700637cbSDimitry Andrictemplate <class _Allocator>
1954*700637cbSDimitry Andricvector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
1955*700637cbSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) {
1956*700637cbSDimitry Andric  if (__n > 0) {
1957*700637cbSDimitry Andric    __vallocate(__n);
1958*700637cbSDimitry Andric    __construct_at_end(__n, __x);
1959*700637cbSDimitry Andric  }
1960*700637cbSDimitry Andric}
1961*700637cbSDimitry Andric
1962*700637cbSDimitry Andrictemplate <class _Allocator>
1963*700637cbSDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
1964*700637cbSDimitry Andricvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last)
1965*700637cbSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) {
1966*700637cbSDimitry Andric  __init_with_sentinel(__first, __last);
1967*700637cbSDimitry Andric}
1968*700637cbSDimitry Andric
1969*700637cbSDimitry Andrictemplate <class _Allocator>
1970*700637cbSDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
1971*700637cbSDimitry Andricvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a)
1972*700637cbSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) {
1973*700637cbSDimitry Andric  __init_with_sentinel(__first, __last);
1974*700637cbSDimitry Andric}
1975*700637cbSDimitry Andric
1976*700637cbSDimitry Andrictemplate <class _Allocator>
1977*700637cbSDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
1978*700637cbSDimitry Andricvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last)
1979*700637cbSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, __default_init_tag()) {
1980*700637cbSDimitry Andric  auto __n = static_cast<size_type>(std::distance(__first, __last));
1981*700637cbSDimitry Andric  __init_with_size(__first, __last, __n);
1982*700637cbSDimitry Andric}
1983*700637cbSDimitry Andric
1984*700637cbSDimitry Andrictemplate <class _Allocator>
1985*700637cbSDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
1986*700637cbSDimitry Andricvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a)
1987*700637cbSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, static_cast<__storage_allocator>(__a)) {
1988*700637cbSDimitry Andric  auto __n = static_cast<size_type>(std::distance(__first, __last));
1989*700637cbSDimitry Andric  __init_with_size(__first, __last, __n);
1990*700637cbSDimitry Andric}
1991*700637cbSDimitry Andric
1992*700637cbSDimitry Andrictemplate <class _Allocator>
1993*700637cbSDimitry Andricvector<bool, _Allocator>::vector(const vector& __v)
1994*700637cbSDimitry Andric    : __begin_(nullptr),
1995*700637cbSDimitry Andric      __size_(0),
1996*700637cbSDimitry Andric      __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc())) {
1997*700637cbSDimitry Andric  if (__v.size() > 0) {
1998*700637cbSDimitry Andric    __vallocate(__v.size());
1999*700637cbSDimitry Andric    __construct_at_end(__v.begin(), __v.end(), __v.size());
2000*700637cbSDimitry Andric  }
2001*700637cbSDimitry Andric}
2002*700637cbSDimitry Andric
2003*700637cbSDimitry Andrictemplate <class _Allocator>
2004*700637cbSDimitry Andricvector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
2005*700637cbSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, __a) {
2006*700637cbSDimitry Andric  if (__v.size() > 0) {
2007*700637cbSDimitry Andric    __vallocate(__v.size());
2008*700637cbSDimitry Andric    __construct_at_end(__v.begin(), __v.end(), __v.size());
2009*700637cbSDimitry Andric  }
2010*700637cbSDimitry Andric}
2011*700637cbSDimitry Andric
2012*700637cbSDimitry Andrictemplate <class _Allocator>
2013*700637cbSDimitry Andricvector<bool, _Allocator>& vector<bool, _Allocator>::operator=(const vector& __v) {
2014*700637cbSDimitry Andric  if (this != std::addressof(__v)) {
2015*700637cbSDimitry Andric    __copy_assign_alloc(__v);
2016*700637cbSDimitry Andric    if (__v.__size_) {
2017*700637cbSDimitry Andric      if (__v.__size_ > capacity()) {
2018*700637cbSDimitry Andric        __vdeallocate();
2019*700637cbSDimitry Andric        __vallocate(__v.__size_);
2020*700637cbSDimitry Andric      }
2021*700637cbSDimitry Andric      std::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
2022*700637cbSDimitry Andric    }
2023*700637cbSDimitry Andric    __size_ = __v.__size_;
2024*700637cbSDimitry Andric  }
2025*700637cbSDimitry Andric  return *this;
2026*700637cbSDimitry Andric}
2027*700637cbSDimitry Andric
2028*700637cbSDimitry Andrictemplate <class _Allocator>
2029*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI vector<bool, _Allocator>::vector(vector&& __v)
2030*700637cbSDimitry Andric    : __begin_(__v.__begin_), __size_(__v.__size_), __cap_alloc_(std::move(__v.__cap_alloc_)) {
2031*700637cbSDimitry Andric  __v.__begin_ = nullptr;
2032*700637cbSDimitry Andric  __v.__size_  = 0;
2033*700637cbSDimitry Andric  __v.__cap()  = 0;
2034*700637cbSDimitry Andric}
2035*700637cbSDimitry Andric
2036*700637cbSDimitry Andrictemplate <class _Allocator>
2037*700637cbSDimitry Andricvector<bool, _Allocator>::vector(vector&& __v, const __type_identity_t<allocator_type>& __a)
2038*700637cbSDimitry Andric    : __begin_(nullptr), __size_(0), __cap_alloc_(0, __a) {
2039*700637cbSDimitry Andric  if (__a == allocator_type(__v.__alloc())) {
2040*700637cbSDimitry Andric    this->__begin_ = __v.__begin_;
2041*700637cbSDimitry Andric    this->__size_  = __v.__size_;
2042*700637cbSDimitry Andric    this->__cap()  = __v.__cap();
2043*700637cbSDimitry Andric    __v.__begin_   = nullptr;
2044*700637cbSDimitry Andric    __v.__cap() = __v.__size_ = 0;
2045*700637cbSDimitry Andric  } else if (__v.size() > 0) {
2046*700637cbSDimitry Andric    __vallocate(__v.size());
2047*700637cbSDimitry Andric    __construct_at_end(__v.begin(), __v.end(), __v.size());
2048*700637cbSDimitry Andric  }
2049*700637cbSDimitry Andric}
2050*700637cbSDimitry Andric
2051*700637cbSDimitry Andrictemplate <class _Allocator>
2052*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI vector<bool, _Allocator>& vector<bool, _Allocator>::operator=(vector&& __v) {
2053*700637cbSDimitry Andric  __move_assign(__v, integral_constant<bool, __storage_traits::propagate_on_container_move_assignment::value>());
2054*700637cbSDimitry Andric  return *this;
2055*700637cbSDimitry Andric}
2056*700637cbSDimitry Andric
2057*700637cbSDimitry Andrictemplate <class _Allocator>
2058*700637cbSDimitry Andricvoid vector<bool, _Allocator>::__move_assign(vector& __c, false_type) {
2059*700637cbSDimitry Andric  if (__alloc() != __c.__alloc())
2060*700637cbSDimitry Andric    assign(__c.begin(), __c.end());
2061*700637cbSDimitry Andric  else
2062*700637cbSDimitry Andric    __move_assign(__c, true_type());
2063*700637cbSDimitry Andric}
2064*700637cbSDimitry Andric
2065*700637cbSDimitry Andrictemplate <class _Allocator>
2066*700637cbSDimitry Andricvoid vector<bool, _Allocator>::__move_assign(vector& __c, true_type) {
2067*700637cbSDimitry Andric  __vdeallocate();
2068*700637cbSDimitry Andric  __move_assign_alloc(__c);
2069*700637cbSDimitry Andric  this->__begin_ = __c.__begin_;
2070*700637cbSDimitry Andric  this->__size_  = __c.__size_;
2071*700637cbSDimitry Andric  this->__cap()  = __c.__cap();
2072*700637cbSDimitry Andric  __c.__begin_   = nullptr;
2073*700637cbSDimitry Andric  __c.__cap() = __c.__size_ = 0;
2074*700637cbSDimitry Andric}
2075*700637cbSDimitry Andric
2076*700637cbSDimitry Andrictemplate <class _Allocator>
2077*700637cbSDimitry Andricvoid vector<bool, _Allocator>::assign(size_type __n, const value_type& __x) {
2078*700637cbSDimitry Andric  __size_ = 0;
2079*700637cbSDimitry Andric  if (__n > 0) {
2080*700637cbSDimitry Andric    size_type __c = capacity();
2081*700637cbSDimitry Andric    if (__n <= __c)
2082*700637cbSDimitry Andric      __size_ = __n;
2083*700637cbSDimitry Andric    else {
2084*700637cbSDimitry Andric      vector __v(get_allocator());
2085*700637cbSDimitry Andric      __v.reserve(__recommend(__n));
2086*700637cbSDimitry Andric      __v.__size_ = __n;
2087*700637cbSDimitry Andric      swap(__v);
2088*700637cbSDimitry Andric    }
2089*700637cbSDimitry Andric    std::fill_n(begin(), __n, __x);
2090*700637cbSDimitry Andric  }
2091*700637cbSDimitry Andric}
2092*700637cbSDimitry Andric
2093*700637cbSDimitry Andrictemplate <class _Allocator>
2094*700637cbSDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
2095*700637cbSDimitry Andricvoid vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last) {
2096*700637cbSDimitry Andric  __assign_with_sentinel(__first, __last);
2097*700637cbSDimitry Andric}
2098*700637cbSDimitry Andric
2099*700637cbSDimitry Andrictemplate <class _Allocator>
2100*700637cbSDimitry Andrictemplate <class _Iterator, class _Sentinel>
2101*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI void vector<bool, _Allocator>::__assign_with_sentinel(_Iterator __first, _Sentinel __last) {
2102*700637cbSDimitry Andric  clear();
2103*700637cbSDimitry Andric  for (; __first != __last; ++__first)
2104*700637cbSDimitry Andric    push_back(*__first);
2105*700637cbSDimitry Andric}
2106*700637cbSDimitry Andric
2107*700637cbSDimitry Andrictemplate <class _Allocator>
2108*700637cbSDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
2109*700637cbSDimitry Andricvoid vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) {
2110*700637cbSDimitry Andric  __assign_with_size(__first, __last, std::distance(__first, __last));
2111*700637cbSDimitry Andric}
2112*700637cbSDimitry Andric
2113*700637cbSDimitry Andrictemplate <class _Allocator>
2114*700637cbSDimitry Andrictemplate <class _ForwardIterator, class _Sentinel>
2115*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI void
2116*700637cbSDimitry Andricvector<bool, _Allocator>::__assign_with_size(_ForwardIterator __first, _Sentinel __last, difference_type __ns) {
2117*700637cbSDimitry Andric  _LIBCPP_ASSERT_VALID_INPUT_RANGE(__ns >= 0, "invalid range specified");
2118*700637cbSDimitry Andric
2119*700637cbSDimitry Andric  clear();
2120*700637cbSDimitry Andric
2121*700637cbSDimitry Andric  const size_t __n = static_cast<size_type>(__ns);
2122*700637cbSDimitry Andric  if (__n) {
2123*700637cbSDimitry Andric    if (__n > capacity()) {
2124*700637cbSDimitry Andric      __vdeallocate();
2125*700637cbSDimitry Andric      __vallocate(__n);
2126*700637cbSDimitry Andric    }
2127*700637cbSDimitry Andric    __construct_at_end(__first, __last, __n);
2128*700637cbSDimitry Andric  }
2129*700637cbSDimitry Andric}
2130*700637cbSDimitry Andric
2131*700637cbSDimitry Andrictemplate <class _Allocator>
2132*700637cbSDimitry Andricvoid vector<bool, _Allocator>::reserve(size_type __n) {
2133*700637cbSDimitry Andric  if (__n > capacity()) {
2134*700637cbSDimitry Andric    if (__n > max_size())
2135*700637cbSDimitry Andric      this->__throw_length_error();
2136*700637cbSDimitry Andric    vector __v(this->get_allocator());
2137*700637cbSDimitry Andric    __v.__vallocate(__n);
2138*700637cbSDimitry Andric    __v.__construct_at_end(this->begin(), this->end(), this->size());
2139*700637cbSDimitry Andric    swap(__v);
2140*700637cbSDimitry Andric  }
2141*700637cbSDimitry Andric}
2142*700637cbSDimitry Andric
2143*700637cbSDimitry Andrictemplate <class _Allocator>
2144*700637cbSDimitry Andricvoid vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT {
2145*700637cbSDimitry Andric  if (__external_cap_to_internal(size()) > __cap()) {
2146*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2147*700637cbSDimitry Andric    try {
2148*700637cbSDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2149*700637cbSDimitry Andric      vector(*this, allocator_type(__alloc())).swap(*this);
2150*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2151*700637cbSDimitry Andric    } catch (...) {
2152*700637cbSDimitry Andric    }
2153*700637cbSDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2154*700637cbSDimitry Andric  }
2155*700637cbSDimitry Andric}
2156*700637cbSDimitry Andric
2157*700637cbSDimitry Andrictemplate <class _Allocator>
2158*700637cbSDimitry Andrictypename vector<bool, _Allocator>::reference vector<bool, _Allocator>::at(size_type __n) {
2159*700637cbSDimitry Andric  if (__n >= size())
2160*700637cbSDimitry Andric    this->__throw_out_of_range();
2161*700637cbSDimitry Andric  return (*this)[__n];
2162*700637cbSDimitry Andric}
2163*700637cbSDimitry Andric
2164*700637cbSDimitry Andrictemplate <class _Allocator>
2165*700637cbSDimitry Andrictypename vector<bool, _Allocator>::const_reference vector<bool, _Allocator>::at(size_type __n) const {
2166*700637cbSDimitry Andric  if (__n >= size())
2167*700637cbSDimitry Andric    this->__throw_out_of_range();
2168*700637cbSDimitry Andric  return (*this)[__n];
2169*700637cbSDimitry Andric}
2170*700637cbSDimitry Andric
2171*700637cbSDimitry Andrictemplate <class _Allocator>
2172*700637cbSDimitry Andricvoid vector<bool, _Allocator>::push_back(const value_type& __x) {
2173*700637cbSDimitry Andric  if (this->__size_ == this->capacity())
2174*700637cbSDimitry Andric    reserve(__recommend(this->__size_ + 1));
2175*700637cbSDimitry Andric  ++this->__size_;
2176*700637cbSDimitry Andric  back() = __x;
2177*700637cbSDimitry Andric}
2178*700637cbSDimitry Andric
2179*700637cbSDimitry Andrictemplate <class _Allocator>
2180*700637cbSDimitry Andrictypename vector<bool, _Allocator>::iterator
2181*700637cbSDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x) {
2182*700637cbSDimitry Andric  iterator __r;
2183*700637cbSDimitry Andric  if (size() < capacity()) {
2184*700637cbSDimitry Andric    const_iterator __old_end = end();
2185*700637cbSDimitry Andric    ++__size_;
2186*700637cbSDimitry Andric    std::copy_backward(__position, __old_end, end());
2187*700637cbSDimitry Andric    __r = __const_iterator_cast(__position);
2188*700637cbSDimitry Andric  } else {
2189*700637cbSDimitry Andric    vector __v(get_allocator());
2190*700637cbSDimitry Andric    __v.reserve(__recommend(__size_ + 1));
2191*700637cbSDimitry Andric    __v.__size_ = __size_ + 1;
2192*700637cbSDimitry Andric    __r         = std::copy(cbegin(), __position, __v.begin());
2193*700637cbSDimitry Andric    std::copy_backward(__position, cend(), __v.end());
2194*700637cbSDimitry Andric    swap(__v);
2195*700637cbSDimitry Andric  }
2196*700637cbSDimitry Andric  *__r = __x;
2197*700637cbSDimitry Andric  return __r;
2198*700637cbSDimitry Andric}
2199*700637cbSDimitry Andric
2200*700637cbSDimitry Andrictemplate <class _Allocator>
2201*700637cbSDimitry Andrictypename vector<bool, _Allocator>::iterator
2202*700637cbSDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x) {
2203*700637cbSDimitry Andric  iterator __r;
2204*700637cbSDimitry Andric  size_type __c = capacity();
2205*700637cbSDimitry Andric  if (__n <= __c && size() <= __c - __n) {
2206*700637cbSDimitry Andric    const_iterator __old_end = end();
2207*700637cbSDimitry Andric    __size_ += __n;
2208*700637cbSDimitry Andric    std::copy_backward(__position, __old_end, end());
2209*700637cbSDimitry Andric    __r = __const_iterator_cast(__position);
2210*700637cbSDimitry Andric  } else {
2211*700637cbSDimitry Andric    vector __v(get_allocator());
2212*700637cbSDimitry Andric    __v.reserve(__recommend(__size_ + __n));
2213*700637cbSDimitry Andric    __v.__size_ = __size_ + __n;
2214*700637cbSDimitry Andric    __r         = std::copy(cbegin(), __position, __v.begin());
2215*700637cbSDimitry Andric    std::copy_backward(__position, cend(), __v.end());
2216*700637cbSDimitry Andric    swap(__v);
2217*700637cbSDimitry Andric  }
2218*700637cbSDimitry Andric  std::fill_n(__r, __n, __x);
2219*700637cbSDimitry Andric  return __r;
2220*700637cbSDimitry Andric}
2221*700637cbSDimitry Andric
2222*700637cbSDimitry Andrictemplate <class _Allocator>
2223*700637cbSDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> >
2224*700637cbSDimitry Andrictypename vector<bool, _Allocator>::iterator
2225*700637cbSDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) {
2226*700637cbSDimitry Andric  return __insert_with_sentinel(__position, __first, __last);
2227*700637cbSDimitry Andric}
2228*700637cbSDimitry Andric
2229*700637cbSDimitry Andrictemplate <class _Allocator>
2230*700637cbSDimitry Andrictemplate <class _InputIterator, class _Sentinel>
2231*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI typename vector<bool, _Allocator>::iterator
2232*700637cbSDimitry Andricvector<bool, _Allocator>::__insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last) {
2233*700637cbSDimitry Andric  difference_type __off = __position - begin();
2234*700637cbSDimitry Andric  iterator __p          = __const_iterator_cast(__position);
2235*700637cbSDimitry Andric  iterator __old_end    = end();
2236*700637cbSDimitry Andric  for (; size() != capacity() && __first != __last; ++__first) {
2237*700637cbSDimitry Andric    ++this->__size_;
2238*700637cbSDimitry Andric    back() = *__first;
2239*700637cbSDimitry Andric  }
2240*700637cbSDimitry Andric  vector __v(get_allocator());
2241*700637cbSDimitry Andric  if (__first != __last) {
2242*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2243*700637cbSDimitry Andric    try {
2244*700637cbSDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2245*700637cbSDimitry Andric      __v.__assign_with_sentinel(std::move(__first), std::move(__last));
2246*700637cbSDimitry Andric      difference_type __old_size = static_cast<difference_type>(__old_end - begin());
2247*700637cbSDimitry Andric      difference_type __old_p    = __p - begin();
2248*700637cbSDimitry Andric      reserve(__recommend(size() + __v.size()));
2249*700637cbSDimitry Andric      __p       = begin() + __old_p;
2250*700637cbSDimitry Andric      __old_end = begin() + __old_size;
2251*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
2252*700637cbSDimitry Andric    } catch (...) {
2253*700637cbSDimitry Andric      erase(__old_end, end());
2254*700637cbSDimitry Andric      throw;
2255*700637cbSDimitry Andric    }
2256*700637cbSDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS
2257*700637cbSDimitry Andric  }
2258*700637cbSDimitry Andric  __p = std::rotate(__p, __old_end, end());
2259*700637cbSDimitry Andric  insert(__p, __v.begin(), __v.end());
2260*700637cbSDimitry Andric  return begin() + __off;
2261*700637cbSDimitry Andric}
2262*700637cbSDimitry Andric
2263*700637cbSDimitry Andrictemplate <class _Allocator>
2264*700637cbSDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> >
2265*700637cbSDimitry Andrictypename vector<bool, _Allocator>::iterator
2266*700637cbSDimitry Andricvector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) {
2267*700637cbSDimitry Andric  return __insert_with_size(__position, __first, __last, std::distance(__first, __last));
2268*700637cbSDimitry Andric}
2269*700637cbSDimitry Andric
2270*700637cbSDimitry Andrictemplate <class _Allocator>
2271*700637cbSDimitry Andrictemplate <class _ForwardIterator, class _Sentinel>
2272*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI typename vector<bool, _Allocator>::iterator vector<bool, _Allocator>::__insert_with_size(
2273*700637cbSDimitry Andric    const_iterator __position, _ForwardIterator __first, _Sentinel __last, difference_type __n_signed) {
2274*700637cbSDimitry Andric  _LIBCPP_ASSERT_VALID_INPUT_RANGE(__n_signed >= 0, "invalid range specified");
2275*700637cbSDimitry Andric  const size_type __n = static_cast<size_type>(__n_signed);
2276*700637cbSDimitry Andric  iterator __r;
2277*700637cbSDimitry Andric  size_type __c = capacity();
2278*700637cbSDimitry Andric  if (__n <= __c && size() <= __c - __n) {
2279*700637cbSDimitry Andric    const_iterator __old_end = end();
2280*700637cbSDimitry Andric    __size_ += __n;
2281*700637cbSDimitry Andric    std::copy_backward(__position, __old_end, end());
2282*700637cbSDimitry Andric    __r = __const_iterator_cast(__position);
2283*700637cbSDimitry Andric  } else {
2284*700637cbSDimitry Andric    vector __v(get_allocator());
2285*700637cbSDimitry Andric    __v.reserve(__recommend(__size_ + __n));
2286*700637cbSDimitry Andric    __v.__size_ = __size_ + __n;
2287*700637cbSDimitry Andric    __r         = std::copy(cbegin(), __position, __v.begin());
2288*700637cbSDimitry Andric    std::copy_backward(__position, cend(), __v.end());
2289*700637cbSDimitry Andric    swap(__v);
2290*700637cbSDimitry Andric  }
2291*700637cbSDimitry Andric  std::__copy<_ClassicAlgPolicy>(__first, __last, __r);
2292*700637cbSDimitry Andric  return __r;
2293*700637cbSDimitry Andric}
2294*700637cbSDimitry Andric
2295*700637cbSDimitry Andrictemplate <class _Allocator>
2296*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI typename vector<bool, _Allocator>::iterator
2297*700637cbSDimitry Andricvector<bool, _Allocator>::erase(const_iterator __position) {
2298*700637cbSDimitry Andric  iterator __r = __const_iterator_cast(__position);
2299*700637cbSDimitry Andric  std::copy(__position + 1, this->cend(), __r);
2300*700637cbSDimitry Andric  --__size_;
2301*700637cbSDimitry Andric  return __r;
2302*700637cbSDimitry Andric}
2303*700637cbSDimitry Andric
2304*700637cbSDimitry Andrictemplate <class _Allocator>
2305*700637cbSDimitry Andrictypename vector<bool, _Allocator>::iterator
2306*700637cbSDimitry Andricvector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last) {
2307*700637cbSDimitry Andric  iterator __r        = __const_iterator_cast(__first);
2308*700637cbSDimitry Andric  difference_type __d = __last - __first;
2309*700637cbSDimitry Andric  std::copy(__last, this->cend(), __r);
2310*700637cbSDimitry Andric  __size_ -= __d;
2311*700637cbSDimitry Andric  return __r;
2312*700637cbSDimitry Andric}
2313*700637cbSDimitry Andric
2314*700637cbSDimitry Andrictemplate <class _Allocator>
2315*700637cbSDimitry Andricvoid vector<bool, _Allocator>::swap(vector& __x) {
2316*700637cbSDimitry Andric  std::swap(this->__begin_, __x.__begin_);
2317*700637cbSDimitry Andric  std::swap(this->__size_, __x.__size_);
2318*700637cbSDimitry Andric  std::swap(this->__cap(), __x.__cap());
2319*700637cbSDimitry Andric  std::__swap_allocator(
2320*700637cbSDimitry Andric      this->__alloc(), __x.__alloc(), integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
2321*700637cbSDimitry Andric}
2322*700637cbSDimitry Andric
2323*700637cbSDimitry Andrictemplate <class _Allocator>
2324*700637cbSDimitry Andricvoid vector<bool, _Allocator>::resize(size_type __sz, value_type __x) {
2325*700637cbSDimitry Andric  size_type __cs = size();
2326*700637cbSDimitry Andric  if (__cs < __sz) {
2327*700637cbSDimitry Andric    iterator __r;
2328*700637cbSDimitry Andric    size_type __c = capacity();
2329*700637cbSDimitry Andric    size_type __n = __sz - __cs;
2330*700637cbSDimitry Andric    if (__n <= __c && __cs <= __c - __n) {
2331*700637cbSDimitry Andric      __r = end();
2332*700637cbSDimitry Andric      __size_ += __n;
2333*700637cbSDimitry Andric    } else {
2334*700637cbSDimitry Andric      vector __v(get_allocator());
2335*700637cbSDimitry Andric      __v.reserve(__recommend(__size_ + __n));
2336*700637cbSDimitry Andric      __v.__size_ = __size_ + __n;
2337*700637cbSDimitry Andric      __r         = std::copy(cbegin(), cend(), __v.begin());
2338*700637cbSDimitry Andric      swap(__v);
2339*700637cbSDimitry Andric    }
2340*700637cbSDimitry Andric    std::fill_n(__r, __n, __x);
2341*700637cbSDimitry Andric  } else
2342*700637cbSDimitry Andric    __size_ = __sz;
2343*700637cbSDimitry Andric}
2344*700637cbSDimitry Andric
2345*700637cbSDimitry Andrictemplate <class _Allocator>
2346*700637cbSDimitry Andricvoid vector<bool, _Allocator>::flip() _NOEXCEPT {
2347*700637cbSDimitry Andric  // do middle whole words
2348*700637cbSDimitry Andric  size_type __n         = __size_;
2349*700637cbSDimitry Andric  __storage_pointer __p = __begin_;
2350*700637cbSDimitry Andric  for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
2351*700637cbSDimitry Andric    *__p = ~*__p;
2352*700637cbSDimitry Andric  // do last partial word
2353*700637cbSDimitry Andric  if (__n > 0) {
2354*700637cbSDimitry Andric    __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
2355*700637cbSDimitry Andric    __storage_type __b = *__p & __m;
2356*700637cbSDimitry Andric    *__p &= ~__m;
2357*700637cbSDimitry Andric    *__p |= ~__b & __m;
2358*700637cbSDimitry Andric  }
2359*700637cbSDimitry Andric}
2360*700637cbSDimitry Andric
2361*700637cbSDimitry Andrictemplate <class _Allocator>
2362*700637cbSDimitry Andricbool vector<bool, _Allocator>::__invariants() const {
2363*700637cbSDimitry Andric  if (this->__begin_ == nullptr) {
2364*700637cbSDimitry Andric    if (this->__size_ != 0 || this->__cap() != 0)
2365*700637cbSDimitry Andric      return false;
2366*700637cbSDimitry Andric  } else {
2367*700637cbSDimitry Andric    if (this->__cap() == 0)
2368*700637cbSDimitry Andric      return false;
2369*700637cbSDimitry Andric    if (this->__size_ > this->capacity())
2370*700637cbSDimitry Andric      return false;
2371*700637cbSDimitry Andric  }
2372*700637cbSDimitry Andric  return true;
2373*700637cbSDimitry Andric}
2374*700637cbSDimitry Andric
2375*700637cbSDimitry Andrictemplate <class _Allocator>
2376*700637cbSDimitry Andricsize_t vector<bool, _Allocator>::__hash_code() const _NOEXCEPT {
2377*700637cbSDimitry Andric  size_t __h = 0;
2378*700637cbSDimitry Andric  // do middle whole words
2379*700637cbSDimitry Andric  size_type __n         = __size_;
2380*700637cbSDimitry Andric  __storage_pointer __p = __begin_;
2381*700637cbSDimitry Andric  for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
2382*700637cbSDimitry Andric    __h ^= *__p;
2383*700637cbSDimitry Andric  // do last partial word
2384*700637cbSDimitry Andric  if (__n > 0) {
2385*700637cbSDimitry Andric    const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
2386*700637cbSDimitry Andric    __h ^= *__p & __m;
2387*700637cbSDimitry Andric  }
2388*700637cbSDimitry Andric  return __h;
2389*700637cbSDimitry Andric}
2390*700637cbSDimitry Andric
2391*700637cbSDimitry Andrictemplate <class _Allocator>
2392*700637cbSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
2393*700637cbSDimitry Andric    : public __unary_function<vector<bool, _Allocator>, size_t> {
2394*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT {
2395*700637cbSDimitry Andric    return __vec.__hash_code();
2396*700637cbSDimitry Andric  }
2397*700637cbSDimitry Andric};
2398*700637cbSDimitry Andric
2399*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
2400*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
2401*700637cbSDimitry Andric  const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
2402*700637cbSDimitry Andric  return __sz == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
2403*700637cbSDimitry Andric}
2404*700637cbSDimitry Andric
2405*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
2406*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
2407*700637cbSDimitry Andric  return !(__x == __y);
2408*700637cbSDimitry Andric}
2409*700637cbSDimitry Andric
2410*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
2411*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator<(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
2412*700637cbSDimitry Andric  return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
2413*700637cbSDimitry Andric}
2414*700637cbSDimitry Andric
2415*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
2416*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator>(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
2417*700637cbSDimitry Andric  return __y < __x;
2418*700637cbSDimitry Andric}
2419*700637cbSDimitry Andric
2420*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
2421*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
2422*700637cbSDimitry Andric  return !(__x < __y);
2423*700637cbSDimitry Andric}
2424*700637cbSDimitry Andric
2425*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
2426*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
2427*700637cbSDimitry Andric  return !(__y < __x);
2428*700637cbSDimitry Andric}
2429*700637cbSDimitry Andric
2430*700637cbSDimitry Andrictemplate <class _Tp, class _Allocator>
2431*700637cbSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) {
2432*700637cbSDimitry Andric  __x.swap(__y);
2433*700637cbSDimitry Andric}
2434*700637cbSDimitry Andric
2435*700637cbSDimitry Andric_LIBCPP_END_NAMESPACE_STD
2436*700637cbSDimitry Andric
2437*700637cbSDimitry Andric_LIBCPP_POP_MACROS
2438*700637cbSDimitry Andric
2439*700637cbSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
2440*700637cbSDimitry Andric#  include <__cxx03/algorithm>
2441*700637cbSDimitry Andric#  include <__cxx03/atomic>
2442*700637cbSDimitry Andric#  include <__cxx03/cstdlib>
2443*700637cbSDimitry Andric#  include <__cxx03/iosfwd>
2444*700637cbSDimitry Andric#  if !defined(_LIBCPP_HAS_NO_LOCALIZATION)
2445*700637cbSDimitry Andric#    include <__cxx03/locale>
2446*700637cbSDimitry Andric#  endif
2447*700637cbSDimitry Andric#  include <__cxx03/type_traits>
2448*700637cbSDimitry Andric#  include <__cxx03/typeinfo>
2449*700637cbSDimitry Andric#  include <__cxx03/utility>
2450*700637cbSDimitry Andric#endif
2451*700637cbSDimitry Andric
2452*700637cbSDimitry Andric#endif // _LIBCPP___CXX03_VECTOR
2453