vector revision 227825
1227825Stheraven// -*- C++ -*-
2227825Stheraven//===------------------------------ vector --------------------------------===//
3227825Stheraven//
4227825Stheraven//                     The LLVM Compiler Infrastructure
5227825Stheraven//
6227825Stheraven// This file is dual licensed under the MIT and the University of Illinois Open
7227825Stheraven// Source Licenses. See LICENSE.TXT for details.
8227825Stheraven//
9227825Stheraven//===----------------------------------------------------------------------===//
10227825Stheraven
11227825Stheraven#ifndef _LIBCPP_VECTOR
12227825Stheraven#define _LIBCPP_VECTOR
13227825Stheraven
14227825Stheraven/*
15227825Stheraven    vector synopsis
16227825Stheraven
17227825Stheravennamespace std
18227825Stheraven{
19227825Stheraven
20227825Stheraventemplate <class T, class Allocator = allocator<T> >
21227825Stheravenclass vector
22227825Stheraven{
23227825Stheravenpublic:
24227825Stheraven    typedef T                                        value_type;
25227825Stheraven    typedef Allocator                                allocator_type;
26227825Stheraven    typedef typename allocator_type::reference       reference;
27227825Stheraven    typedef typename allocator_type::const_reference const_reference;
28227825Stheraven    typedef implementation-defined                   iterator;
29227825Stheraven    typedef implementation-defined                   const_iterator;
30227825Stheraven    typedef typename allocator_type::size_type       size_type;
31227825Stheraven    typedef typename allocator_type::difference_type difference_type;
32227825Stheraven    typedef typename allocator_type::pointer         pointer;
33227825Stheraven    typedef typename allocator_type::const_pointer   const_pointer;
34227825Stheraven    typedef std::reverse_iterator<iterator>          reverse_iterator;
35227825Stheraven    typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
36227825Stheraven
37227825Stheraven    vector()
38227825Stheraven        noexcept(is_nothrow_default_constructible<allocator_type>::value);
39227825Stheraven    explicit vector(const allocator_type&);
40227825Stheraven    explicit vector(size_type n);
41227825Stheraven    vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
42227825Stheraven    template <class InputIterator>
43227825Stheraven        vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
44227825Stheraven    vector(const vector& x);
45227825Stheraven    vector(vector&& x)
46227825Stheraven        noexcept(is_nothrow_move_constructible<allocator_type>::value);
47227825Stheraven    vector(initializer_list<value_type> il);
48227825Stheraven    vector(initializer_list<value_type> il, const allocator_type& a);
49227825Stheraven    ~vector();
50227825Stheraven    vector& operator=(const vector& x);
51227825Stheraven    vector& operator=(vector&& x)
52227825Stheraven        noexcept(
53227825Stheraven             allocator_type::propagate_on_container_move_assignment::value &&
54227825Stheraven             is_nothrow_move_assignable<allocator_type>::value);
55227825Stheraven    vector& operator=(initializer_list<value_type> il);
56227825Stheraven    template <class InputIterator>
57227825Stheraven        void assign(InputIterator first, InputIterator last);
58227825Stheraven    void assign(size_type n, const value_type& u);
59227825Stheraven    void assign(initializer_list<value_type> il);
60227825Stheraven
61227825Stheraven    allocator_type get_allocator() const noexcept;
62227825Stheraven
63227825Stheraven    iterator               begin() noexcept;
64227825Stheraven    const_iterator         begin()   const noexcept;
65227825Stheraven    iterator               end() noexcept;
66227825Stheraven    const_iterator         end()     const noexcept;
67227825Stheraven
68227825Stheraven    reverse_iterator       rbegin() noexcept;
69227825Stheraven    const_reverse_iterator rbegin()  const noexcept;
70227825Stheraven    reverse_iterator       rend() noexcept;
71227825Stheraven    const_reverse_iterator rend()    const noexcept;
72227825Stheraven
73227825Stheraven    const_iterator         cbegin()  const noexcept;
74227825Stheraven    const_iterator         cend()    const noexcept;
75227825Stheraven    const_reverse_iterator crbegin() const noexcept;
76227825Stheraven    const_reverse_iterator crend()   const noexcept;
77227825Stheraven
78227825Stheraven    size_type size() const noexcept;
79227825Stheraven    size_type max_size() const noexcept;
80227825Stheraven    size_type capacity() const noexcept;
81227825Stheraven    bool empty() const noexcept;
82227825Stheraven    void reserve(size_type n);
83227825Stheraven    void shrink_to_fit() noexcept;
84227825Stheraven
85227825Stheraven    reference       operator[](size_type n);
86227825Stheraven    const_reference operator[](size_type n) const;
87227825Stheraven    reference       at(size_type n);
88227825Stheraven    const_reference at(size_type n) const;
89227825Stheraven
90227825Stheraven    reference       front();
91227825Stheraven    const_reference front() const;
92227825Stheraven    reference       back();
93227825Stheraven    const_reference back() const;
94227825Stheraven
95227825Stheraven    value_type*       data() noexcept;
96227825Stheraven    const value_type* data() const noexcept;
97227825Stheraven
98227825Stheraven    void push_back(const value_type& x);
99227825Stheraven    void push_back(value_type&& x);
100227825Stheraven    template <class... Args>
101227825Stheraven        void emplace_back(Args&&... args);
102227825Stheraven    void pop_back();
103227825Stheraven
104227825Stheraven    template <class... Args> iterator emplace(const_iterator position, Args&&... args);
105227825Stheraven    iterator insert(const_iterator position, const value_type& x);
106227825Stheraven    iterator insert(const_iterator position, value_type&& x);
107227825Stheraven    iterator insert(const_iterator position, size_type n, const value_type& x);
108227825Stheraven    template <class InputIterator>
109227825Stheraven        iterator insert(const_iterator position, InputIterator first, InputIterator last);
110227825Stheraven    iterator insert(const_iterator position, initializer_list<value_type> il);
111227825Stheraven
112227825Stheraven    iterator erase(const_iterator position);
113227825Stheraven    iterator erase(const_iterator first, const_iterator last);
114227825Stheraven
115227825Stheraven    void clear() noexcept;
116227825Stheraven
117227825Stheraven    void resize(size_type sz);
118227825Stheraven    void resize(size_type sz, const value_type& c);
119227825Stheraven
120227825Stheraven    void swap(vector&)
121227825Stheraven        noexcept(!allocator_type::propagate_on_container_swap::value ||
122227825Stheraven                 __is_nothrow_swappable<allocator_type>::value);
123227825Stheraven
124227825Stheraven    bool __invariants() const;
125227825Stheraven};
126227825Stheraven
127227825Stheraventemplate <class Allocator = allocator<T> >
128227825Stheravenclass vector<bool, Allocator>
129227825Stheraven{
130227825Stheravenpublic:
131227825Stheraven    typedef bool                                     value_type;
132227825Stheraven    typedef Allocator                                allocator_type;
133227825Stheraven    typedef implementation-defined                   iterator;
134227825Stheraven    typedef implementation-defined                   const_iterator;
135227825Stheraven    typedef typename allocator_type::size_type       size_type;
136227825Stheraven    typedef typename allocator_type::difference_type difference_type;
137227825Stheraven    typedef iterator                                 pointer;
138227825Stheraven    typedef const_iterator                           const_pointer;
139227825Stheraven    typedef std::reverse_iterator<iterator>          reverse_iterator;
140227825Stheraven    typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
141227825Stheraven
142227825Stheraven    class reference
143227825Stheraven    {
144227825Stheraven    public:
145227825Stheraven        reference(const reference&) noexcept;
146227825Stheraven        operator bool() const noexcept;
147227825Stheraven        reference& operator=(const bool x) noexcept;
148227825Stheraven        reference& operator=(const reference& x) noexcept;
149227825Stheraven        iterator operator&() const noexcept;
150227825Stheraven        void flip() noexcept;
151227825Stheraven    };
152227825Stheraven
153227825Stheraven    class const_reference
154227825Stheraven    {
155227825Stheraven    public:
156227825Stheraven        const_reference(const reference&) noexcept;
157227825Stheraven        operator bool() const noexcept;
158227825Stheraven        const_iterator operator&() const noexcept;
159227825Stheraven    };
160227825Stheraven
161227825Stheraven    vector()
162227825Stheraven        noexcept(is_nothrow_default_constructible<allocator_type>::value);
163227825Stheraven    explicit vector(const allocator_type&);
164227825Stheraven    explicit vector(size_type n, const value_type& value = value_type(), const allocator_type& = allocator_type());
165227825Stheraven    template <class InputIterator>
166227825Stheraven        vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
167227825Stheraven    vector(const vector& x);
168227825Stheraven    vector(vector&& x)
169227825Stheraven        noexcept(is_nothrow_move_constructible<allocator_type>::value);
170227825Stheraven    vector(initializer_list<value_type> il);
171227825Stheraven    vector(initializer_list<value_type> il, const allocator_type& a);
172227825Stheraven    ~vector();
173227825Stheraven    vector& operator=(const vector& x);
174227825Stheraven    vector& operator=(vector&& x)
175227825Stheraven        noexcept(
176227825Stheraven             allocator_type::propagate_on_container_move_assignment::value &&
177227825Stheraven             is_nothrow_move_assignable<allocator_type>::value);
178227825Stheraven    vector& operator=(initializer_list<value_type> il);
179227825Stheraven    template <class InputIterator>
180227825Stheraven        void assign(InputIterator first, InputIterator last);
181227825Stheraven    void assign(size_type n, const value_type& u);
182227825Stheraven    void assign(initializer_list<value_type> il);
183227825Stheraven
184227825Stheraven    allocator_type get_allocator() const noexcept;
185227825Stheraven
186227825Stheraven    iterator               begin() noexcept;
187227825Stheraven    const_iterator         begin()   const noexcept;
188227825Stheraven    iterator               end() noexcept;
189227825Stheraven    const_iterator         end()     const noexcept;
190227825Stheraven
191227825Stheraven    reverse_iterator       rbegin() noexcept;
192227825Stheraven    const_reverse_iterator rbegin()  const noexcept;
193227825Stheraven    reverse_iterator       rend() noexcept;
194227825Stheraven    const_reverse_iterator rend()    const noexcept;
195227825Stheraven
196227825Stheraven    const_iterator         cbegin()  const noexcept;
197227825Stheraven    const_iterator         cend()    const noexcept;
198227825Stheraven    const_reverse_iterator crbegin() const noexcept;
199227825Stheraven    const_reverse_iterator crend()   const noexcept;
200227825Stheraven
201227825Stheraven    size_type size() const noexcept;
202227825Stheraven    size_type max_size() const noexcept;
203227825Stheraven    size_type capacity() const noexcept;
204227825Stheraven    bool empty() const noexcept;
205227825Stheraven    void reserve(size_type n);
206227825Stheraven    void shrink_to_fit() noexcept;
207227825Stheraven
208227825Stheraven    reference       operator[](size_type n);
209227825Stheraven    const_reference operator[](size_type n) const;
210227825Stheraven    reference       at(size_type n);
211227825Stheraven    const_reference at(size_type n) const;
212227825Stheraven
213227825Stheraven    reference       front();
214227825Stheraven    const_reference front() const;
215227825Stheraven    reference       back();
216227825Stheraven    const_reference back() const;
217227825Stheraven
218227825Stheraven    void push_back(const value_type& x);
219227825Stheraven    void pop_back();
220227825Stheraven
221227825Stheraven    iterator insert(const_iterator position, const value_type& x);
222227825Stheraven    iterator insert(const_iterator position, size_type n, const value_type& x);
223227825Stheraven    template <class InputIterator>
224227825Stheraven        iterator insert(const_iterator position, InputIterator first, InputIterator last);
225227825Stheraven    iterator insert(const_iterator position, initializer_list<value_type> il);
226227825Stheraven
227227825Stheraven    iterator erase(const_iterator position);
228227825Stheraven    iterator erase(const_iterator first, const_iterator last);
229227825Stheraven
230227825Stheraven    void clear() noexcept;
231227825Stheraven
232227825Stheraven    void resize(size_type sz);
233227825Stheraven    void resize(size_type sz, value_type x);
234227825Stheraven
235227825Stheraven    void swap(vector&)
236227825Stheraven        noexcept(!allocator_type::propagate_on_container_swap::value ||
237227825Stheraven                 __is_nothrow_swappable<allocator_type>::value);
238227825Stheraven    void flip() noexcept;
239227825Stheraven
240227825Stheraven    bool __invariants() const;
241227825Stheraven};
242227825Stheraven
243227825Stheraventemplate <class Allocator> struct hash<std::vector<bool, Allocator>>;
244227825Stheraven
245227825Stheraventemplate <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
246227825Stheraventemplate <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
247227825Stheraventemplate <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
248227825Stheraventemplate <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
249227825Stheraventemplate <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
250227825Stheraventemplate <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
251227825Stheraven
252227825Stheraventemplate <class T, class Allocator>
253227825Stheravenvoid swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
254227825Stheraven    noexcept(noexcept(x.swap(y)));
255227825Stheraven
256227825Stheraven}  // std
257227825Stheraven
258227825Stheraven*/
259227825Stheraven
260227825Stheraven#include <__config>
261227825Stheraven#include <__bit_reference>
262227825Stheraven#include <type_traits>
263227825Stheraven#include <climits>
264227825Stheraven#include <limits>
265227825Stheraven#include <initializer_list>
266227825Stheraven#include <memory>
267227825Stheraven#include <stdexcept>
268227825Stheraven#include <algorithm>
269227825Stheraven#include <cstring>
270227825Stheraven#include <__split_buffer>
271227825Stheraven#include <__functional_base>
272227825Stheraven
273227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
274227825Stheraven#pragma GCC system_header
275227825Stheraven#endif
276227825Stheraven
277227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD
278227825Stheraven
279227825Stheraventemplate <bool>
280227825Stheravenclass __vector_base_common
281227825Stheraven{
282227825Stheravenprotected:
283227825Stheraven    _LIBCPP_ALWAYS_INLINE __vector_base_common() {}
284227825Stheraven    void __throw_length_error() const;
285227825Stheraven    void __throw_out_of_range() const;
286227825Stheraven};
287227825Stheraven
288227825Stheraventemplate <bool __b>
289227825Stheravenvoid
290227825Stheraven__vector_base_common<__b>::__throw_length_error() const
291227825Stheraven{
292227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
293227825Stheraven    throw length_error("vector");
294227825Stheraven#else
295227825Stheraven    assert(!"vector length_error");
296227825Stheraven#endif
297227825Stheraven}
298227825Stheraven
299227825Stheraventemplate <bool __b>
300227825Stheravenvoid
301227825Stheraven__vector_base_common<__b>::__throw_out_of_range() const
302227825Stheraven{
303227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
304227825Stheraven    throw out_of_range("vector");
305227825Stheraven#else
306227825Stheraven    assert(!"vector out_of_range");
307227825Stheraven#endif
308227825Stheraven}
309227825Stheraven
310227825Stheraven#ifdef _MSC_VER
311227825Stheraven#pragma warning( push )
312227825Stheraven#pragma warning( disable: 4231 )
313227825Stheraven#endif // _MSC_VER
314227825Stheravenextern template class __vector_base_common<true>;
315227825Stheraven#ifdef _MSC_VER
316227825Stheraven#pragma warning( pop )
317227825Stheraven#endif // _MSC_VER
318227825Stheraven
319227825Stheraventemplate <class _Tp, class _Allocator>
320227825Stheravenclass __vector_base
321227825Stheraven    : protected __vector_base_common<true>
322227825Stheraven{
323227825Stheravenprotected:
324227825Stheraven    typedef _Tp                                      value_type;
325227825Stheraven    typedef _Allocator                               allocator_type;
326227825Stheraven    typedef allocator_traits<allocator_type>         __alloc_traits;
327227825Stheraven    typedef value_type&                              reference;
328227825Stheraven    typedef const value_type&                        const_reference;
329227825Stheraven    typedef typename __alloc_traits::size_type       size_type;
330227825Stheraven    typedef typename __alloc_traits::difference_type difference_type;
331227825Stheraven    typedef typename __alloc_traits::pointer         pointer;
332227825Stheraven    typedef typename __alloc_traits::const_pointer   const_pointer;
333227825Stheraven    typedef pointer                                  iterator;
334227825Stheraven    typedef const_pointer                            const_iterator;
335227825Stheraven
336227825Stheraven    pointer                                         __begin_;
337227825Stheraven    pointer                                         __end_;
338227825Stheraven    __compressed_pair<pointer, allocator_type> __end_cap_;
339227825Stheraven
340227825Stheraven    _LIBCPP_INLINE_VISIBILITY
341227825Stheraven    allocator_type& __alloc() _NOEXCEPT
342227825Stheraven        {return __end_cap_.second();}
343227825Stheraven    _LIBCPP_INLINE_VISIBILITY
344227825Stheraven    const allocator_type& __alloc() const _NOEXCEPT
345227825Stheraven        {return __end_cap_.second();}
346227825Stheraven    _LIBCPP_INLINE_VISIBILITY
347227825Stheraven    pointer& __end_cap() _NOEXCEPT
348227825Stheraven        {return __end_cap_.first();}
349227825Stheraven    _LIBCPP_INLINE_VISIBILITY
350227825Stheraven    const pointer& __end_cap() const _NOEXCEPT
351227825Stheraven        {return __end_cap_.first();}
352227825Stheraven
353227825Stheraven    _LIBCPP_INLINE_VISIBILITY
354227825Stheraven    __vector_base()
355227825Stheraven        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
356227825Stheraven    _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
357227825Stheraven    ~__vector_base();
358227825Stheraven
359227825Stheraven    _LIBCPP_INLINE_VISIBILITY
360227825Stheraven    void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
361227825Stheraven    _LIBCPP_INLINE_VISIBILITY
362227825Stheraven    size_type capacity() const _NOEXCEPT
363227825Stheraven        {return static_cast<size_type>(__end_cap() - __begin_);}
364227825Stheraven
365227825Stheraven    _LIBCPP_INLINE_VISIBILITY
366227825Stheraven    void __destruct_at_end(const_pointer __new_last) _NOEXCEPT
367227825Stheraven        {__destruct_at_end(__new_last, is_trivially_destructible<value_type>());}
368227825Stheraven    _LIBCPP_INLINE_VISIBILITY
369227825Stheraven    void __destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT;
370227825Stheraven    _LIBCPP_INLINE_VISIBILITY
371227825Stheraven    void __destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT;
372227825Stheraven
373227825Stheraven    _LIBCPP_INLINE_VISIBILITY
374227825Stheraven    void __copy_assign_alloc(const __vector_base& __c)
375227825Stheraven        {__copy_assign_alloc(__c, integral_constant<bool,
376227825Stheraven                      __alloc_traits::propagate_on_container_copy_assignment::value>());}
377227825Stheraven
378227825Stheraven    _LIBCPP_INLINE_VISIBILITY
379227825Stheraven    void __move_assign_alloc(__vector_base& __c)
380227825Stheraven        _NOEXCEPT_(
381227825Stheraven            !__alloc_traits::propagate_on_container_move_assignment::value ||
382227825Stheraven            is_nothrow_move_assignable<allocator_type>::value)
383227825Stheraven        {__move_assign_alloc(__c, integral_constant<bool,
384227825Stheraven                      __alloc_traits::propagate_on_container_move_assignment::value>());}
385227825Stheraven
386227825Stheraven    _LIBCPP_INLINE_VISIBILITY
387227825Stheraven    static void __swap_alloc(allocator_type& __x, allocator_type& __y)
388227825Stheraven        _NOEXCEPT_(
389227825Stheraven            !__alloc_traits::propagate_on_container_swap::value ||
390227825Stheraven            __is_nothrow_swappable<allocator_type>::value)
391227825Stheraven        {__swap_alloc(__x, __y, integral_constant<bool,
392227825Stheraven                      __alloc_traits::propagate_on_container_swap::value>());}
393227825Stheravenprivate:
394227825Stheraven    _LIBCPP_INLINE_VISIBILITY
395227825Stheraven    void __copy_assign_alloc(const __vector_base& __c, true_type)
396227825Stheraven        {
397227825Stheraven            if (__alloc() != __c.__alloc())
398227825Stheraven            {
399227825Stheraven                clear();
400227825Stheraven                __alloc_traits::deallocate(__alloc(), __begin_, capacity());
401227825Stheraven                __begin_ = __end_ = __end_cap() = nullptr;
402227825Stheraven            }
403227825Stheraven            __alloc() = __c.__alloc();
404227825Stheraven        }
405227825Stheraven
406227825Stheraven    _LIBCPP_INLINE_VISIBILITY
407227825Stheraven    void __copy_assign_alloc(const __vector_base& __c, false_type)
408227825Stheraven        {}
409227825Stheraven
410227825Stheraven    _LIBCPP_INLINE_VISIBILITY
411227825Stheraven    void __move_assign_alloc(__vector_base& __c, true_type)
412227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
413227825Stheraven        {
414227825Stheraven            __alloc() = _VSTD::move(__c.__alloc());
415227825Stheraven        }
416227825Stheraven
417227825Stheraven    _LIBCPP_INLINE_VISIBILITY
418227825Stheraven    void __move_assign_alloc(__vector_base& __c, false_type)
419227825Stheraven        _NOEXCEPT
420227825Stheraven        {}
421227825Stheraven
422227825Stheraven    _LIBCPP_INLINE_VISIBILITY
423227825Stheraven    static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
424227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
425227825Stheraven        {
426227825Stheraven            using _VSTD::swap;
427227825Stheraven            swap(__x, __y);
428227825Stheraven        }
429227825Stheraven    _LIBCPP_INLINE_VISIBILITY
430227825Stheraven    static void __swap_alloc(allocator_type& __x, allocator_type& __y, false_type)
431227825Stheraven        _NOEXCEPT
432227825Stheraven        {}
433227825Stheraven};
434227825Stheraven
435227825Stheraventemplate <class _Tp, class _Allocator>
436227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
437227825Stheravenvoid
438227825Stheraven__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT
439227825Stheraven{
440227825Stheraven    while (__new_last < __end_)
441227825Stheraven        __alloc_traits::destroy(__alloc(), const_cast<pointer>(--__end_));
442227825Stheraven}
443227825Stheraven
444227825Stheraventemplate <class _Tp, class _Allocator>
445227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
446227825Stheravenvoid
447227825Stheraven__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT
448227825Stheraven{
449227825Stheraven    __end_ = const_cast<pointer>(__new_last);
450227825Stheraven}
451227825Stheraven
452227825Stheraventemplate <class _Tp, class _Allocator>
453227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
454227825Stheraven__vector_base<_Tp, _Allocator>::__vector_base()
455227825Stheraven        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
456227825Stheraven    : __begin_(0),
457227825Stheraven      __end_(0),
458227825Stheraven      __end_cap_(0)
459227825Stheraven{
460227825Stheraven}
461227825Stheraven
462227825Stheraventemplate <class _Tp, class _Allocator>
463227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
464227825Stheraven__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
465227825Stheraven    : __begin_(0),
466227825Stheraven      __end_(0),
467227825Stheraven      __end_cap_(0, __a)
468227825Stheraven{
469227825Stheraven}
470227825Stheraven
471227825Stheraventemplate <class _Tp, class _Allocator>
472227825Stheraven__vector_base<_Tp, _Allocator>::~__vector_base()
473227825Stheraven{
474227825Stheraven    if (__begin_ != 0)
475227825Stheraven    {
476227825Stheraven        clear();
477227825Stheraven        __alloc_traits::deallocate(__alloc(), __begin_, capacity());
478227825Stheraven    }
479227825Stheraven}
480227825Stheraven
481227825Stheraventemplate <class _Tp, class _Allocator = allocator<_Tp> >
482227825Stheravenclass _LIBCPP_VISIBLE vector
483227825Stheraven    : private __vector_base<_Tp, _Allocator>
484227825Stheraven{
485227825Stheravenprivate:
486227825Stheraven    typedef __vector_base<_Tp, _Allocator>           __base;
487227825Stheravenpublic:
488227825Stheraven    typedef vector                                   __self;
489227825Stheraven    typedef _Tp                                      value_type;
490227825Stheraven    typedef _Allocator                               allocator_type;
491227825Stheraven    typedef typename __base::__alloc_traits          __alloc_traits;
492227825Stheraven    typedef typename __base::reference               reference;
493227825Stheraven    typedef typename __base::const_reference         const_reference;
494227825Stheraven    typedef typename __base::size_type               size_type;
495227825Stheraven    typedef typename __base::difference_type         difference_type;
496227825Stheraven    typedef typename __base::pointer                 pointer;
497227825Stheraven    typedef typename __base::const_pointer           const_pointer;
498227825Stheraven    typedef __wrap_iter<pointer>                     iterator;
499227825Stheraven    typedef __wrap_iter<const_pointer>               const_iterator;
500227825Stheraven    typedef _VSTD::reverse_iterator<iterator>         reverse_iterator;
501227825Stheraven    typedef _VSTD::reverse_iterator<const_iterator>   const_reverse_iterator;
502227825Stheraven
503227825Stheraven    _LIBCPP_INLINE_VISIBILITY
504227825Stheraven    vector()
505227825Stheraven        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
506227825Stheraven        {
507227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
508227825Stheraven            __get_db()->__insert_c(this);
509227825Stheraven#endif
510227825Stheraven        }
511227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
512227825Stheraven        : __base(__a)
513227825Stheraven    {
514227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
515227825Stheraven        __get_db()->__insert_c(this);
516227825Stheraven#endif
517227825Stheraven    }
518227825Stheraven    explicit vector(size_type __n);
519227825Stheraven    vector(size_type __n, const_reference __x);
520227825Stheraven    vector(size_type __n, const_reference __x, const allocator_type& __a);
521227825Stheraven    template <class _InputIterator>
522227825Stheraven        vector(_InputIterator __first, _InputIterator __last,
523227825Stheraven               typename enable_if<__is_input_iterator  <_InputIterator>::value &&
524227825Stheraven                                 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
525227825Stheraven    template <class _InputIterator>
526227825Stheraven        vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
527227825Stheraven               typename enable_if<__is_input_iterator  <_InputIterator>::value &&
528227825Stheraven                                 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
529227825Stheraven    template <class _ForwardIterator>
530227825Stheraven        vector(_ForwardIterator __first, _ForwardIterator __last,
531227825Stheraven               typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
532227825Stheraven    template <class _ForwardIterator>
533227825Stheraven        vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
534227825Stheraven               typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
535227825Stheraven#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
536227825Stheraven    _LIBCPP_INLINE_VISIBILITY
537227825Stheraven    vector(initializer_list<value_type> __il);
538227825Stheraven    _LIBCPP_INLINE_VISIBILITY
539227825Stheraven    vector(initializer_list<value_type> __il, const allocator_type& __a);
540227825Stheraven#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
541227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
542227825Stheraven    _LIBCPP_INLINE_VISIBILITY
543227825Stheraven    ~vector()
544227825Stheraven    {
545227825Stheraven        __get_db()->__erase_c(this);
546227825Stheraven    }
547227825Stheraven#endif
548227825Stheraven
549227825Stheraven    vector(const vector& __x);
550227825Stheraven    vector(const vector& __x, const allocator_type& __a);
551227825Stheraven    _LIBCPP_INLINE_VISIBILITY
552227825Stheraven    vector& operator=(const vector& __x);
553227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
554227825Stheraven    _LIBCPP_INLINE_VISIBILITY
555227825Stheraven    vector(vector&& __x)
556227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
557227825Stheraven    _LIBCPP_INLINE_VISIBILITY
558227825Stheraven    vector(vector&& __x, const allocator_type& __a);
559227825Stheraven    _LIBCPP_INLINE_VISIBILITY
560227825Stheraven    vector& operator=(vector&& __x)
561227825Stheraven        _NOEXCEPT_(
562227825Stheraven             __alloc_traits::propagate_on_container_move_assignment::value &&
563227825Stheraven             is_nothrow_move_assignable<allocator_type>::value);
564227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
565227825Stheraven#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
566227825Stheraven    _LIBCPP_INLINE_VISIBILITY
567227825Stheraven    vector& operator=(initializer_list<value_type> __il)
568227825Stheraven        {assign(__il.begin(), __il.end()); return *this;}
569227825Stheraven#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
570227825Stheraven
571227825Stheraven    template <class _InputIterator>
572227825Stheraven        typename enable_if
573227825Stheraven        <
574227825Stheraven             __is_input_iterator  <_InputIterator>::value &&
575227825Stheraven            !__is_forward_iterator<_InputIterator>::value,
576227825Stheraven            void
577227825Stheraven        >::type
578227825Stheraven        assign(_InputIterator __first, _InputIterator __last);
579227825Stheraven    template <class _ForwardIterator>
580227825Stheraven        typename enable_if
581227825Stheraven        <
582227825Stheraven            __is_forward_iterator<_ForwardIterator>::value,
583227825Stheraven            void
584227825Stheraven        >::type
585227825Stheraven        assign(_ForwardIterator __first, _ForwardIterator __last);
586227825Stheraven
587227825Stheraven    void assign(size_type __n, const_reference __u);
588227825Stheraven#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
589227825Stheraven    _LIBCPP_INLINE_VISIBILITY
590227825Stheraven    void assign(initializer_list<value_type> __il)
591227825Stheraven        {assign(__il.begin(), __il.end());}
592227825Stheraven#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
593227825Stheraven
594227825Stheraven    _LIBCPP_INLINE_VISIBILITY
595227825Stheraven    allocator_type get_allocator() const _NOEXCEPT
596227825Stheraven        {return this->__alloc();}
597227825Stheraven
598227825Stheraven    _LIBCPP_INLINE_VISIBILITY iterator               begin() _NOEXCEPT;
599227825Stheraven    _LIBCPP_INLINE_VISIBILITY const_iterator         begin()   const _NOEXCEPT;
600227825Stheraven    _LIBCPP_INLINE_VISIBILITY iterator               end() _NOEXCEPT;
601227825Stheraven    _LIBCPP_INLINE_VISIBILITY const_iterator         end()     const _NOEXCEPT;
602227825Stheraven
603227825Stheraven    _LIBCPP_INLINE_VISIBILITY
604227825Stheraven    reverse_iterator       rbegin() _NOEXCEPT
605227825Stheraven        {return       reverse_iterator(end());}
606227825Stheraven    _LIBCPP_INLINE_VISIBILITY
607227825Stheraven    const_reverse_iterator rbegin()  const _NOEXCEPT
608227825Stheraven        {return const_reverse_iterator(end());}
609227825Stheraven    _LIBCPP_INLINE_VISIBILITY
610227825Stheraven    reverse_iterator       rend() _NOEXCEPT
611227825Stheraven        {return       reverse_iterator(begin());}
612227825Stheraven    _LIBCPP_INLINE_VISIBILITY
613227825Stheraven    const_reverse_iterator rend()    const _NOEXCEPT
614227825Stheraven        {return const_reverse_iterator(begin());}
615227825Stheraven
616227825Stheraven    _LIBCPP_INLINE_VISIBILITY
617227825Stheraven    const_iterator         cbegin()  const _NOEXCEPT
618227825Stheraven        {return begin();}
619227825Stheraven    _LIBCPP_INLINE_VISIBILITY
620227825Stheraven    const_iterator         cend()    const _NOEXCEPT
621227825Stheraven        {return end();}
622227825Stheraven    _LIBCPP_INLINE_VISIBILITY
623227825Stheraven    const_reverse_iterator crbegin() const _NOEXCEPT
624227825Stheraven        {return rbegin();}
625227825Stheraven    _LIBCPP_INLINE_VISIBILITY
626227825Stheraven    const_reverse_iterator crend()   const _NOEXCEPT
627227825Stheraven        {return rend();}
628227825Stheraven
629227825Stheraven    _LIBCPP_INLINE_VISIBILITY
630227825Stheraven    size_type size() const _NOEXCEPT
631227825Stheraven        {return static_cast<size_type>(this->__end_ - this->__begin_);}
632227825Stheraven    _LIBCPP_INLINE_VISIBILITY
633227825Stheraven    size_type capacity() const _NOEXCEPT
634227825Stheraven        {return __base::capacity();}
635227825Stheraven    _LIBCPP_INLINE_VISIBILITY
636227825Stheraven    bool empty() const _NOEXCEPT
637227825Stheraven        {return this->__begin_ == this->__end_;}
638227825Stheraven    size_type max_size() const _NOEXCEPT;
639227825Stheraven    void reserve(size_type __n);
640227825Stheraven    void shrink_to_fit() _NOEXCEPT;
641227825Stheraven
642227825Stheraven    _LIBCPP_INLINE_VISIBILITY reference       operator[](size_type __n);
643227825Stheraven    _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const;
644227825Stheraven    reference       at(size_type __n);
645227825Stheraven    const_reference at(size_type __n) const;
646227825Stheraven
647227825Stheraven    _LIBCPP_INLINE_VISIBILITY reference       front()
648227825Stheraven    {
649227825Stheraven        _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
650227825Stheraven        return *this->__begin_;
651227825Stheraven    }
652227825Stheraven    _LIBCPP_INLINE_VISIBILITY const_reference front() const
653227825Stheraven    {
654227825Stheraven        _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
655227825Stheraven        return *this->__begin_;
656227825Stheraven    }
657227825Stheraven    _LIBCPP_INLINE_VISIBILITY reference       back()
658227825Stheraven    {
659227825Stheraven        _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
660227825Stheraven        return *(this->__end_ - 1);
661227825Stheraven    }
662227825Stheraven    _LIBCPP_INLINE_VISIBILITY const_reference back()  const
663227825Stheraven    {
664227825Stheraven        _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
665227825Stheraven        return *(this->__end_ - 1);
666227825Stheraven    }
667227825Stheraven
668227825Stheraven    _LIBCPP_INLINE_VISIBILITY
669227825Stheraven    value_type*       data() _NOEXCEPT
670227825Stheraven        {return _VSTD::__to_raw_pointer(this->__begin_);}
671227825Stheraven    _LIBCPP_INLINE_VISIBILITY
672227825Stheraven    const value_type* data() const _NOEXCEPT
673227825Stheraven        {return _VSTD::__to_raw_pointer(this->__begin_);}
674227825Stheraven
675227825Stheraven    _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
676227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
677227825Stheraven    void push_back(value_type&& __x);
678227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
679227825Stheraven    template <class... _Args>
680227825Stheraven        void emplace_back(_Args&&... __args);
681227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
682227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
683227825Stheraven    void pop_back();
684227825Stheraven
685227825Stheraven    iterator insert(const_iterator __position, const_reference __x);
686227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
687227825Stheraven    iterator insert(const_iterator __position, value_type&& __x);
688227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
689227825Stheraven    template <class... _Args>
690227825Stheraven        iterator emplace(const_iterator __position, _Args&&... __args);
691227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
692227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
693227825Stheraven    iterator insert(const_iterator __position, size_type __n, const_reference __x);
694227825Stheraven    template <class _InputIterator>
695227825Stheraven        typename enable_if
696227825Stheraven        <
697227825Stheraven             __is_input_iterator  <_InputIterator>::value &&
698227825Stheraven            !__is_forward_iterator<_InputIterator>::value,
699227825Stheraven            iterator
700227825Stheraven        >::type
701227825Stheraven        insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
702227825Stheraven    template <class _ForwardIterator>
703227825Stheraven        typename enable_if
704227825Stheraven        <
705227825Stheraven            __is_forward_iterator<_ForwardIterator>::value,
706227825Stheraven            iterator
707227825Stheraven        >::type
708227825Stheraven        insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
709227825Stheraven#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
710227825Stheraven    _LIBCPP_INLINE_VISIBILITY
711227825Stheraven    iterator insert(const_iterator __position, initializer_list<value_type> __il)
712227825Stheraven        {return insert(__position, __il.begin(), __il.end());}
713227825Stheraven#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
714227825Stheraven
715227825Stheraven    _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
716227825Stheraven    iterator erase(const_iterator __first, const_iterator __last);
717227825Stheraven
718227825Stheraven    _LIBCPP_INLINE_VISIBILITY
719227825Stheraven    void clear() _NOEXCEPT
720227825Stheraven    {
721227825Stheraven        __base::clear();
722227825Stheraven        __invalidate_all_iterators();
723227825Stheraven    }
724227825Stheraven
725227825Stheraven    void resize(size_type __sz);
726227825Stheraven    void resize(size_type __sz, const_reference __x);
727227825Stheraven
728227825Stheraven    void swap(vector&)
729227825Stheraven        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
730227825Stheraven                   __is_nothrow_swappable<allocator_type>::value);
731227825Stheraven
732227825Stheraven    bool __invariants() const;
733227825Stheraven
734227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
735227825Stheraven
736227825Stheraven    bool __dereferenceable(const const_iterator* __i) const;
737227825Stheraven    bool __decrementable(const const_iterator* __i) const;
738227825Stheraven    bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
739227825Stheraven    bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
740227825Stheraven
741227825Stheraven#endif  // _LIBCPP_DEBUG_LEVEL >= 2
742227825Stheraven
743227825Stheravenprivate:
744227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
745227825Stheraven    void allocate(size_type __n);
746227825Stheraven    void deallocate() _NOEXCEPT;
747227825Stheraven    _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
748227825Stheraven    void __construct_at_end(size_type __n);
749227825Stheraven    void __construct_at_end(size_type __n, const_reference __x);
750227825Stheraven    template <class _ForwardIterator>
751227825Stheraven        typename enable_if
752227825Stheraven        <
753227825Stheraven            __is_forward_iterator<_ForwardIterator>::value,
754227825Stheraven            void
755227825Stheraven        >::type
756227825Stheraven        __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
757227825Stheraven    void __move_construct_at_end(pointer __first, pointer __last);
758227825Stheraven    void __append(size_type __n);
759227825Stheraven    void __append(size_type __n, const_reference __x);
760227825Stheraven    _LIBCPP_INLINE_VISIBILITY
761227825Stheraven    iterator       __make_iter(pointer __p) _NOEXCEPT;
762227825Stheraven    _LIBCPP_INLINE_VISIBILITY
763227825Stheraven    const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
764227825Stheraven    void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
765227825Stheraven    pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
766227825Stheraven    void __move_range(pointer __from_s, pointer __from_e, pointer __to);
767227825Stheraven    void __move_assign(vector& __c, true_type)
768227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
769227825Stheraven    void __move_assign(vector& __c, false_type);
770227825Stheraven    _LIBCPP_INLINE_VISIBILITY
771227825Stheraven    void __destruct_at_end(const_pointer __new_last) _NOEXCEPT
772227825Stheraven    {
773227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
774227825Stheraven        __c_node* __c = __get_db()->__find_c_and_lock(this);
775227825Stheraven        for (__i_node** __p = __c->end_; __p != __c->beg_; )
776227825Stheraven        {
777227825Stheraven            --__p;
778227825Stheraven            const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
779227825Stheraven            if (__i->base() > __new_last)
780227825Stheraven            {
781227825Stheraven                (*__p)->__c_ = nullptr;
782227825Stheraven                if (--__c->end_ != __p)
783227825Stheraven                    memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
784227825Stheraven            }
785227825Stheraven        }
786227825Stheraven        __get_db()->unlock();
787227825Stheraven#endif
788227825Stheraven        __base::__destruct_at_end(__new_last);
789227825Stheraven    }
790227825Stheraven};
791227825Stheraven
792227825Stheraventemplate <class _Tp, class _Allocator>
793227825Stheravenvoid
794227825Stheravenvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
795227825Stheraven{
796227825Stheraven    for (pointer __p = this->__end_; this->__begin_ < __p;)
797227825Stheraven        __v.push_front(_VSTD::move_if_noexcept(*--__p));
798227825Stheraven    _VSTD::swap(this->__begin_, __v.__begin_);
799227825Stheraven    _VSTD::swap(this->__end_, __v.__end_);
800227825Stheraven    _VSTD::swap(this->__end_cap(), __v.__end_cap());
801227825Stheraven    __v.__first_ = __v.__begin_;
802227825Stheraven    __invalidate_all_iterators();
803227825Stheraven}
804227825Stheraven
805227825Stheraventemplate <class _Tp, class _Allocator>
806227825Stheraventypename vector<_Tp, _Allocator>::pointer
807227825Stheravenvector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
808227825Stheraven{
809227825Stheraven    pointer __r = __v.__begin_;
810227825Stheraven    for (pointer __i = __p; this->__begin_ < __i;)
811227825Stheraven        __v.push_front(_VSTD::move_if_noexcept(*--__i));
812227825Stheraven    for (pointer __i = __p; __i < this->__end_; ++__i)
813227825Stheraven        __v.push_back(_VSTD::move_if_noexcept(*__i));
814227825Stheraven    _VSTD::swap(this->__begin_, __v.__begin_);
815227825Stheraven    _VSTD::swap(this->__end_, __v.__end_);
816227825Stheraven    _VSTD::swap(this->__end_cap(), __v.__end_cap());
817227825Stheraven    __v.__first_ = __v.__begin_;
818227825Stheraven    __invalidate_all_iterators();
819227825Stheraven    return __r;
820227825Stheraven}
821227825Stheraven
822227825Stheraven//  Allocate space for __n objects
823227825Stheraven//  throws length_error if __n > max_size()
824227825Stheraven//  throws (probably bad_alloc) if memory run out
825227825Stheraven//  Precondition:  __begin_ == __end_ == __end_cap() == 0
826227825Stheraven//  Precondition:  __n > 0
827227825Stheraven//  Postcondition:  capacity() == __n
828227825Stheraven//  Postcondition:  size() == 0
829227825Stheraventemplate <class _Tp, class _Allocator>
830227825Stheravenvoid
831227825Stheravenvector<_Tp, _Allocator>::allocate(size_type __n)
832227825Stheraven{
833227825Stheraven    if (__n > max_size())
834227825Stheraven        this->__throw_length_error();
835227825Stheraven    this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
836227825Stheraven    this->__end_cap() = this->__begin_ + __n;
837227825Stheraven}
838227825Stheraven
839227825Stheraventemplate <class _Tp, class _Allocator>
840227825Stheravenvoid
841227825Stheravenvector<_Tp, _Allocator>::deallocate() _NOEXCEPT
842227825Stheraven{
843227825Stheraven    if (this->__begin_ != 0)
844227825Stheraven    {
845227825Stheraven        clear();
846227825Stheraven        __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
847227825Stheraven        this->__begin_ = this->__end_ = this->__end_cap() = 0;
848227825Stheraven    }
849227825Stheraven}
850227825Stheraven
851227825Stheraventemplate <class _Tp, class _Allocator>
852227825Stheraventypename vector<_Tp, _Allocator>::size_type
853227825Stheravenvector<_Tp, _Allocator>::max_size() const _NOEXCEPT
854227825Stheraven{
855227825Stheraven    return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()), numeric_limits<size_type>::max() / 2);  // end() >= begin(), always
856227825Stheraven}
857227825Stheraven
858227825Stheraven//  Precondition:  __new_size > capacity()
859227825Stheraventemplate <class _Tp, class _Allocator>
860227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
861227825Stheraventypename vector<_Tp, _Allocator>::size_type
862227825Stheravenvector<_Tp, _Allocator>::__recommend(size_type __new_size) const
863227825Stheraven{
864227825Stheraven    const size_type __ms = max_size();
865227825Stheraven    if (__new_size > __ms)
866227825Stheraven        this->__throw_length_error();
867227825Stheraven    const size_type __cap = capacity();
868227825Stheraven    if (__cap >= __ms / 2)
869227825Stheraven        return __ms;
870227825Stheraven    return _VSTD::max<size_type>(2*__cap, __new_size);
871227825Stheraven}
872227825Stheraven
873227825Stheraven//  Default constructs __n objects starting at __end_
874227825Stheraven//  throws if construction throws
875227825Stheraven//  Precondition:  __n > 0
876227825Stheraven//  Precondition:  size() + __n <= capacity()
877227825Stheraven//  Postcondition:  size() == size() + __n
878227825Stheraventemplate <class _Tp, class _Allocator>
879227825Stheravenvoid
880227825Stheravenvector<_Tp, _Allocator>::__construct_at_end(size_type __n)
881227825Stheraven{
882227825Stheraven    allocator_type& __a = this->__alloc();
883227825Stheraven    do
884227825Stheraven    {
885227825Stheraven        __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_));
886227825Stheraven        ++this->__end_;
887227825Stheraven        --__n;
888227825Stheraven    } while (__n > 0);
889227825Stheraven}
890227825Stheraven
891227825Stheraven//  Copy constructs __n objects starting at __end_ from __x
892227825Stheraven//  throws if construction throws
893227825Stheraven//  Precondition:  __n > 0
894227825Stheraven//  Precondition:  size() + __n <= capacity()
895227825Stheraven//  Postcondition:  size() == old size() + __n
896227825Stheraven//  Postcondition:  [i] == __x for all i in [size() - __n, __n)
897227825Stheraventemplate <class _Tp, class _Allocator>
898227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
899227825Stheravenvoid
900227825Stheravenvector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
901227825Stheraven{
902227825Stheraven    allocator_type& __a = this->__alloc();
903227825Stheraven    do
904227825Stheraven    {
905227825Stheraven        __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x);
906227825Stheraven        ++this->__end_;
907227825Stheraven        --__n;
908227825Stheraven    } while (__n > 0);
909227825Stheraven}
910227825Stheraven
911227825Stheraventemplate <class _Tp, class _Allocator>
912227825Stheraventemplate <class _ForwardIterator>
913227825Stheraventypename enable_if
914227825Stheraven<
915227825Stheraven    __is_forward_iterator<_ForwardIterator>::value,
916227825Stheraven    void
917227825Stheraven>::type
918227825Stheravenvector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
919227825Stheraven{
920227825Stheraven    allocator_type& __a = this->__alloc();
921227825Stheraven    for (; __first != __last; ++__first)
922227825Stheraven    {
923227825Stheraven        __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first);
924227825Stheraven        ++this->__end_;
925227825Stheraven    }
926227825Stheraven}
927227825Stheraven
928227825Stheraventemplate <class _Tp, class _Allocator>
929227825Stheravenvoid
930227825Stheravenvector<_Tp, _Allocator>::__move_construct_at_end(pointer __first, pointer __last)
931227825Stheraven{
932227825Stheraven    allocator_type& __a = this->__alloc();
933227825Stheraven    for (; __first != __last; ++__first)
934227825Stheraven    {
935227825Stheraven        __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
936227825Stheraven                                  _VSTD::move(*__first));
937227825Stheraven        ++this->__end_;
938227825Stheraven    }
939227825Stheraven}
940227825Stheraven
941227825Stheraven//  Default constructs __n objects starting at __end_
942227825Stheraven//  throws if construction throws
943227825Stheraven//  Postcondition:  size() == size() + __n
944227825Stheraven//  Exception safety: strong.
945227825Stheraventemplate <class _Tp, class _Allocator>
946227825Stheravenvoid
947227825Stheravenvector<_Tp, _Allocator>::__append(size_type __n)
948227825Stheraven{
949227825Stheraven    if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
950227825Stheraven        this->__construct_at_end(__n);
951227825Stheraven    else
952227825Stheraven    {
953227825Stheraven        allocator_type& __a = this->__alloc();
954227825Stheraven        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
955227825Stheraven        __v.__construct_at_end(__n);
956227825Stheraven        __swap_out_circular_buffer(__v);
957227825Stheraven    }
958227825Stheraven}
959227825Stheraven
960227825Stheraven//  Default constructs __n objects starting at __end_
961227825Stheraven//  throws if construction throws
962227825Stheraven//  Postcondition:  size() == size() + __n
963227825Stheraven//  Exception safety: strong.
964227825Stheraventemplate <class _Tp, class _Allocator>
965227825Stheravenvoid
966227825Stheravenvector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
967227825Stheraven{
968227825Stheraven    if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
969227825Stheraven        this->__construct_at_end(__n, __x);
970227825Stheraven    else
971227825Stheraven    {
972227825Stheraven        allocator_type& __a = this->__alloc();
973227825Stheraven        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
974227825Stheraven        __v.__construct_at_end(__n, __x);
975227825Stheraven        __swap_out_circular_buffer(__v);
976227825Stheraven    }
977227825Stheraven}
978227825Stheraven
979227825Stheraventemplate <class _Tp, class _Allocator>
980227825Stheravenvector<_Tp, _Allocator>::vector(size_type __n)
981227825Stheraven{
982227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
983227825Stheraven    __get_db()->__insert_c(this);
984227825Stheraven#endif
985227825Stheraven    if (__n > 0)
986227825Stheraven    {
987227825Stheraven        allocate(__n);
988227825Stheraven        __construct_at_end(__n);
989227825Stheraven    }
990227825Stheraven}
991227825Stheraven
992227825Stheraventemplate <class _Tp, class _Allocator>
993227825Stheravenvector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
994227825Stheraven{
995227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
996227825Stheraven    __get_db()->__insert_c(this);
997227825Stheraven#endif
998227825Stheraven    if (__n > 0)
999227825Stheraven    {
1000227825Stheraven        allocate(__n);
1001227825Stheraven        __construct_at_end(__n, __x);
1002227825Stheraven    }
1003227825Stheraven}
1004227825Stheraven
1005227825Stheraventemplate <class _Tp, class _Allocator>
1006227825Stheravenvector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a)
1007227825Stheraven    : __base(__a)
1008227825Stheraven{
1009227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1010227825Stheraven    __get_db()->__insert_c(this);
1011227825Stheraven#endif
1012227825Stheraven    if (__n > 0)
1013227825Stheraven    {
1014227825Stheraven        allocate(__n);
1015227825Stheraven        __construct_at_end(__n, __x);
1016227825Stheraven    }
1017227825Stheraven}
1018227825Stheraven
1019227825Stheraventemplate <class _Tp, class _Allocator>
1020227825Stheraventemplate <class _InputIterator>
1021227825Stheravenvector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
1022227825Stheraven       typename enable_if<__is_input_iterator  <_InputIterator>::value &&
1023227825Stheraven                         !__is_forward_iterator<_InputIterator>::value>::type*)
1024227825Stheraven{
1025227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1026227825Stheraven    __get_db()->__insert_c(this);
1027227825Stheraven#endif
1028227825Stheraven    for (; __first != __last; ++__first)
1029227825Stheraven        push_back(*__first);
1030227825Stheraven}
1031227825Stheraven
1032227825Stheraventemplate <class _Tp, class _Allocator>
1033227825Stheraventemplate <class _InputIterator>
1034227825Stheravenvector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1035227825Stheraven       typename enable_if<__is_input_iterator  <_InputIterator>::value &&
1036227825Stheraven                         !__is_forward_iterator<_InputIterator>::value>::type*)
1037227825Stheraven    : __base(__a)
1038227825Stheraven{
1039227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1040227825Stheraven    __get_db()->__insert_c(this);
1041227825Stheraven#endif
1042227825Stheraven    for (; __first != __last; ++__first)
1043227825Stheraven        push_back(*__first);
1044227825Stheraven}
1045227825Stheraven
1046227825Stheraventemplate <class _Tp, class _Allocator>
1047227825Stheraventemplate <class _ForwardIterator>
1048227825Stheravenvector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
1049227825Stheraven                                typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
1050227825Stheraven{
1051227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1052227825Stheraven    __get_db()->__insert_c(this);
1053227825Stheraven#endif
1054227825Stheraven    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
1055227825Stheraven    if (__n > 0)
1056227825Stheraven    {
1057227825Stheraven        allocate(__n);
1058227825Stheraven        __construct_at_end(__first, __last);
1059227825Stheraven    }
1060227825Stheraven}
1061227825Stheraven
1062227825Stheraventemplate <class _Tp, class _Allocator>
1063227825Stheraventemplate <class _ForwardIterator>
1064227825Stheravenvector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
1065227825Stheraven                                typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
1066227825Stheraven    : __base(__a)
1067227825Stheraven{
1068227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1069227825Stheraven    __get_db()->__insert_c(this);
1070227825Stheraven#endif
1071227825Stheraven    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
1072227825Stheraven    if (__n > 0)
1073227825Stheraven    {
1074227825Stheraven        allocate(__n);
1075227825Stheraven        __construct_at_end(__first, __last);
1076227825Stheraven    }
1077227825Stheraven}
1078227825Stheraven
1079227825Stheraventemplate <class _Tp, class _Allocator>
1080227825Stheravenvector<_Tp, _Allocator>::vector(const vector& __x)
1081227825Stheraven    : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
1082227825Stheraven{
1083227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1084227825Stheraven    __get_db()->__insert_c(this);
1085227825Stheraven#endif
1086227825Stheraven    size_type __n = __x.size();
1087227825Stheraven    if (__n > 0)
1088227825Stheraven    {
1089227825Stheraven        allocate(__n);
1090227825Stheraven        __construct_at_end(__x.__begin_, __x.__end_);
1091227825Stheraven    }
1092227825Stheraven}
1093227825Stheraven
1094227825Stheraventemplate <class _Tp, class _Allocator>
1095227825Stheravenvector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
1096227825Stheraven    : __base(__a)
1097227825Stheraven{
1098227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1099227825Stheraven    __get_db()->__insert_c(this);
1100227825Stheraven#endif
1101227825Stheraven    size_type __n = __x.size();
1102227825Stheraven    if (__n > 0)
1103227825Stheraven    {
1104227825Stheraven        allocate(__n);
1105227825Stheraven        __construct_at_end(__x.__begin_, __x.__end_);
1106227825Stheraven    }
1107227825Stheraven}
1108227825Stheraven
1109227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1110227825Stheraven
1111227825Stheraventemplate <class _Tp, class _Allocator>
1112227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
1113227825Stheravenvector<_Tp, _Allocator>::vector(vector&& __x)
1114227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
1115227825Stheraven    : __base(_VSTD::move(__x.__alloc()))
1116227825Stheraven{
1117227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1118227825Stheraven    __get_db()->__insert_c(this);
1119227825Stheraven    __get_db()->swap(this, &__x);
1120227825Stheraven#endif
1121227825Stheraven    this->__begin_ = __x.__begin_;
1122227825Stheraven    this->__end_ = __x.__end_;
1123227825Stheraven    this->__end_cap() = __x.__end_cap();
1124227825Stheraven    __x.__begin_ = __x.__end_ = __x.__end_cap() = 0;
1125227825Stheraven}
1126227825Stheraven
1127227825Stheraventemplate <class _Tp, class _Allocator>
1128227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
1129227825Stheravenvector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
1130227825Stheraven    : __base(__a)
1131227825Stheraven{
1132227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1133227825Stheraven    __get_db()->__insert_c(this);
1134227825Stheraven#endif
1135227825Stheraven    if (__a == __x.__alloc())
1136227825Stheraven    {
1137227825Stheraven        this->__begin_ = __x.__begin_;
1138227825Stheraven        this->__end_ = __x.__end_;
1139227825Stheraven        this->__end_cap() = __x.__end_cap();
1140227825Stheraven        __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1141227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1142227825Stheraven        __get_db()->swap(this, &__x);
1143227825Stheraven#endif
1144227825Stheraven    }
1145227825Stheraven    else
1146227825Stheraven    {
1147227825Stheraven        typedef move_iterator<iterator> _I;
1148227825Stheraven        assign(_I(__x.begin()), _I(__x.end()));
1149227825Stheraven    }
1150227825Stheraven}
1151227825Stheraven
1152227825Stheraven#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1153227825Stheraven
1154227825Stheraventemplate <class _Tp, class _Allocator>
1155227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
1156227825Stheravenvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
1157227825Stheraven{
1158227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1159227825Stheraven    __get_db()->__insert_c(this);
1160227825Stheraven#endif
1161227825Stheraven    if (__il.size() > 0)
1162227825Stheraven    {
1163227825Stheraven        allocate(__il.size());
1164227825Stheraven        __construct_at_end(__il.begin(), __il.end());
1165227825Stheraven    }
1166227825Stheraven}
1167227825Stheraven
1168227825Stheraventemplate <class _Tp, class _Allocator>
1169227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
1170227825Stheravenvector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1171227825Stheraven    : __base(__a)
1172227825Stheraven{
1173227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1174227825Stheraven    __get_db()->__insert_c(this);
1175227825Stheraven#endif
1176227825Stheraven    if (__il.size() > 0)
1177227825Stheraven    {
1178227825Stheraven        allocate(__il.size());
1179227825Stheraven        __construct_at_end(__il.begin(), __il.end());
1180227825Stheraven    }
1181227825Stheraven}
1182227825Stheraven
1183227825Stheraven#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1184227825Stheraven
1185227825Stheraventemplate <class _Tp, class _Allocator>
1186227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
1187227825Stheravenvector<_Tp, _Allocator>&
1188227825Stheravenvector<_Tp, _Allocator>::operator=(vector&& __x)
1189227825Stheraven        _NOEXCEPT_(
1190227825Stheraven             __alloc_traits::propagate_on_container_move_assignment::value &&
1191227825Stheraven             is_nothrow_move_assignable<allocator_type>::value)
1192227825Stheraven{
1193227825Stheraven    __move_assign(__x, integral_constant<bool,
1194227825Stheraven          __alloc_traits::propagate_on_container_move_assignment::value>());
1195227825Stheraven    return *this;
1196227825Stheraven}
1197227825Stheraven
1198227825Stheraventemplate <class _Tp, class _Allocator>
1199227825Stheravenvoid
1200227825Stheravenvector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
1201227825Stheraven{
1202227825Stheraven    if (__base::__alloc() != __c.__alloc())
1203227825Stheraven    {
1204227825Stheraven        typedef move_iterator<iterator> _I;
1205227825Stheraven        assign(_I(__c.begin()), _I(__c.end()));
1206227825Stheraven    }
1207227825Stheraven    else
1208227825Stheraven        __move_assign(__c, true_type());
1209227825Stheraven}
1210227825Stheraven
1211227825Stheraventemplate <class _Tp, class _Allocator>
1212227825Stheravenvoid
1213227825Stheravenvector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
1214227825Stheraven    _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1215227825Stheraven{
1216227825Stheraven    deallocate();
1217227825Stheraven    this->__begin_ = __c.__begin_;
1218227825Stheraven    this->__end_ = __c.__end_;
1219227825Stheraven    this->__end_cap() = __c.__end_cap();
1220227825Stheraven    __base::__move_assign_alloc(__c);
1221227825Stheraven    __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
1222227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1223227825Stheraven    __get_db()->swap(this, &__c);
1224227825Stheraven#endif
1225227825Stheraven}
1226227825Stheraven
1227227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1228227825Stheraven
1229227825Stheraventemplate <class _Tp, class _Allocator>
1230227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
1231227825Stheravenvector<_Tp, _Allocator>&
1232227825Stheravenvector<_Tp, _Allocator>::operator=(const vector& __x)
1233227825Stheraven{
1234227825Stheraven    if (this != &__x)
1235227825Stheraven    {
1236227825Stheraven        __base::__copy_assign_alloc(__x);
1237227825Stheraven        assign(__x.__begin_, __x.__end_);
1238227825Stheraven    }
1239227825Stheraven    return *this;
1240227825Stheraven}
1241227825Stheraven
1242227825Stheraventemplate <class _Tp, class _Allocator>
1243227825Stheraventemplate <class _InputIterator>
1244227825Stheraventypename enable_if
1245227825Stheraven<
1246227825Stheraven     __is_input_iterator  <_InputIterator>::value &&
1247227825Stheraven    !__is_forward_iterator<_InputIterator>::value,
1248227825Stheraven    void
1249227825Stheraven>::type
1250227825Stheravenvector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
1251227825Stheraven{
1252227825Stheraven    clear();
1253227825Stheraven    for (; __first != __last; ++__first)
1254227825Stheraven        push_back(*__first);
1255227825Stheraven}
1256227825Stheraven
1257227825Stheraventemplate <class _Tp, class _Allocator>
1258227825Stheraventemplate <class _ForwardIterator>
1259227825Stheraventypename enable_if
1260227825Stheraven<
1261227825Stheraven    __is_forward_iterator<_ForwardIterator>::value,
1262227825Stheraven    void
1263227825Stheraven>::type
1264227825Stheravenvector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
1265227825Stheraven{
1266227825Stheraven    typename iterator_traits<_ForwardIterator>::difference_type __new_size = _VSTD::distance(__first, __last);
1267227825Stheraven    if (static_cast<size_type>(__new_size) <= capacity())
1268227825Stheraven    {
1269227825Stheraven        _ForwardIterator __mid = __last;
1270227825Stheraven        bool __growing = false;
1271227825Stheraven        if (static_cast<size_type>(__new_size) > size())
1272227825Stheraven        {
1273227825Stheraven            __growing = true;
1274227825Stheraven            __mid =  __first;
1275227825Stheraven            _VSTD::advance(__mid, size());
1276227825Stheraven        }
1277227825Stheraven        pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
1278227825Stheraven        if (__growing)
1279227825Stheraven            __construct_at_end(__mid, __last);
1280227825Stheraven        else
1281227825Stheraven            this->__destruct_at_end(__m);
1282227825Stheraven    }
1283227825Stheraven    else
1284227825Stheraven    {
1285227825Stheraven        deallocate();
1286227825Stheraven        allocate(__recommend(static_cast<size_type>(__new_size)));
1287227825Stheraven        __construct_at_end(__first, __last);
1288227825Stheraven    }
1289227825Stheraven}
1290227825Stheraven
1291227825Stheraventemplate <class _Tp, class _Allocator>
1292227825Stheravenvoid
1293227825Stheravenvector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
1294227825Stheraven{
1295227825Stheraven    if (__n <= capacity())
1296227825Stheraven    {
1297227825Stheraven        size_type __s = size();
1298227825Stheraven        _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
1299227825Stheraven        if (__n > __s)
1300227825Stheraven            __construct_at_end(__n - __s, __u);
1301227825Stheraven        else
1302227825Stheraven            this->__destruct_at_end(this->__begin_ + __n);
1303227825Stheraven    }
1304227825Stheraven    else
1305227825Stheraven    {
1306227825Stheraven        deallocate();
1307227825Stheraven        allocate(__recommend(static_cast<size_type>(__n)));
1308227825Stheraven        __construct_at_end(__n, __u);
1309227825Stheraven    }
1310227825Stheraven}
1311227825Stheraven
1312227825Stheraventemplate <class _Tp, class _Allocator>
1313227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
1314227825Stheraventypename vector<_Tp, _Allocator>::iterator
1315227825Stheravenvector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
1316227825Stheraven{
1317227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1318227825Stheraven    return iterator(this, __p);
1319227825Stheraven#else
1320227825Stheraven    return iterator(__p);
1321227825Stheraven#endif
1322227825Stheraven}
1323227825Stheraven
1324227825Stheraventemplate <class _Tp, class _Allocator>
1325227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
1326227825Stheraventypename vector<_Tp, _Allocator>::const_iterator
1327227825Stheravenvector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
1328227825Stheraven{
1329227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1330227825Stheraven    return const_iterator(this, __p);
1331227825Stheraven#else
1332227825Stheraven    return const_iterator(__p);
1333227825Stheraven#endif
1334227825Stheraven}
1335227825Stheraven
1336227825Stheraventemplate <class _Tp, class _Allocator>
1337227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
1338227825Stheraventypename vector<_Tp, _Allocator>::iterator
1339227825Stheravenvector<_Tp, _Allocator>::begin() _NOEXCEPT
1340227825Stheraven{
1341227825Stheraven    return __make_iter(this->__begin_);
1342227825Stheraven}
1343227825Stheraven
1344227825Stheraventemplate <class _Tp, class _Allocator>
1345227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
1346227825Stheraventypename vector<_Tp, _Allocator>::const_iterator
1347227825Stheravenvector<_Tp, _Allocator>::begin() const _NOEXCEPT
1348227825Stheraven{
1349227825Stheraven    return __make_iter(this->__begin_);
1350227825Stheraven}
1351227825Stheraven
1352227825Stheraventemplate <class _Tp, class _Allocator>
1353227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
1354227825Stheraventypename vector<_Tp, _Allocator>::iterator
1355227825Stheravenvector<_Tp, _Allocator>::end() _NOEXCEPT
1356227825Stheraven{
1357227825Stheraven    return __make_iter(this->__end_);
1358227825Stheraven}
1359227825Stheraven
1360227825Stheraventemplate <class _Tp, class _Allocator>
1361227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
1362227825Stheraventypename vector<_Tp, _Allocator>::const_iterator
1363227825Stheravenvector<_Tp, _Allocator>::end() const _NOEXCEPT
1364227825Stheraven{
1365227825Stheraven    return __make_iter(this->__end_);
1366227825Stheraven}
1367227825Stheraven
1368227825Stheraventemplate <class _Tp, class _Allocator>
1369227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
1370227825Stheraventypename vector<_Tp, _Allocator>::reference
1371227825Stheravenvector<_Tp, _Allocator>::operator[](size_type __n)
1372227825Stheraven{
1373227825Stheraven    _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
1374227825Stheraven    return this->__begin_[__n];
1375227825Stheraven}
1376227825Stheraven
1377227825Stheraventemplate <class _Tp, class _Allocator>
1378227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
1379227825Stheraventypename vector<_Tp, _Allocator>::const_reference
1380227825Stheravenvector<_Tp, _Allocator>::operator[](size_type __n) const
1381227825Stheraven{
1382227825Stheraven    _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
1383227825Stheraven    return this->__begin_[__n];
1384227825Stheraven}
1385227825Stheraven
1386227825Stheraventemplate <class _Tp, class _Allocator>
1387227825Stheraventypename vector<_Tp, _Allocator>::reference
1388227825Stheravenvector<_Tp, _Allocator>::at(size_type __n)
1389227825Stheraven{
1390227825Stheraven    if (__n >= size())
1391227825Stheraven        this->__throw_out_of_range();
1392227825Stheraven    return this->__begin_[__n];
1393227825Stheraven}
1394227825Stheraven
1395227825Stheraventemplate <class _Tp, class _Allocator>
1396227825Stheraventypename vector<_Tp, _Allocator>::const_reference
1397227825Stheravenvector<_Tp, _Allocator>::at(size_type __n) const
1398227825Stheraven{
1399227825Stheraven    if (__n >= size())
1400227825Stheraven        this->__throw_out_of_range();
1401227825Stheraven    return this->__begin_[__n];
1402227825Stheraven}
1403227825Stheraven
1404227825Stheraventemplate <class _Tp, class _Allocator>
1405227825Stheravenvoid
1406227825Stheravenvector<_Tp, _Allocator>::reserve(size_type __n)
1407227825Stheraven{
1408227825Stheraven    if (__n > capacity())
1409227825Stheraven    {
1410227825Stheraven        allocator_type& __a = this->__alloc();
1411227825Stheraven        __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
1412227825Stheraven        __swap_out_circular_buffer(__v);
1413227825Stheraven    }
1414227825Stheraven}
1415227825Stheraven
1416227825Stheraventemplate <class _Tp, class _Allocator>
1417227825Stheravenvoid
1418227825Stheravenvector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
1419227825Stheraven{
1420227825Stheraven    if (capacity() > size())
1421227825Stheraven    {
1422227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
1423227825Stheraven        try
1424227825Stheraven        {
1425227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
1426227825Stheraven            allocator_type& __a = this->__alloc();
1427227825Stheraven            __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
1428227825Stheraven            __swap_out_circular_buffer(__v);
1429227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
1430227825Stheraven        }
1431227825Stheraven        catch (...)
1432227825Stheraven        {
1433227825Stheraven        }
1434227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
1435227825Stheraven    }
1436227825Stheraven}
1437227825Stheraven
1438227825Stheraventemplate <class _Tp, class _Allocator>
1439227825Stheravenvoid
1440227825Stheravenvector<_Tp, _Allocator>::push_back(const_reference __x)
1441227825Stheraven{
1442227825Stheraven    if (this->__end_ < this->__end_cap())
1443227825Stheraven    {
1444227825Stheraven        __alloc_traits::construct(this->__alloc(),
1445227825Stheraven                                  _VSTD::__to_raw_pointer(this->__end_), __x);
1446227825Stheraven        ++this->__end_;
1447227825Stheraven    }
1448227825Stheraven    else
1449227825Stheraven    {
1450227825Stheraven        allocator_type& __a = this->__alloc();
1451227825Stheraven        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1452227825Stheraven        __v.push_back(__x);
1453227825Stheraven        __swap_out_circular_buffer(__v);
1454227825Stheraven    }
1455227825Stheraven}
1456227825Stheraven
1457227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1458227825Stheraven
1459227825Stheraventemplate <class _Tp, class _Allocator>
1460227825Stheravenvoid
1461227825Stheravenvector<_Tp, _Allocator>::push_back(value_type&& __x)
1462227825Stheraven{
1463227825Stheraven    if (this->__end_ < this->__end_cap())
1464227825Stheraven    {
1465227825Stheraven        __alloc_traits::construct(this->__alloc(),
1466227825Stheraven                                  _VSTD::__to_raw_pointer(this->__end_),
1467227825Stheraven                                  _VSTD::move(__x));
1468227825Stheraven        ++this->__end_;
1469227825Stheraven    }
1470227825Stheraven    else
1471227825Stheraven    {
1472227825Stheraven        allocator_type& __a = this->__alloc();
1473227825Stheraven        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1474227825Stheraven        __v.push_back(_VSTD::move(__x));
1475227825Stheraven        __swap_out_circular_buffer(__v);
1476227825Stheraven    }
1477227825Stheraven}
1478227825Stheraven
1479227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
1480227825Stheraven
1481227825Stheraventemplate <class _Tp, class _Allocator>
1482227825Stheraventemplate <class... _Args>
1483227825Stheravenvoid
1484227825Stheravenvector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1485227825Stheraven{
1486227825Stheraven    if (this->__end_ < this->__end_cap())
1487227825Stheraven    {
1488227825Stheraven        __alloc_traits::construct(this->__alloc(),
1489227825Stheraven                                  _VSTD::__to_raw_pointer(this->__end_),
1490227825Stheraven                                  _VSTD::forward<_Args>(__args)...);
1491227825Stheraven        ++this->__end_;
1492227825Stheraven    }
1493227825Stheraven    else
1494227825Stheraven    {
1495227825Stheraven        allocator_type& __a = this->__alloc();
1496227825Stheraven        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1497227825Stheraven        __v.emplace_back(_VSTD::forward<_Args>(__args)...);
1498227825Stheraven        __swap_out_circular_buffer(__v);
1499227825Stheraven    }
1500227825Stheraven}
1501227825Stheraven
1502227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
1503227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1504227825Stheraven
1505227825Stheraventemplate <class _Tp, class _Allocator>
1506227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
1507227825Stheravenvoid
1508227825Stheravenvector<_Tp, _Allocator>::pop_back()
1509227825Stheraven{
1510227825Stheraven    _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector");
1511227825Stheraven    this->__destruct_at_end(this->__end_ - 1);
1512227825Stheraven}
1513227825Stheraven
1514227825Stheraventemplate <class _Tp, class _Allocator>
1515227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
1516227825Stheraventypename vector<_Tp, _Allocator>::iterator
1517227825Stheravenvector<_Tp, _Allocator>::erase(const_iterator __position)
1518227825Stheraven{
1519227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1520227825Stheraven    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1521227825Stheraven        "vector::erase(iterator) called with an iterator not"
1522227825Stheraven        " referring to this vector");
1523227825Stheraven#endif
1524227825Stheraven    pointer __p = const_cast<pointer>(&*__position);
1525227825Stheraven    iterator __r = __make_iter(__p);
1526227825Stheraven    this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
1527227825Stheraven    return __r;
1528227825Stheraven}
1529227825Stheraven
1530227825Stheraventemplate <class _Tp, class _Allocator>
1531227825Stheraventypename vector<_Tp, _Allocator>::iterator
1532227825Stheravenvector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
1533227825Stheraven{
1534227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1535227825Stheraven    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
1536227825Stheraven        "vector::erase(iterator,  iterator) called with an iterator not"
1537227825Stheraven        " referring to this vector");
1538227825Stheraven#endif
1539227825Stheraven    _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
1540227825Stheraven    pointer __p = this->__begin_ + (__first - begin());
1541227825Stheraven    iterator __r = __make_iter(__p);
1542227825Stheraven    this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
1543227825Stheraven    return __r;
1544227825Stheraven}
1545227825Stheraven
1546227825Stheraventemplate <class _Tp, class _Allocator>
1547227825Stheravenvoid
1548227825Stheravenvector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
1549227825Stheraven{
1550227825Stheraven    pointer __old_last = this->__end_;
1551227825Stheraven    difference_type __n = __old_last - __to;
1552227825Stheraven    for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_)
1553227825Stheraven        __alloc_traits::construct(this->__alloc(),
1554227825Stheraven                                  _VSTD::__to_raw_pointer(this->__end_),
1555227825Stheraven                                  _VSTD::move(*__i));
1556227825Stheraven    _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
1557227825Stheraven}
1558227825Stheraven
1559227825Stheraventemplate <class _Tp, class _Allocator>
1560227825Stheraventypename vector<_Tp, _Allocator>::iterator
1561227825Stheravenvector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
1562227825Stheraven{
1563227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1564227825Stheraven    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1565227825Stheraven        "vector::insert(iterator, x) called with an iterator not"
1566227825Stheraven        " referring to this vector");
1567227825Stheraven#endif
1568227825Stheraven    pointer __p = this->__begin_ + (__position - begin());
1569227825Stheraven    if (this->__end_ < this->__end_cap())
1570227825Stheraven    {
1571227825Stheraven        if (__p == this->__end_)
1572227825Stheraven        {
1573227825Stheraven            __alloc_traits::construct(this->__alloc(),
1574227825Stheraven                                      _VSTD::__to_raw_pointer(this->__end_), __x);
1575227825Stheraven            ++this->__end_;
1576227825Stheraven        }
1577227825Stheraven        else
1578227825Stheraven        {
1579227825Stheraven            __move_range(__p, this->__end_, __p + 1);
1580227825Stheraven            const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1581227825Stheraven            if (__p <= __xr && __xr < this->__end_)
1582227825Stheraven                ++__xr;
1583227825Stheraven            *__p = *__xr;
1584227825Stheraven        }
1585227825Stheraven    }
1586227825Stheraven    else
1587227825Stheraven    {
1588227825Stheraven        allocator_type& __a = this->__alloc();
1589227825Stheraven        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1590227825Stheraven        __v.push_back(__x);
1591227825Stheraven        __p = __swap_out_circular_buffer(__v, __p);
1592227825Stheraven    }
1593227825Stheraven    return __make_iter(__p);
1594227825Stheraven}
1595227825Stheraven
1596227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1597227825Stheraven
1598227825Stheraventemplate <class _Tp, class _Allocator>
1599227825Stheraventypename vector<_Tp, _Allocator>::iterator
1600227825Stheravenvector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
1601227825Stheraven{
1602227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1603227825Stheraven    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1604227825Stheraven        "vector::insert(iterator, x) called with an iterator not"
1605227825Stheraven        " referring to this vector");
1606227825Stheraven#endif
1607227825Stheraven    pointer __p = this->__begin_ + (__position - begin());
1608227825Stheraven    if (this->__end_ < this->__end_cap())
1609227825Stheraven    {
1610227825Stheraven        if (__p == this->__end_)
1611227825Stheraven        {
1612227825Stheraven            __alloc_traits::construct(this->__alloc(),
1613227825Stheraven                                      _VSTD::__to_raw_pointer(this->__end_),
1614227825Stheraven                                      _VSTD::move(__x));
1615227825Stheraven            ++this->__end_;
1616227825Stheraven        }
1617227825Stheraven        else
1618227825Stheraven        {
1619227825Stheraven            __move_range(__p, this->__end_, __p + 1);
1620227825Stheraven            *__p = _VSTD::move(__x);
1621227825Stheraven        }
1622227825Stheraven    }
1623227825Stheraven    else
1624227825Stheraven    {
1625227825Stheraven        allocator_type& __a = this->__alloc();
1626227825Stheraven        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1627227825Stheraven        __v.push_back(_VSTD::move(__x));
1628227825Stheraven        __p = __swap_out_circular_buffer(__v, __p);
1629227825Stheraven    }
1630227825Stheraven    return __make_iter(__p);
1631227825Stheraven}
1632227825Stheraven
1633227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
1634227825Stheraven
1635227825Stheraventemplate <class _Tp, class _Allocator>
1636227825Stheraventemplate <class... _Args>
1637227825Stheraventypename vector<_Tp, _Allocator>::iterator
1638227825Stheravenvector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
1639227825Stheraven{
1640227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1641227825Stheraven    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1642227825Stheraven        "vector::emplace(iterator, x) called with an iterator not"
1643227825Stheraven        " referring to this vector");
1644227825Stheraven#endif
1645227825Stheraven    pointer __p = this->__begin_ + (__position - begin());
1646227825Stheraven    if (this->__end_ < this->__end_cap())
1647227825Stheraven    {
1648227825Stheraven        if (__p == this->__end_)
1649227825Stheraven        {
1650227825Stheraven            __alloc_traits::construct(this->__alloc(),
1651227825Stheraven                                      _VSTD::__to_raw_pointer(this->__end_),
1652227825Stheraven                                      _VSTD::forward<_Args>(__args)...);
1653227825Stheraven            ++this->__end_;
1654227825Stheraven        }
1655227825Stheraven        else
1656227825Stheraven        {
1657227825Stheraven            __move_range(__p, this->__end_, __p + 1);
1658227825Stheraven            *__p = value_type(_VSTD::forward<_Args>(__args)...);
1659227825Stheraven        }
1660227825Stheraven    }
1661227825Stheraven    else
1662227825Stheraven    {
1663227825Stheraven        allocator_type& __a = this->__alloc();
1664227825Stheraven        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1665227825Stheraven        __v.emplace_back(_VSTD::forward<_Args>(__args)...);
1666227825Stheraven        __p = __swap_out_circular_buffer(__v, __p);
1667227825Stheraven    }
1668227825Stheraven    return __make_iter(__p);
1669227825Stheraven}
1670227825Stheraven
1671227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
1672227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1673227825Stheraven
1674227825Stheraventemplate <class _Tp, class _Allocator>
1675227825Stheraventypename vector<_Tp, _Allocator>::iterator
1676227825Stheravenvector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
1677227825Stheraven{
1678227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1679227825Stheraven    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1680227825Stheraven        "vector::insert(iterator, n, x) called with an iterator not"
1681227825Stheraven        " referring to this vector");
1682227825Stheraven#endif
1683227825Stheraven    pointer __p = this->__begin_ + (__position - begin());
1684227825Stheraven    if (__n > 0)
1685227825Stheraven    {
1686227825Stheraven        if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
1687227825Stheraven        {
1688227825Stheraven            size_type __old_n = __n;
1689227825Stheraven            pointer __old_last = this->__end_;
1690227825Stheraven            if (__n > static_cast<size_type>(this->__end_ - __p))
1691227825Stheraven            {
1692227825Stheraven                size_type __cx = __n - (this->__end_ - __p);
1693227825Stheraven                __construct_at_end(__cx, __x);
1694227825Stheraven                __n -= __cx;
1695227825Stheraven            }
1696227825Stheraven            if (__n > 0)
1697227825Stheraven            {
1698227825Stheraven                __move_range(__p, __old_last, __p + __old_n);
1699227825Stheraven                const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1700227825Stheraven                if (__p <= __xr && __xr < this->__end_)
1701227825Stheraven                    __xr += __old_n;
1702227825Stheraven                _VSTD::fill_n(__p, __n, *__xr);
1703227825Stheraven            }
1704227825Stheraven        }
1705227825Stheraven        else
1706227825Stheraven        {
1707227825Stheraven            allocator_type& __a = this->__alloc();
1708227825Stheraven            __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1709227825Stheraven            __v.__construct_at_end(__n, __x);
1710227825Stheraven            __p = __swap_out_circular_buffer(__v, __p);
1711227825Stheraven        }
1712227825Stheraven    }
1713227825Stheraven    return __make_iter(__p);
1714227825Stheraven}
1715227825Stheraven
1716227825Stheraventemplate <class _Tp, class _Allocator>
1717227825Stheraventemplate <class _InputIterator>
1718227825Stheraventypename enable_if
1719227825Stheraven<
1720227825Stheraven     __is_input_iterator  <_InputIterator>::value &&
1721227825Stheraven    !__is_forward_iterator<_InputIterator>::value,
1722227825Stheraven    typename vector<_Tp, _Allocator>::iterator
1723227825Stheraven>::type
1724227825Stheravenvector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
1725227825Stheraven{
1726227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1727227825Stheraven    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1728227825Stheraven        "vector::insert(iterator, range) called with an iterator not"
1729227825Stheraven        " referring to this vector");
1730227825Stheraven#endif
1731227825Stheraven    difference_type __off = __position - begin();
1732227825Stheraven    pointer __p = this->__begin_ + __off;
1733227825Stheraven    allocator_type& __a = this->__alloc();
1734227825Stheraven    pointer __old_last = this->__end_;
1735227825Stheraven    for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
1736227825Stheraven    {
1737227825Stheraven        __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
1738227825Stheraven                                  *__first);
1739227825Stheraven        ++this->__end_;
1740227825Stheraven    }
1741227825Stheraven    __split_buffer<value_type, allocator_type&> __v(__a);
1742227825Stheraven    if (__first != __last)
1743227825Stheraven    {
1744227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
1745227825Stheraven        try
1746227825Stheraven        {
1747227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
1748227825Stheraven            __v.__construct_at_end(__first, __last);
1749227825Stheraven            difference_type __old_size = __old_last - this->__begin_;
1750227825Stheraven            difference_type __old_p = __p - this->__begin_;
1751227825Stheraven            reserve(__recommend(size() + __v.size()));
1752227825Stheraven            __p = this->__begin_ + __old_p;
1753227825Stheraven            __old_last = this->__begin_ + __old_size;
1754227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
1755227825Stheraven        }
1756227825Stheraven        catch (...)
1757227825Stheraven        {
1758227825Stheraven            erase(__make_iter(__old_last), end());
1759227825Stheraven            throw;
1760227825Stheraven        }
1761227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
1762227825Stheraven    }
1763227825Stheraven    __p = _VSTD::rotate(__p, __old_last, this->__end_);
1764227825Stheraven    insert(__make_iter(__p), make_move_iterator(__v.begin()),
1765227825Stheraven                                    make_move_iterator(__v.end()));
1766227825Stheraven    return begin() + __off;
1767227825Stheraven}
1768227825Stheraven
1769227825Stheraventemplate <class _Tp, class _Allocator>
1770227825Stheraventemplate <class _ForwardIterator>
1771227825Stheraventypename enable_if
1772227825Stheraven<
1773227825Stheraven    __is_forward_iterator<_ForwardIterator>::value,
1774227825Stheraven    typename vector<_Tp, _Allocator>::iterator
1775227825Stheraven>::type
1776227825Stheravenvector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
1777227825Stheraven{
1778227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1779227825Stheraven    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1780227825Stheraven        "vector::insert(iterator, range) called with an iterator not"
1781227825Stheraven        " referring to this vector");
1782227825Stheraven#endif
1783227825Stheraven    pointer __p = this->__begin_ + (__position - begin());
1784227825Stheraven    difference_type __n = _VSTD::distance(__first, __last);
1785227825Stheraven    if (__n > 0)
1786227825Stheraven    {
1787227825Stheraven        if (__n <= this->__end_cap() - this->__end_)
1788227825Stheraven        {
1789227825Stheraven            size_type __old_n = __n;
1790227825Stheraven            pointer __old_last = this->__end_;
1791227825Stheraven            _ForwardIterator __m = __last;
1792227825Stheraven            difference_type __dx = this->__end_ - __p;
1793227825Stheraven            if (__n > __dx)
1794227825Stheraven            {
1795227825Stheraven                __m = __first;
1796227825Stheraven                _VSTD::advance(__m, this->__end_ - __p);
1797227825Stheraven                __construct_at_end(__m, __last);
1798227825Stheraven                __n = __dx;
1799227825Stheraven            }
1800227825Stheraven            if (__n > 0)
1801227825Stheraven            {
1802227825Stheraven                __move_range(__p, __old_last, __p + __old_n);
1803227825Stheraven                _VSTD::copy(__first, __m, __p);
1804227825Stheraven            }
1805227825Stheraven        }
1806227825Stheraven        else
1807227825Stheraven        {
1808227825Stheraven            allocator_type& __a = this->__alloc();
1809227825Stheraven            __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1810227825Stheraven            __v.__construct_at_end(__first, __last);
1811227825Stheraven            __p = __swap_out_circular_buffer(__v, __p);
1812227825Stheraven        }
1813227825Stheraven    }
1814227825Stheraven    return __make_iter(__p);
1815227825Stheraven}
1816227825Stheraven
1817227825Stheraventemplate <class _Tp, class _Allocator>
1818227825Stheravenvoid
1819227825Stheravenvector<_Tp, _Allocator>::resize(size_type __sz)
1820227825Stheraven{
1821227825Stheraven    size_type __cs = size();
1822227825Stheraven    if (__cs < __sz)
1823227825Stheraven        this->__append(__sz - __cs);
1824227825Stheraven    else if (__cs > __sz)
1825227825Stheraven        this->__destruct_at_end(this->__begin_ + __sz);
1826227825Stheraven}
1827227825Stheraven
1828227825Stheraventemplate <class _Tp, class _Allocator>
1829227825Stheravenvoid
1830227825Stheravenvector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
1831227825Stheraven{
1832227825Stheraven    size_type __cs = size();
1833227825Stheraven    if (__cs < __sz)
1834227825Stheraven        this->__append(__sz - __cs, __x);
1835227825Stheraven    else if (__cs > __sz)
1836227825Stheraven        this->__destruct_at_end(this->__begin_ + __sz);
1837227825Stheraven}
1838227825Stheraven
1839227825Stheraventemplate <class _Tp, class _Allocator>
1840227825Stheravenvoid
1841227825Stheravenvector<_Tp, _Allocator>::swap(vector& __x)
1842227825Stheraven        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1843227825Stheraven                   __is_nothrow_swappable<allocator_type>::value)
1844227825Stheraven{
1845227825Stheraven    _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
1846227825Stheraven                   this->__alloc() == __x.__alloc(),
1847227825Stheraven                   "vector::swap: Either propagate_on_container_swap must be true"
1848227825Stheraven                   " or the allocators must compare equal");
1849227825Stheraven    _VSTD::swap(this->__begin_, __x.__begin_);
1850227825Stheraven    _VSTD::swap(this->__end_, __x.__end_);
1851227825Stheraven    _VSTD::swap(this->__end_cap(), __x.__end_cap());
1852227825Stheraven    __base::__swap_alloc(this->__alloc(), __x.__alloc());
1853227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1854227825Stheraven    __get_db()->swap(this, &__x);
1855227825Stheraven#endif  // _LIBCPP_DEBUG_LEVEL >= 2
1856227825Stheraven}
1857227825Stheraven
1858227825Stheraventemplate <class _Tp, class _Allocator>
1859227825Stheravenbool
1860227825Stheravenvector<_Tp, _Allocator>::__invariants() const
1861227825Stheraven{
1862227825Stheraven    if (this->__begin_ == 0)
1863227825Stheraven    {
1864227825Stheraven        if (this->__end_ != 0 || this->__end_cap() != 0)
1865227825Stheraven            return false;
1866227825Stheraven    }
1867227825Stheraven    else
1868227825Stheraven    {
1869227825Stheraven        if (this->__begin_ > this->__end_)
1870227825Stheraven            return false;
1871227825Stheraven        if (this->__begin_ == this->__end_cap())
1872227825Stheraven            return false;
1873227825Stheraven        if (this->__end_ > this->__end_cap())
1874227825Stheraven            return false;
1875227825Stheraven    }
1876227825Stheraven    return true;
1877227825Stheraven}
1878227825Stheraven
1879227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1880227825Stheraven
1881227825Stheraventemplate <class _Tp, class _Allocator>
1882227825Stheravenbool
1883227825Stheravenvector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
1884227825Stheraven{
1885227825Stheraven    return this->__begin_ <= __i->base() && __i->base() < this->__end_;
1886227825Stheraven}
1887227825Stheraven
1888227825Stheraventemplate <class _Tp, class _Allocator>
1889227825Stheravenbool
1890227825Stheravenvector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
1891227825Stheraven{
1892227825Stheraven    return this->__begin_ < __i->base() && __i->base() <= this->__end_;
1893227825Stheraven}
1894227825Stheraven
1895227825Stheraventemplate <class _Tp, class _Allocator>
1896227825Stheravenbool
1897227825Stheravenvector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
1898227825Stheraven{
1899227825Stheraven    const_pointer __p = __i->base() + __n;
1900227825Stheraven    return this->__begin_ <= __p && __p <= this->__end_;
1901227825Stheraven}
1902227825Stheraven
1903227825Stheraventemplate <class _Tp, class _Allocator>
1904227825Stheravenbool
1905227825Stheravenvector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1906227825Stheraven{
1907227825Stheraven    const_pointer __p = __i->base() + __n;
1908227825Stheraven    return this->__begin_ <= __p && __p < this->__end_;
1909227825Stheraven}
1910227825Stheraven
1911227825Stheraven#endif  // _LIBCPP_DEBUG_LEVEL >= 2
1912227825Stheraven
1913227825Stheraventemplate <class _Tp, class _Allocator>
1914227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
1915227825Stheravenvoid
1916227825Stheravenvector<_Tp, _Allocator>::__invalidate_all_iterators()
1917227825Stheraven{
1918227825Stheraven#if _LIBCPP_DEBUG_LEVEL >= 2
1919227825Stheraven    __get_db()->__invalidate_all(this);
1920227825Stheraven#endif  // _LIBCPP_DEBUG_LEVEL >= 2
1921227825Stheraven}
1922227825Stheraven
1923227825Stheraven// vector<bool>
1924227825Stheraven
1925227825Stheraventemplate <class _Allocator> class vector<bool, _Allocator>;
1926227825Stheraven
1927227825Stheraventemplate <class _Allocator> struct hash<vector<bool, _Allocator> >;
1928227825Stheraven
1929227825Stheraventemplate <class _Allocator>
1930227825Stheravenstruct __has_storage_type<vector<bool, _Allocator> >
1931227825Stheraven{
1932227825Stheraven    static const bool value = true;
1933227825Stheraven};
1934227825Stheraven
1935227825Stheraventemplate <class _Allocator>
1936227825Stheravenclass _LIBCPP_VISIBLE vector<bool, _Allocator>
1937227825Stheraven    : private __vector_base_common<true>
1938227825Stheraven{
1939227825Stheravenpublic:
1940227825Stheraven    typedef vector                                   __self;
1941227825Stheraven    typedef bool                                     value_type;
1942227825Stheraven    typedef _Allocator                               allocator_type;
1943227825Stheraven    typedef allocator_traits<allocator_type>         __alloc_traits;
1944227825Stheraven    typedef typename __alloc_traits::size_type       size_type;
1945227825Stheraven    typedef typename __alloc_traits::difference_type difference_type;
1946227825Stheraven    typedef __bit_iterator<vector, false>            pointer;
1947227825Stheraven    typedef __bit_iterator<vector, true>             const_pointer;
1948227825Stheraven#ifdef _LIBCPP_DEBUG
1949227825Stheraven    typedef __debug_iter<vector, pointer>            iterator;
1950227825Stheraven    typedef __debug_iter<vector, const_pointer>      const_iterator;
1951227825Stheraven
1952227825Stheraven    friend class __debug_iter<vector, pointer>;
1953227825Stheraven    friend class __debug_iter<vector, const_pointer>;
1954227825Stheraven
1955227825Stheraven    pair<iterator*, const_iterator*> __iterator_list_;
1956227825Stheraven
1957227825Stheraven    _LIBCPP_INLINE_VISIBILITY iterator*&       __get_iterator_list(iterator*)       {return __iterator_list_.first;}
1958227825Stheraven    _LIBCPP_INLINE_VISIBILITY const_iterator*& __get_iterator_list(const_iterator*) {return __iterator_list_.second;}
1959227825Stheraven#else  // _LIBCPP_DEBUG
1960227825Stheraven    typedef pointer                                  iterator;
1961227825Stheraven    typedef const_pointer                            const_iterator;
1962227825Stheraven#endif  // _LIBCPP_DEBUG
1963227825Stheraven    typedef _VSTD::reverse_iterator<iterator>         reverse_iterator;
1964227825Stheraven    typedef _VSTD::reverse_iterator<const_iterator>   const_reverse_iterator;
1965227825Stheraven
1966227825Stheravenprivate:
1967227825Stheraven    typedef size_type __storage_type;
1968227825Stheraven    typedef typename __alloc_traits::template
1969227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1970227825Stheraven                rebind_alloc<__storage_type>
1971227825Stheraven#else
1972227825Stheraven                rebind_alloc<__storage_type>::other
1973227825Stheraven#endif
1974227825Stheraven                                                     __storage_allocator;
1975227825Stheraven    typedef allocator_traits<__storage_allocator>    __storage_traits;
1976227825Stheraven    typedef typename __storage_traits::pointer       __storage_pointer;
1977227825Stheraven    typedef typename __storage_traits::const_pointer __const_storage_pointer;
1978227825Stheraven
1979227825Stheraven    __storage_pointer                                      __begin_;
1980227825Stheraven    size_type                                              __size_;
1981227825Stheraven    __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
1982227825Stheravenpublic:
1983227825Stheraven    typedef __bit_reference<vector>                  reference;
1984227825Stheraven    typedef __bit_const_reference<vector>            const_reference;
1985227825Stheravenprivate:
1986227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1987227825Stheraven    size_type& __cap() _NOEXCEPT
1988227825Stheraven        {return __cap_alloc_.first();}
1989227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1990227825Stheraven    const size_type& __cap() const _NOEXCEPT
1991227825Stheraven        {return __cap_alloc_.first();}
1992227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1993227825Stheraven    __storage_allocator& __alloc() _NOEXCEPT
1994227825Stheraven        {return __cap_alloc_.second();}
1995227825Stheraven    _LIBCPP_INLINE_VISIBILITY
1996227825Stheraven    const __storage_allocator& __alloc() const _NOEXCEPT
1997227825Stheraven        {return __cap_alloc_.second();}
1998227825Stheraven
1999227825Stheraven    static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
2000227825Stheraven
2001227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2002227825Stheraven    static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
2003227825Stheraven        {return __n * __bits_per_word;}
2004227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2005227825Stheraven    static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
2006227825Stheraven        {return (__n - 1) / __bits_per_word + 1;}
2007227825Stheraven
2008227825Stheravenpublic:
2009227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2010227825Stheraven    vector()
2011227825Stheraven        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
2012227825Stheraven    _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a);
2013227825Stheraven    ~vector();
2014227825Stheraven    explicit vector(size_type __n);
2015227825Stheraven    vector(size_type __n, const value_type& __v);
2016227825Stheraven    vector(size_type __n, const value_type& __v, const allocator_type& __a);
2017227825Stheraven    template <class _InputIterator>
2018227825Stheraven        vector(_InputIterator __first, _InputIterator __last,
2019227825Stheraven               typename enable_if<__is_input_iterator  <_InputIterator>::value &&
2020227825Stheraven                                 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2021227825Stheraven    template <class _InputIterator>
2022227825Stheraven        vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2023227825Stheraven               typename enable_if<__is_input_iterator  <_InputIterator>::value &&
2024227825Stheraven                                 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2025227825Stheraven    template <class _ForwardIterator>
2026227825Stheraven        vector(_ForwardIterator __first, _ForwardIterator __last,
2027227825Stheraven               typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2028227825Stheraven    template <class _ForwardIterator>
2029227825Stheraven        vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2030227825Stheraven               typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2031227825Stheraven
2032227825Stheraven    vector(const vector& __v);
2033227825Stheraven    vector(const vector& __v, const allocator_type& __a);
2034227825Stheraven    vector& operator=(const vector& __v);
2035227825Stheraven#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2036227825Stheraven    vector(initializer_list<value_type> __il);
2037227825Stheraven    vector(initializer_list<value_type> __il, const allocator_type& __a);
2038227825Stheraven#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2039227825Stheraven
2040227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2041227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2042227825Stheraven    vector(vector&& __v)
2043227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
2044227825Stheraven    vector(vector&& __v, const allocator_type& __a);
2045227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2046227825Stheraven    vector& operator=(vector&& __v)
2047227825Stheraven        _NOEXCEPT_(
2048227825Stheraven             __alloc_traits::propagate_on_container_move_assignment::value &&
2049227825Stheraven             is_nothrow_move_assignable<allocator_type>::value);
2050227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2051227825Stheraven#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2052227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2053227825Stheraven    vector& operator=(initializer_list<value_type> __il)
2054227825Stheraven        {assign(__il.begin(), __il.end()); return *this;}
2055227825Stheraven#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2056227825Stheraven
2057227825Stheraven    template <class _InputIterator>
2058227825Stheraven        typename enable_if
2059227825Stheraven        <
2060227825Stheraven            __is_input_iterator<_InputIterator>::value &&
2061227825Stheraven           !__is_forward_iterator<_InputIterator>::value,
2062227825Stheraven           void
2063227825Stheraven        >::type
2064227825Stheraven        assign(_InputIterator __first, _InputIterator __last);
2065227825Stheraven    template <class _ForwardIterator>
2066227825Stheraven        typename enable_if
2067227825Stheraven        <
2068227825Stheraven            __is_forward_iterator<_ForwardIterator>::value,
2069227825Stheraven           void
2070227825Stheraven        >::type
2071227825Stheraven        assign(_ForwardIterator __first, _ForwardIterator __last);
2072227825Stheraven
2073227825Stheraven    void assign(size_type __n, const value_type& __x);
2074227825Stheraven#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2075227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2076227825Stheraven    void assign(initializer_list<value_type> __il)
2077227825Stheraven        {assign(__il.begin(), __il.end());}
2078227825Stheraven#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2079227825Stheraven
2080227825Stheraven    _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
2081227825Stheraven        {return allocator_type(this->__alloc());}
2082227825Stheraven
2083227825Stheraven    size_type max_size() const _NOEXCEPT;
2084227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2085227825Stheraven    size_type capacity() const _NOEXCEPT
2086227825Stheraven        {return __internal_cap_to_external(__cap());}
2087227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2088227825Stheraven    size_type size() const _NOEXCEPT
2089227825Stheraven        {return __size_;}
2090227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2091227825Stheraven    bool empty() const _NOEXCEPT
2092227825Stheraven        {return __size_ == 0;}
2093227825Stheraven    void reserve(size_type __n);
2094227825Stheraven    void shrink_to_fit() _NOEXCEPT;
2095227825Stheraven
2096227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2097227825Stheraven    iterator begin() _NOEXCEPT
2098227825Stheraven        {return __make_iter(0);}
2099227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2100227825Stheraven    const_iterator begin() const _NOEXCEPT
2101227825Stheraven        {return __make_iter(0);}
2102227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2103227825Stheraven    iterator end() _NOEXCEPT
2104227825Stheraven        {return __make_iter(__size_);}
2105227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2106227825Stheraven    const_iterator end()   const _NOEXCEPT
2107227825Stheraven        {return __make_iter(__size_);}
2108227825Stheraven
2109227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2110227825Stheraven    reverse_iterator rbegin() _NOEXCEPT
2111227825Stheraven        {return       reverse_iterator(end());}
2112227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2113227825Stheraven    const_reverse_iterator rbegin() const _NOEXCEPT
2114227825Stheraven        {return const_reverse_iterator(end());}
2115227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2116227825Stheraven    reverse_iterator rend() _NOEXCEPT
2117227825Stheraven        {return       reverse_iterator(begin());}
2118227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2119227825Stheraven    const_reverse_iterator rend()   const _NOEXCEPT
2120227825Stheraven        {return const_reverse_iterator(begin());}
2121227825Stheraven
2122227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2123227825Stheraven    const_iterator         cbegin()  const _NOEXCEPT
2124227825Stheraven        {return __make_iter(0);}
2125227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2126227825Stheraven    const_iterator         cend()    const _NOEXCEPT
2127227825Stheraven        {return __make_iter(__size_);}
2128227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2129227825Stheraven    const_reverse_iterator crbegin() const _NOEXCEPT
2130227825Stheraven        {return rbegin();}
2131227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2132227825Stheraven    const_reverse_iterator crend()   const _NOEXCEPT
2133227825Stheraven        {return rend();}
2134227825Stheraven
2135227825Stheraven    _LIBCPP_INLINE_VISIBILITY reference       operator[](size_type __n)       {return __make_ref(__n);}
2136227825Stheraven    _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
2137227825Stheraven    reference       at(size_type __n);
2138227825Stheraven    const_reference at(size_type __n) const;
2139227825Stheraven
2140227825Stheraven    _LIBCPP_INLINE_VISIBILITY reference       front()       {return __make_ref(0);}
2141227825Stheraven    _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
2142227825Stheraven    _LIBCPP_INLINE_VISIBILITY reference       back()        {return __make_ref(__size_ - 1);}
2143227825Stheraven    _LIBCPP_INLINE_VISIBILITY const_reference back()  const {return __make_ref(__size_ - 1);}
2144227825Stheraven
2145227825Stheraven    void push_back(const value_type& __x);
2146227825Stheraven    _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
2147227825Stheraven
2148227825Stheraven    iterator insert(const_iterator __position, const value_type& __x);
2149227825Stheraven    iterator insert(const_iterator __position, size_type __n, const value_type& __x);
2150227825Stheraven    iterator insert(const_iterator __position, size_type __n, const_reference __x);
2151227825Stheraven    template <class _InputIterator>
2152227825Stheraven        typename enable_if
2153227825Stheraven        <
2154227825Stheraven             __is_input_iterator  <_InputIterator>::value &&
2155227825Stheraven            !__is_forward_iterator<_InputIterator>::value,
2156227825Stheraven            iterator
2157227825Stheraven        >::type
2158227825Stheraven        insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
2159227825Stheraven    template <class _ForwardIterator>
2160227825Stheraven        typename enable_if
2161227825Stheraven        <
2162227825Stheraven            __is_forward_iterator<_ForwardIterator>::value,
2163227825Stheraven            iterator
2164227825Stheraven        >::type
2165227825Stheraven        insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
2166227825Stheraven#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2167227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2168227825Stheraven    iterator insert(const_iterator __position, initializer_list<value_type> __il)
2169227825Stheraven        {return insert(__position, __il.begin(), __il.end());}
2170227825Stheraven#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2171227825Stheraven
2172227825Stheraven    _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
2173227825Stheraven    iterator erase(const_iterator __first, const_iterator __last);
2174227825Stheraven
2175227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2176227825Stheraven    void clear() _NOEXCEPT {__size_ = 0;}
2177227825Stheraven
2178227825Stheraven    void swap(vector&)
2179227825Stheraven        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2180227825Stheraven                   __is_nothrow_swappable<allocator_type>::value);
2181227825Stheraven
2182227825Stheraven    void resize(size_type __sz, value_type __x = false);
2183227825Stheraven    void flip() _NOEXCEPT;
2184227825Stheraven
2185227825Stheraven    bool __invariants() const;
2186227825Stheraven
2187227825Stheravenprivate:
2188227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
2189227825Stheraven    void allocate(size_type __n);
2190227825Stheraven    void deallocate() _NOEXCEPT;
2191227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2192227825Stheraven    static size_type __align(size_type __new_size) _NOEXCEPT
2193227825Stheraven        {return __new_size + (__bits_per_word-1) & ~(__bits_per_word-1);};
2194227825Stheraven    _LIBCPP_INLINE_VISIBILITY  size_type __recommend(size_type __new_size) const;
2195227825Stheraven    _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
2196227825Stheraven    template <class _ForwardIterator>
2197227825Stheraven        typename enable_if
2198227825Stheraven        <
2199227825Stheraven            __is_forward_iterator<_ForwardIterator>::value,
2200227825Stheraven            void
2201227825Stheraven        >::type
2202227825Stheraven        __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
2203227825Stheraven    void __append(size_type __n, const_reference __x);
2204227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2205227825Stheraven    reference __make_ref(size_type __pos) _NOEXCEPT
2206227825Stheraven        {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2207227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2208227825Stheraven    const_reference __make_ref(size_type __pos) const _NOEXCEPT
2209227825Stheraven        {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2210227825Stheraven#ifdef _LIBCPP_DEBUG
2211227825Stheraven    _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_type __pos)
2212227825Stheraven        {return iterator(this, pointer(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word)));}
2213227825Stheraven    _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_type __pos) const
2214227825Stheraven        {return const_iterator(this, const_pointer(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word)));}
2215227825Stheraven    _LIBCPP_INLINE_VISIBILITY iterator __const_iterator_cast(const_iterator __p)
2216227825Stheraven        {return iterator(this, pointer(const_cast<__storage_pointer>(__p.base().__seg_), __p.base().__ctz_));}
2217227825Stheraven#else  // _LIBCPP_DEBUG
2218227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2219227825Stheraven    iterator __make_iter(size_type __pos) _NOEXCEPT
2220227825Stheraven        {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2221227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2222227825Stheraven    const_iterator __make_iter(size_type __pos) const _NOEXCEPT
2223227825Stheraven        {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2224227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2225227825Stheraven    iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
2226227825Stheraven        {return iterator(const_cast<__storage_pointer>(__p.__seg_), __p.__ctz_);}
2227227825Stheraven#endif  // _LIBCPP_DEBUG
2228227825Stheraven
2229227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2230227825Stheraven    void __copy_assign_alloc(const vector& __v)
2231227825Stheraven        {__copy_assign_alloc(__v, integral_constant<bool,
2232227825Stheraven                      __storage_traits::propagate_on_container_copy_assignment::value>());}
2233227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2234227825Stheraven    void __copy_assign_alloc(const vector& __c, true_type)
2235227825Stheraven        {
2236227825Stheraven            if (__alloc() != __c.__alloc())
2237227825Stheraven                deallocate();
2238227825Stheraven            __alloc() = __c.__alloc();
2239227825Stheraven        }
2240227825Stheraven
2241227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2242227825Stheraven    void __copy_assign_alloc(const vector& __c, false_type)
2243227825Stheraven        {}
2244227825Stheraven
2245227825Stheraven    void __move_assign(vector& __c, false_type);
2246227825Stheraven    void __move_assign(vector& __c, true_type)
2247227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
2248227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2249227825Stheraven    void __move_assign_alloc(vector& __c)
2250227825Stheraven        _NOEXCEPT_(
2251227825Stheraven            !__storage_traits::propagate_on_container_move_assignment::value ||
2252227825Stheraven            is_nothrow_move_assignable<allocator_type>::value)
2253227825Stheraven        {__move_assign_alloc(__c, integral_constant<bool,
2254227825Stheraven                      __storage_traits::propagate_on_container_move_assignment::value>());}
2255227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2256227825Stheraven    void __move_assign_alloc(vector& __c, true_type)
2257227825Stheraven        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2258227825Stheraven        {
2259227825Stheraven            __alloc() = _VSTD::move(__c.__alloc());
2260227825Stheraven        }
2261227825Stheraven
2262227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2263227825Stheraven    void __move_assign_alloc(vector& __c, false_type)
2264227825Stheraven        _NOEXCEPT
2265227825Stheraven        {}
2266227825Stheraven
2267227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2268227825Stheraven    static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y)
2269227825Stheraven        _NOEXCEPT_(
2270227825Stheraven            !__storage_traits::propagate_on_container_swap::value ||
2271227825Stheraven            __is_nothrow_swappable<allocator_type>::value)
2272227825Stheraven        {__swap_alloc(__x, __y, integral_constant<bool,
2273227825Stheraven                      __storage_traits::propagate_on_container_swap::value>());}
2274227825Stheraven
2275227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2276227825Stheraven    static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, true_type)
2277227825Stheraven        _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
2278227825Stheraven        {
2279227825Stheraven            using _VSTD::swap;
2280227825Stheraven            swap(__x, __y);
2281227825Stheraven        }
2282227825Stheraven    _LIBCPP_INLINE_VISIBILITY
2283227825Stheraven    static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, false_type)
2284227825Stheraven        _NOEXCEPT
2285227825Stheraven        {}
2286227825Stheraven
2287227825Stheraven    size_t __hash_code() const _NOEXCEPT;
2288227825Stheraven
2289227825Stheraven    friend class __bit_reference<vector>;
2290227825Stheraven    friend class __bit_const_reference<vector>;
2291227825Stheraven    friend class __bit_iterator<vector, false>;
2292227825Stheraven    friend class __bit_iterator<vector, true>;
2293227825Stheraven    friend class __bit_array<vector>;
2294227825Stheraven    friend struct _LIBCPP_VISIBLE hash<vector>;
2295227825Stheraven};
2296227825Stheraven
2297227825Stheraventemplate <class _Allocator>
2298227825Stheraven#ifndef _LIBCPP_DEBUG
2299227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
2300227825Stheraven#endif
2301227825Stheravenvoid
2302227825Stheravenvector<bool, _Allocator>::__invalidate_all_iterators()
2303227825Stheraven{
2304227825Stheraven#ifdef _LIBCPP_DEBUG
2305227825Stheraven    iterator::__remove_all(this);
2306227825Stheraven    const_iterator::__remove_all(this);
2307227825Stheraven#endif  // _LIBCPP_DEBUG
2308227825Stheraven}
2309227825Stheraven
2310227825Stheraven//  Allocate space for __n objects
2311227825Stheraven//  throws length_error if __n > max_size()
2312227825Stheraven//  throws (probably bad_alloc) if memory run out
2313227825Stheraven//  Precondition:  __begin_ == __end_ == __cap() == 0
2314227825Stheraven//  Precondition:  __n > 0
2315227825Stheraven//  Postcondition:  capacity() == __n
2316227825Stheraven//  Postcondition:  size() == 0
2317227825Stheraventemplate <class _Allocator>
2318227825Stheravenvoid
2319227825Stheravenvector<bool, _Allocator>::allocate(size_type __n)
2320227825Stheraven{
2321227825Stheraven    if (__n > max_size())
2322227825Stheraven        this->__throw_length_error();
2323227825Stheraven    __n = __external_cap_to_internal(__n);
2324227825Stheraven    this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
2325227825Stheraven    this->__size_ = 0;
2326227825Stheraven    this->__cap() = __n;
2327227825Stheraven}
2328227825Stheraven
2329227825Stheraventemplate <class _Allocator>
2330227825Stheravenvoid
2331227825Stheravenvector<bool, _Allocator>::deallocate() _NOEXCEPT
2332227825Stheraven{
2333227825Stheraven    if (this->__begin_ != 0)
2334227825Stheraven    {
2335227825Stheraven        __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2336227825Stheraven        __invalidate_all_iterators();
2337227825Stheraven        this->__begin_ = 0;
2338227825Stheraven        this->__size_ = this->__cap() = 0;
2339227825Stheraven    }
2340227825Stheraven}
2341227825Stheraven
2342227825Stheraventemplate <class _Allocator>
2343227825Stheraventypename vector<bool, _Allocator>::size_type
2344227825Stheravenvector<bool, _Allocator>::max_size() const _NOEXCEPT
2345227825Stheraven{
2346227825Stheraven    size_type __amax = __storage_traits::max_size(__alloc());
2347227825Stheraven    size_type __nmax = numeric_limits<size_type>::max() / 2;  // end() >= begin(), always
2348227825Stheraven    if (__nmax / __bits_per_word <= __amax)
2349227825Stheraven        return __nmax;
2350227825Stheraven    return __internal_cap_to_external(__amax);
2351227825Stheraven}
2352227825Stheraven
2353227825Stheraven//  Precondition:  __new_size > capacity()
2354227825Stheraventemplate <class _Allocator>
2355227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
2356227825Stheraventypename vector<bool, _Allocator>::size_type
2357227825Stheravenvector<bool, _Allocator>::__recommend(size_type __new_size) const
2358227825Stheraven{
2359227825Stheraven    const size_type __ms = max_size();
2360227825Stheraven    if (__new_size > __ms)
2361227825Stheraven        this->__throw_length_error();
2362227825Stheraven    const size_type __cap = capacity();
2363227825Stheraven    if (__cap >= __ms / 2)
2364227825Stheraven        return __ms;
2365227825Stheraven    return _VSTD::max(2*__cap, __align(__new_size));
2366227825Stheraven}
2367227825Stheraven
2368227825Stheraven//  Default constructs __n objects starting at __end_
2369227825Stheraven//  Precondition:  __n > 0
2370227825Stheraven//  Precondition:  size() + __n <= capacity()
2371227825Stheraven//  Postcondition:  size() == size() + __n
2372227825Stheraventemplate <class _Allocator>
2373227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
2374227825Stheravenvoid
2375227825Stheravenvector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
2376227825Stheraven{
2377227825Stheraven    size_type __old_size = this->__size_;
2378227825Stheraven    this->__size_ += __n;
2379227825Stheraven    _VSTD::fill_n(__make_iter(__old_size), __n, __x);
2380227825Stheraven}
2381227825Stheraven
2382227825Stheraventemplate <class _Allocator>
2383227825Stheraventemplate <class _ForwardIterator>
2384227825Stheraventypename enable_if
2385227825Stheraven<
2386227825Stheraven    __is_forward_iterator<_ForwardIterator>::value,
2387227825Stheraven    void
2388227825Stheraven>::type
2389227825Stheravenvector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
2390227825Stheraven{
2391227825Stheraven    size_type __old_size = this->__size_;
2392227825Stheraven    this->__size_ += _VSTD::distance(__first, __last);
2393227825Stheraven    _VSTD::copy(__first, __last, __make_iter(__old_size));
2394227825Stheraven}
2395227825Stheraven
2396227825Stheraventemplate <class _Allocator>
2397227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
2398227825Stheravenvector<bool, _Allocator>::vector()
2399227825Stheraven        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
2400227825Stheraven    : __begin_(0),
2401227825Stheraven      __size_(0),
2402227825Stheraven      __cap_alloc_(0)
2403227825Stheraven{
2404227825Stheraven}
2405227825Stheraven
2406227825Stheraventemplate <class _Allocator>
2407227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
2408227825Stheravenvector<bool, _Allocator>::vector(const allocator_type& __a)
2409227825Stheraven    : __begin_(0),
2410227825Stheraven      __size_(0),
2411227825Stheraven      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2412227825Stheraven{
2413227825Stheraven}
2414227825Stheraven
2415227825Stheraventemplate <class _Allocator>
2416227825Stheravenvector<bool, _Allocator>::vector(size_type __n)
2417227825Stheraven    : __begin_(0),
2418227825Stheraven      __size_(0),
2419227825Stheraven      __cap_alloc_(0)
2420227825Stheraven{
2421227825Stheraven    if (__n > 0)
2422227825Stheraven    {
2423227825Stheraven        allocate(__n);
2424227825Stheraven        __construct_at_end(__n, false);
2425227825Stheraven    }
2426227825Stheraven}
2427227825Stheraven
2428227825Stheraventemplate <class _Allocator>
2429227825Stheravenvector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
2430227825Stheraven    : __begin_(0),
2431227825Stheraven      __size_(0),
2432227825Stheraven      __cap_alloc_(0)
2433227825Stheraven{
2434227825Stheraven    if (__n > 0)
2435227825Stheraven    {
2436227825Stheraven        allocate(__n);
2437227825Stheraven        __construct_at_end(__n, __x);
2438227825Stheraven    }
2439227825Stheraven}
2440227825Stheraven
2441227825Stheraventemplate <class _Allocator>
2442227825Stheravenvector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
2443227825Stheraven    : __begin_(0),
2444227825Stheraven      __size_(0),
2445227825Stheraven      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2446227825Stheraven{
2447227825Stheraven    if (__n > 0)
2448227825Stheraven    {
2449227825Stheraven        allocate(__n);
2450227825Stheraven        __construct_at_end(__n, __x);
2451227825Stheraven    }
2452227825Stheraven}
2453227825Stheraven
2454227825Stheraventemplate <class _Allocator>
2455227825Stheraventemplate <class _InputIterator>
2456227825Stheravenvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2457227825Stheraven       typename enable_if<__is_input_iterator  <_InputIterator>::value &&
2458227825Stheraven                         !__is_forward_iterator<_InputIterator>::value>::type*)
2459227825Stheraven    : __begin_(0),
2460227825Stheraven      __size_(0),
2461227825Stheraven      __cap_alloc_(0)
2462227825Stheraven{
2463227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
2464227825Stheraven    try
2465227825Stheraven    {
2466227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
2467227825Stheraven        for (; __first != __last; ++__first)
2468227825Stheraven            push_back(*__first);
2469227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
2470227825Stheraven    }
2471227825Stheraven    catch (...)
2472227825Stheraven    {
2473227825Stheraven        if (__begin_ != 0)
2474227825Stheraven            __storage_traits::deallocate(__alloc(), __begin_, __cap());
2475227825Stheraven        __invalidate_all_iterators();
2476227825Stheraven        throw;
2477227825Stheraven    }
2478227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
2479227825Stheraven}
2480227825Stheraven
2481227825Stheraventemplate <class _Allocator>
2482227825Stheraventemplate <class _InputIterator>
2483227825Stheravenvector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2484227825Stheraven       typename enable_if<__is_input_iterator  <_InputIterator>::value &&
2485227825Stheraven                         !__is_forward_iterator<_InputIterator>::value>::type*)
2486227825Stheraven    : __begin_(0),
2487227825Stheraven      __size_(0),
2488227825Stheraven      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2489227825Stheraven{
2490227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
2491227825Stheraven    try
2492227825Stheraven    {
2493227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
2494227825Stheraven        for (; __first != __last; ++__first)
2495227825Stheraven            push_back(*__first);
2496227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
2497227825Stheraven    }
2498227825Stheraven    catch (...)
2499227825Stheraven    {
2500227825Stheraven        if (__begin_ != 0)
2501227825Stheraven            __storage_traits::deallocate(__alloc(), __begin_, __cap());
2502227825Stheraven        __invalidate_all_iterators();
2503227825Stheraven        throw;
2504227825Stheraven    }
2505227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
2506227825Stheraven}
2507227825Stheraven
2508227825Stheraventemplate <class _Allocator>
2509227825Stheraventemplate <class _ForwardIterator>
2510227825Stheravenvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2511227825Stheraven                                typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2512227825Stheraven    : __begin_(0),
2513227825Stheraven      __size_(0),
2514227825Stheraven      __cap_alloc_(0)
2515227825Stheraven{
2516227825Stheraven    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2517227825Stheraven    if (__n > 0)
2518227825Stheraven    {
2519227825Stheraven        allocate(__n);
2520227825Stheraven        __construct_at_end(__first, __last);
2521227825Stheraven    }
2522227825Stheraven}
2523227825Stheraven
2524227825Stheraventemplate <class _Allocator>
2525227825Stheraventemplate <class _ForwardIterator>
2526227825Stheravenvector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2527227825Stheraven                                typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2528227825Stheraven    : __begin_(0),
2529227825Stheraven      __size_(0),
2530227825Stheraven      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2531227825Stheraven{
2532227825Stheraven    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2533227825Stheraven    if (__n > 0)
2534227825Stheraven    {
2535227825Stheraven        allocate(__n);
2536227825Stheraven        __construct_at_end(__first, __last);
2537227825Stheraven    }
2538227825Stheraven}
2539227825Stheraven
2540227825Stheraven#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2541227825Stheraven
2542227825Stheraventemplate <class _Allocator>
2543227825Stheravenvector<bool, _Allocator>::vector(initializer_list<value_type> __il)
2544227825Stheraven    : __begin_(0),
2545227825Stheraven      __size_(0),
2546227825Stheraven      __cap_alloc_(0)
2547227825Stheraven{
2548227825Stheraven    size_type __n = static_cast<size_type>(__il.size());
2549227825Stheraven    if (__n > 0)
2550227825Stheraven    {
2551227825Stheraven        allocate(__n);
2552227825Stheraven        __construct_at_end(__il.begin(), __il.end());
2553227825Stheraven    }
2554227825Stheraven}
2555227825Stheraven
2556227825Stheraventemplate <class _Allocator>
2557227825Stheravenvector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
2558227825Stheraven    : __begin_(0),
2559227825Stheraven      __size_(0),
2560227825Stheraven      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2561227825Stheraven{
2562227825Stheraven    size_type __n = static_cast<size_type>(__il.size());
2563227825Stheraven    if (__n > 0)
2564227825Stheraven    {
2565227825Stheraven        allocate(__n);
2566227825Stheraven        __construct_at_end(__il.begin(), __il.end());
2567227825Stheraven    }
2568227825Stheraven}
2569227825Stheraven
2570227825Stheraven#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2571227825Stheraven
2572227825Stheraventemplate <class _Allocator>
2573227825Stheravenvector<bool, _Allocator>::~vector()
2574227825Stheraven{
2575227825Stheraven    if (__begin_ != 0)
2576227825Stheraven        __storage_traits::deallocate(__alloc(), __begin_, __cap());
2577227825Stheraven#ifdef _LIBCPP_DEBUG
2578227825Stheraven    __invalidate_all_iterators();
2579227825Stheraven#endif
2580227825Stheraven}
2581227825Stheraven
2582227825Stheraventemplate <class _Allocator>
2583227825Stheravenvector<bool, _Allocator>::vector(const vector& __v)
2584227825Stheraven    : __begin_(0),
2585227825Stheraven      __size_(0),
2586227825Stheraven      __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
2587227825Stheraven{
2588227825Stheraven    if (__v.size() > 0)
2589227825Stheraven    {
2590227825Stheraven        allocate(__v.size());
2591227825Stheraven        __construct_at_end(__v.begin(), __v.end());
2592227825Stheraven    }
2593227825Stheraven}
2594227825Stheraven
2595227825Stheraventemplate <class _Allocator>
2596227825Stheravenvector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
2597227825Stheraven    : __begin_(0),
2598227825Stheraven      __size_(0),
2599227825Stheraven      __cap_alloc_(0, __a)
2600227825Stheraven{
2601227825Stheraven    if (__v.size() > 0)
2602227825Stheraven    {
2603227825Stheraven        allocate(__v.size());
2604227825Stheraven        __construct_at_end(__v.begin(), __v.end());
2605227825Stheraven    }
2606227825Stheraven}
2607227825Stheraven
2608227825Stheraventemplate <class _Allocator>
2609227825Stheravenvector<bool, _Allocator>&
2610227825Stheravenvector<bool, _Allocator>::operator=(const vector& __v)
2611227825Stheraven{
2612227825Stheraven    if (this != &__v)
2613227825Stheraven    {
2614227825Stheraven        __copy_assign_alloc(__v);
2615227825Stheraven        if (__v.__size_)
2616227825Stheraven        {
2617227825Stheraven            if (__v.__size_ > capacity())
2618227825Stheraven            {
2619227825Stheraven                deallocate();
2620227825Stheraven                allocate(__v.__size_);
2621227825Stheraven            }
2622227825Stheraven            _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
2623227825Stheraven        }
2624227825Stheraven        __size_ = __v.__size_;
2625227825Stheraven    }
2626227825Stheraven    return *this;
2627227825Stheraven}
2628227825Stheraven
2629227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2630227825Stheraven
2631227825Stheraventemplate <class _Allocator>
2632227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
2633227825Stheravenvector<bool, _Allocator>::vector(vector&& __v)
2634227825Stheraven        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
2635227825Stheraven    : __begin_(__v.__begin_),
2636227825Stheraven      __size_(__v.__size_),
2637227825Stheraven      __cap_alloc_(__v.__cap_alloc_)
2638227825Stheraven{
2639227825Stheraven    __v.__begin_ = 0;
2640227825Stheraven    __v.__size_ = 0;
2641227825Stheraven    __v.__cap() = 0;
2642227825Stheraven}
2643227825Stheraven
2644227825Stheraventemplate <class _Allocator>
2645227825Stheravenvector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
2646227825Stheraven    : __begin_(0),
2647227825Stheraven      __size_(0),
2648227825Stheraven      __cap_alloc_(0, __a)
2649227825Stheraven{
2650227825Stheraven    if (__a == allocator_type(__v.__alloc()))
2651227825Stheraven    {
2652227825Stheraven        this->__begin_ = __v.__begin_;
2653227825Stheraven        this->__size_ = __v.__size_;
2654227825Stheraven        this->__cap() = __v.__cap();
2655227825Stheraven        __v.__begin_ = nullptr;
2656227825Stheraven        __v.__cap() = __v.__size_ = 0;
2657227825Stheraven    }
2658227825Stheraven    else if (__v.size() > 0)
2659227825Stheraven    {
2660227825Stheraven        allocate(__v.size());
2661227825Stheraven        __construct_at_end(__v.begin(), __v.end());
2662227825Stheraven    }
2663227825Stheraven}
2664227825Stheraven
2665227825Stheraventemplate <class _Allocator>
2666227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
2667227825Stheravenvector<bool, _Allocator>&
2668227825Stheravenvector<bool, _Allocator>::operator=(vector&& __v)
2669227825Stheraven        _NOEXCEPT_(
2670227825Stheraven             __alloc_traits::propagate_on_container_move_assignment::value &&
2671227825Stheraven             is_nothrow_move_assignable<allocator_type>::value)
2672227825Stheraven{
2673227825Stheraven    __move_assign(__v, integral_constant<bool,
2674227825Stheraven          __storage_traits::propagate_on_container_move_assignment::value>());
2675227825Stheraven}
2676227825Stheraven
2677227825Stheraventemplate <class _Allocator>
2678227825Stheravenvoid
2679227825Stheravenvector<bool, _Allocator>::__move_assign(vector& __c, false_type)
2680227825Stheraven{
2681227825Stheraven    if (__alloc() != __c.__alloc())
2682227825Stheraven        assign(__c.begin(), __c.end());
2683227825Stheraven    else
2684227825Stheraven        __move_assign(__c, true_type());
2685227825Stheraven}
2686227825Stheraven
2687227825Stheraventemplate <class _Allocator>
2688227825Stheravenvoid
2689227825Stheravenvector<bool, _Allocator>::__move_assign(vector& __c, true_type)
2690227825Stheraven    _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2691227825Stheraven{
2692227825Stheraven    deallocate();
2693227825Stheraven    this->__begin_ = __c.__begin_;
2694227825Stheraven    this->__size_ = __c.__size_;
2695227825Stheraven    this->__cap() = __c.__cap();
2696227825Stheraven    __move_assign_alloc(__c);
2697227825Stheraven    __c.__begin_ = nullptr;
2698227825Stheraven    __c.__cap() = __c.__size_ = 0;
2699227825Stheraven}
2700227825Stheraven
2701227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2702227825Stheraven
2703227825Stheraventemplate <class _Allocator>
2704227825Stheravenvoid
2705227825Stheravenvector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
2706227825Stheraven{
2707227825Stheraven    __size_ = 0;
2708227825Stheraven    if (__n > 0)
2709227825Stheraven    {
2710227825Stheraven        size_type __c = capacity();
2711227825Stheraven        if (__n <= __c)
2712227825Stheraven            __size_ = __n;
2713227825Stheraven        else
2714227825Stheraven        {
2715227825Stheraven            vector __v(__alloc());
2716227825Stheraven            __v.reserve(__recommend(__n));
2717227825Stheraven            __v.__size_ = __n;
2718227825Stheraven            swap(__v);
2719227825Stheraven        }
2720227825Stheraven        _VSTD::fill_n(begin(), __n, __x);
2721227825Stheraven    }
2722227825Stheraven}
2723227825Stheraven
2724227825Stheraventemplate <class _Allocator>
2725227825Stheraventemplate <class _InputIterator>
2726227825Stheraventypename enable_if
2727227825Stheraven<
2728227825Stheraven    __is_input_iterator<_InputIterator>::value &&
2729227825Stheraven   !__is_forward_iterator<_InputIterator>::value,
2730227825Stheraven   void
2731227825Stheraven>::type
2732227825Stheravenvector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2733227825Stheraven{
2734227825Stheraven    clear();
2735227825Stheraven    for (; __first != __last; ++__first)
2736227825Stheraven        push_back(*__first);
2737227825Stheraven}
2738227825Stheraven
2739227825Stheraventemplate <class _Allocator>
2740227825Stheraventemplate <class _ForwardIterator>
2741227825Stheraventypename enable_if
2742227825Stheraven<
2743227825Stheraven    __is_forward_iterator<_ForwardIterator>::value,
2744227825Stheraven   void
2745227825Stheraven>::type
2746227825Stheravenvector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2747227825Stheraven{
2748227825Stheraven    clear();
2749227825Stheraven    difference_type __n = _VSTD::distance(__first, __last);
2750227825Stheraven    if (__n)
2751227825Stheraven    {
2752227825Stheraven        if (__n > capacity())
2753227825Stheraven        {
2754227825Stheraven            deallocate();
2755227825Stheraven            allocate(__n);
2756227825Stheraven        }
2757227825Stheraven        __construct_at_end(__first, __last);
2758227825Stheraven    }
2759227825Stheraven}
2760227825Stheraven
2761227825Stheraventemplate <class _Allocator>
2762227825Stheravenvoid
2763227825Stheravenvector<bool, _Allocator>::reserve(size_type __n)
2764227825Stheraven{
2765227825Stheraven    if (__n > capacity())
2766227825Stheraven    {
2767227825Stheraven        vector __v(this->__alloc());
2768227825Stheraven        __v.allocate(__n);
2769227825Stheraven        __v.__construct_at_end(this->begin(), this->end());
2770227825Stheraven        swap(__v);
2771227825Stheraven        __invalidate_all_iterators();
2772227825Stheraven    }
2773227825Stheraven}
2774227825Stheraven
2775227825Stheraventemplate <class _Allocator>
2776227825Stheravenvoid
2777227825Stheravenvector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
2778227825Stheraven{
2779227825Stheraven    if (__external_cap_to_internal(size()) > __cap())
2780227825Stheraven    {
2781227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
2782227825Stheraven        try
2783227825Stheraven        {
2784227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
2785227825Stheraven            vector(*this, allocator_type(__alloc())).swap(*this);
2786227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
2787227825Stheraven        }
2788227825Stheraven        catch (...)
2789227825Stheraven        {
2790227825Stheraven        }
2791227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
2792227825Stheraven    }
2793227825Stheraven}
2794227825Stheraven
2795227825Stheraventemplate <class _Allocator>
2796227825Stheraventypename vector<bool, _Allocator>::reference
2797227825Stheravenvector<bool, _Allocator>::at(size_type __n)
2798227825Stheraven{
2799227825Stheraven    if (__n >= size())
2800227825Stheraven        this->__throw_out_of_range();
2801227825Stheraven    return (*this)[__n];
2802227825Stheraven}
2803227825Stheraven
2804227825Stheraventemplate <class _Allocator>
2805227825Stheraventypename vector<bool, _Allocator>::const_reference
2806227825Stheravenvector<bool, _Allocator>::at(size_type __n) const
2807227825Stheraven{
2808227825Stheraven    if (__n >= size())
2809227825Stheraven        this->__throw_out_of_range();
2810227825Stheraven    return (*this)[__n];
2811227825Stheraven}
2812227825Stheraven
2813227825Stheraventemplate <class _Allocator>
2814227825Stheravenvoid
2815227825Stheravenvector<bool, _Allocator>::push_back(const value_type& __x)
2816227825Stheraven{
2817227825Stheraven    if (this->__size_ == this->capacity())
2818227825Stheraven        reserve(__recommend(this->__size_ + 1));
2819227825Stheraven    ++this->__size_;
2820227825Stheraven    back() = __x;
2821227825Stheraven}
2822227825Stheraven
2823227825Stheraventemplate <class _Allocator>
2824227825Stheraventypename vector<bool, _Allocator>::iterator
2825227825Stheravenvector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
2826227825Stheraven{
2827227825Stheraven    iterator __r;
2828227825Stheraven    if (size() < capacity())
2829227825Stheraven    {
2830227825Stheraven        const_iterator __old_end = end();
2831227825Stheraven        ++__size_;
2832227825Stheraven        _VSTD::copy_backward(__position, __old_end, end());
2833227825Stheraven        __r = __const_iterator_cast(__position);
2834227825Stheraven    }
2835227825Stheraven    else
2836227825Stheraven    {
2837227825Stheraven        vector __v(__alloc());
2838227825Stheraven        __v.reserve(__recommend(__size_ + 1));
2839227825Stheraven        __v.__size_ = __size_ + 1;
2840227825Stheraven        __r = _VSTD::copy(cbegin(), __position, __v.begin());
2841227825Stheraven        _VSTD::copy_backward(__position, cend(), __v.end());
2842227825Stheraven        swap(__v);
2843227825Stheraven    }
2844227825Stheraven    *__r = __x;
2845227825Stheraven    return __r;
2846227825Stheraven}
2847227825Stheraven
2848227825Stheraventemplate <class _Allocator>
2849227825Stheraventypename vector<bool, _Allocator>::iterator
2850227825Stheravenvector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
2851227825Stheraven{
2852227825Stheraven    iterator __r;
2853227825Stheraven    size_type __c = capacity();
2854227825Stheraven    if (__n <= __c && size() <= __c - __n)
2855227825Stheraven    {
2856227825Stheraven        const_iterator __old_end = end();
2857227825Stheraven        __size_ += __n;
2858227825Stheraven        _VSTD::copy_backward(__position, __old_end, end());
2859227825Stheraven        __r = __const_iterator_cast(__position);
2860227825Stheraven    }
2861227825Stheraven    else
2862227825Stheraven    {
2863227825Stheraven        vector __v(__alloc());
2864227825Stheraven        __v.reserve(__recommend(__size_ + __n));
2865227825Stheraven        __v.__size_ = __size_ + __n;
2866227825Stheraven        __r = _VSTD::copy(cbegin(), __position, __v.begin());
2867227825Stheraven        _VSTD::copy_backward(__position, cend(), __v.end());
2868227825Stheraven        swap(__v);
2869227825Stheraven    }
2870227825Stheraven    _VSTD::fill_n(__r, __n, __x);
2871227825Stheraven    return __r;
2872227825Stheraven}
2873227825Stheraven
2874227825Stheraventemplate <class _Allocator>
2875227825Stheraventemplate <class _InputIterator>
2876227825Stheraventypename enable_if
2877227825Stheraven<
2878227825Stheraven     __is_input_iterator  <_InputIterator>::value &&
2879227825Stheraven    !__is_forward_iterator<_InputIterator>::value,
2880227825Stheraven    typename vector<bool, _Allocator>::iterator
2881227825Stheraven>::type
2882227825Stheravenvector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
2883227825Stheraven{
2884227825Stheraven    difference_type __off = __position - begin();
2885227825Stheraven    iterator __p = __const_iterator_cast(__position);
2886227825Stheraven    iterator __old_end = end();
2887227825Stheraven    for (; size() != capacity() && __first != __last; ++__first)
2888227825Stheraven    {
2889227825Stheraven        ++this->__size_;
2890227825Stheraven        back() = *__first;
2891227825Stheraven    }
2892227825Stheraven    vector __v(__alloc());
2893227825Stheraven    if (__first != __last)
2894227825Stheraven    {
2895227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
2896227825Stheraven        try
2897227825Stheraven        {
2898227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
2899227825Stheraven            __v.assign(__first, __last);
2900227825Stheraven            difference_type __old_size = static_cast<difference_type>(__old_end - begin());
2901227825Stheraven            difference_type __old_p = __p - begin();
2902227825Stheraven            reserve(__recommend(size() + __v.size()));
2903227825Stheraven            __p = begin() + __old_p;
2904227825Stheraven            __old_end = begin() + __old_size;
2905227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS
2906227825Stheraven        }
2907227825Stheraven        catch (...)
2908227825Stheraven        {
2909227825Stheraven            erase(__old_end, end());
2910227825Stheraven            throw;
2911227825Stheraven        }
2912227825Stheraven#endif  // _LIBCPP_NO_EXCEPTIONS
2913227825Stheraven    }
2914227825Stheraven    __p = _VSTD::rotate(__p, __old_end, end());
2915227825Stheraven    insert(__p, __v.begin(), __v.end());
2916227825Stheraven    return begin() + __off;
2917227825Stheraven}
2918227825Stheraven
2919227825Stheraventemplate <class _Allocator>
2920227825Stheraventemplate <class _ForwardIterator>
2921227825Stheraventypename enable_if
2922227825Stheraven<
2923227825Stheraven    __is_forward_iterator<_ForwardIterator>::value,
2924227825Stheraven    typename vector<bool, _Allocator>::iterator
2925227825Stheraven>::type
2926227825Stheravenvector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
2927227825Stheraven{
2928227825Stheraven    difference_type __n = _VSTD::distance(__first, __last);
2929227825Stheraven    iterator __r;
2930227825Stheraven    size_type __c = capacity();
2931227825Stheraven    if (__n <= __c && size() <= __c - __n)
2932227825Stheraven    {
2933227825Stheraven        const_iterator __old_end = end();
2934227825Stheraven        __size_ += __n;
2935227825Stheraven        _VSTD::copy_backward(__position, __old_end, end());
2936227825Stheraven        __r = __const_iterator_cast(__position);
2937227825Stheraven    }
2938227825Stheraven    else
2939227825Stheraven    {
2940227825Stheraven        vector __v(__alloc());
2941227825Stheraven        __v.reserve(__recommend(__size_ + __n));
2942227825Stheraven        __v.__size_ = __size_ + __n;
2943227825Stheraven        __r = _VSTD::copy(cbegin(), __position, __v.begin());
2944227825Stheraven        _VSTD::copy_backward(__position, cend(), __v.end());
2945227825Stheraven        swap(__v);
2946227825Stheraven    }
2947227825Stheraven    _VSTD::copy(__first, __last, __r);
2948227825Stheraven    return __r;
2949227825Stheraven}
2950227825Stheraven
2951227825Stheraventemplate <class _Allocator>
2952227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
2953227825Stheraventypename vector<bool, _Allocator>::iterator
2954227825Stheravenvector<bool, _Allocator>::erase(const_iterator __position)
2955227825Stheraven{
2956227825Stheraven    iterator __r = __const_iterator_cast(__position);
2957227825Stheraven    _VSTD::copy(__position + 1, this->cend(), __r);
2958227825Stheraven    --__size_;
2959227825Stheraven    return __r;
2960227825Stheraven}
2961227825Stheraven
2962227825Stheraventemplate <class _Allocator>
2963227825Stheraventypename vector<bool, _Allocator>::iterator
2964227825Stheravenvector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
2965227825Stheraven{
2966227825Stheraven    iterator __r = __const_iterator_cast(__first);
2967227825Stheraven    difference_type __d = __last - __first;
2968227825Stheraven    _VSTD::copy(__last, this->cend(), __r);
2969227825Stheraven    __size_ -= __d;
2970227825Stheraven    return __r;
2971227825Stheraven}
2972227825Stheraven
2973227825Stheraventemplate <class _Allocator>
2974227825Stheravenvoid
2975227825Stheravenvector<bool, _Allocator>::swap(vector& __x)
2976227825Stheraven        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2977227825Stheraven                   __is_nothrow_swappable<allocator_type>::value)
2978227825Stheraven{
2979227825Stheraven    _VSTD::swap(this->__begin_, __x.__begin_);
2980227825Stheraven    _VSTD::swap(this->__size_, __x.__size_);
2981227825Stheraven    _VSTD::swap(this->__cap(), __x.__cap());
2982227825Stheraven    __swap_alloc(this->__alloc(), __x.__alloc());
2983227825Stheraven#ifdef _LIBCPP_DEBUG
2984227825Stheraven    iterator::swap(this, &__x);
2985227825Stheraven    const_iterator::swap(this, &__x);
2986227825Stheraven#endif  // _LIBCPP_DEBUG
2987227825Stheraven}
2988227825Stheraven
2989227825Stheraventemplate <class _Allocator>
2990227825Stheravenvoid
2991227825Stheravenvector<bool, _Allocator>::resize(size_type __sz, value_type __x)
2992227825Stheraven{
2993227825Stheraven    size_type __cs = size();
2994227825Stheraven    if (__cs < __sz)
2995227825Stheraven    {
2996227825Stheraven        iterator __r;
2997227825Stheraven        size_type __c = capacity();
2998227825Stheraven        size_type __n = __sz - __cs;
2999227825Stheraven        if (__n <= __c && __cs <= __c - __n)
3000227825Stheraven        {
3001227825Stheraven            __r = end();
3002227825Stheraven            __size_ += __n;
3003227825Stheraven        }
3004227825Stheraven        else
3005227825Stheraven        {
3006227825Stheraven            vector __v(__alloc());
3007227825Stheraven            __v.reserve(__recommend(__size_ + __n));
3008227825Stheraven            __v.__size_ = __size_ + __n;
3009227825Stheraven            __r = _VSTD::copy(cbegin(), cend(), __v.begin());
3010227825Stheraven            swap(__v);
3011227825Stheraven        }
3012227825Stheraven        _VSTD::fill_n(__r, __n, __x);
3013227825Stheraven    }
3014227825Stheraven    else
3015227825Stheraven        __size_ = __sz;
3016227825Stheraven}
3017227825Stheraven
3018227825Stheraventemplate <class _Allocator>
3019227825Stheravenvoid
3020227825Stheravenvector<bool, _Allocator>::flip() _NOEXCEPT
3021227825Stheraven{
3022227825Stheraven    // do middle whole words
3023227825Stheraven    size_type __n = __size_;
3024227825Stheraven    __storage_pointer __p = __begin_;
3025227825Stheraven    for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3026227825Stheraven        *__p = ~*__p;
3027227825Stheraven    // do last partial word
3028227825Stheraven    if (__n > 0)
3029227825Stheraven    {
3030227825Stheraven        __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3031227825Stheraven        __storage_type __b = *__p & __m;
3032227825Stheraven        *__p &= ~__m;
3033227825Stheraven        *__p |= ~__b & __m;
3034227825Stheraven    }
3035227825Stheraven}
3036227825Stheraven
3037227825Stheraventemplate <class _Allocator>
3038227825Stheravenbool
3039227825Stheravenvector<bool, _Allocator>::__invariants() const
3040227825Stheraven{
3041227825Stheraven    if (this->__begin_ == 0)
3042227825Stheraven    {
3043227825Stheraven        if (this->__size_ != 0 || this->__cap() != 0)
3044227825Stheraven            return false;
3045227825Stheraven    }
3046227825Stheraven    else
3047227825Stheraven    {
3048227825Stheraven        if (this->__cap() == 0)
3049227825Stheraven            return false;
3050227825Stheraven        if (this->__size_ > this->capacity())
3051227825Stheraven            return false;
3052227825Stheraven    }
3053227825Stheraven    return true;
3054227825Stheraven}
3055227825Stheraven
3056227825Stheraventemplate <class _Allocator>
3057227825Stheravensize_t
3058227825Stheravenvector<bool, _Allocator>::__hash_code() const _NOEXCEPT
3059227825Stheraven{
3060227825Stheraven    size_t __h = 0;
3061227825Stheraven    // do middle whole words
3062227825Stheraven    size_type __n = __size_;
3063227825Stheraven    __storage_pointer __p = __begin_;
3064227825Stheraven    for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3065227825Stheraven        __h ^= *__p;
3066227825Stheraven    // do last partial word
3067227825Stheraven    if (__n > 0)
3068227825Stheraven    {
3069227825Stheraven        const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3070227825Stheraven        __h ^= *__p & __m;
3071227825Stheraven    }
3072227825Stheraven    return __h;
3073227825Stheraven}
3074227825Stheraven
3075227825Stheraventemplate <class _Allocator>
3076227825Stheravenstruct _LIBCPP_VISIBLE hash<vector<bool, _Allocator> >
3077227825Stheraven    : public unary_function<vector<bool, _Allocator>, size_t>
3078227825Stheraven{
3079227825Stheraven    _LIBCPP_INLINE_VISIBILITY
3080227825Stheraven    size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
3081227825Stheraven        {return __vec.__hash_code();}
3082227825Stheraven};
3083227825Stheraven
3084227825Stheraventemplate <class _Tp, class _Allocator>
3085227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
3086227825Stheravenbool
3087227825Stheravenoperator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3088227825Stheraven{
3089227825Stheraven    const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
3090227825Stheraven    return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
3091227825Stheraven}
3092227825Stheraven
3093227825Stheraventemplate <class _Tp, class _Allocator>
3094227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
3095227825Stheravenbool
3096227825Stheravenoperator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3097227825Stheraven{
3098227825Stheraven    return !(__x == __y);
3099227825Stheraven}
3100227825Stheraven
3101227825Stheraventemplate <class _Tp, class _Allocator>
3102227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
3103227825Stheravenbool
3104227825Stheravenoperator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3105227825Stheraven{
3106227825Stheraven    return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
3107227825Stheraven}
3108227825Stheraven
3109227825Stheraventemplate <class _Tp, class _Allocator>
3110227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
3111227825Stheravenbool
3112227825Stheravenoperator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3113227825Stheraven{
3114227825Stheraven    return __y < __x;
3115227825Stheraven}
3116227825Stheraven
3117227825Stheraventemplate <class _Tp, class _Allocator>
3118227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
3119227825Stheravenbool
3120227825Stheravenoperator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3121227825Stheraven{
3122227825Stheraven    return !(__x < __y);
3123227825Stheraven}
3124227825Stheraven
3125227825Stheraventemplate <class _Tp, class _Allocator>
3126227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
3127227825Stheravenbool
3128227825Stheravenoperator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3129227825Stheraven{
3130227825Stheraven    return !(__y < __x);
3131227825Stheraven}
3132227825Stheraven
3133227825Stheraventemplate <class _Tp, class _Allocator>
3134227825Stheraven_LIBCPP_INLINE_VISIBILITY inline
3135227825Stheravenvoid
3136227825Stheravenswap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
3137227825Stheraven    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
3138227825Stheraven{
3139227825Stheraven    __x.swap(__y);
3140227825Stheraven}
3141227825Stheraven
3142227825Stheraven_LIBCPP_END_NAMESPACE_STD
3143227825Stheraven
3144227825Stheraven#endif  // _LIBCPP_VECTOR
3145