xref: /llvm-project-15.0.7/libcxx/include/vector (revision 7f01ac39)
1// -*- C++ -*-
2//===------------------------------ vector --------------------------------===//
3//
4//                     The LLVM Compiler Infrastructure
5//
6// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_VECTOR
12#define _LIBCPP_VECTOR
13
14/*
15    vector synopsis
16
17namespace std
18{
19
20template <class T, class Allocator = allocator<T> >
21class vector
22{
23public:
24    typedef T                                        value_type;
25    typedef Allocator                                allocator_type;
26    typedef typename allocator_type::reference       reference;
27    typedef typename allocator_type::const_reference const_reference;
28    typedef implementation-defined                   iterator;
29    typedef implementation-defined                   const_iterator;
30    typedef typename allocator_type::size_type       size_type;
31    typedef typename allocator_type::difference_type difference_type;
32    typedef typename allocator_type::pointer         pointer;
33    typedef typename allocator_type::const_pointer   const_pointer;
34    typedef std::reverse_iterator<iterator>          reverse_iterator;
35    typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
36
37    vector()
38        noexcept(is_nothrow_default_constructible<allocator_type>::value);
39    explicit vector(const allocator_type&);
40    explicit vector(size_type n);
41    vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
42    template <class InputIterator>
43        vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
44    vector(const vector& x);
45    vector(vector&& x)
46        noexcept(is_nothrow_move_constructible<allocator_type>::value);
47    vector(initializer_list<value_type> il);
48    vector(initializer_list<value_type> il, const allocator_type& a);
49    ~vector();
50    vector& operator=(const vector& x);
51    vector& operator=(vector&& x)
52        noexcept(
53             allocator_type::propagate_on_container_move_assignment::value &&
54             is_nothrow_move_assignable<allocator_type>::value);
55    vector& operator=(initializer_list<value_type> il);
56    template <class InputIterator>
57        void assign(InputIterator first, InputIterator last);
58    void assign(size_type n, const value_type& u);
59    void assign(initializer_list<value_type> il);
60
61    allocator_type get_allocator() const noexcept;
62
63    iterator               begin() noexcept;
64    const_iterator         begin()   const noexcept;
65    iterator               end() noexcept;
66    const_iterator         end()     const noexcept;
67
68    reverse_iterator       rbegin() noexcept;
69    const_reverse_iterator rbegin()  const noexcept;
70    reverse_iterator       rend() noexcept;
71    const_reverse_iterator rend()    const noexcept;
72
73    const_iterator         cbegin()  const noexcept;
74    const_iterator         cend()    const noexcept;
75    const_reverse_iterator crbegin() const noexcept;
76    const_reverse_iterator crend()   const noexcept;
77
78    size_type size() const noexcept;
79    size_type max_size() const noexcept;
80    size_type capacity() const noexcept;
81    bool empty() const noexcept;
82    void reserve(size_type n);
83    void shrink_to_fit() noexcept;
84
85    reference       operator[](size_type n);
86    const_reference operator[](size_type n) const;
87    reference       at(size_type n);
88    const_reference at(size_type n) const;
89
90    reference       front();
91    const_reference front() const;
92    reference       back();
93    const_reference back() const;
94
95    value_type*       data() noexcept;
96    const value_type* data() const noexcept;
97
98    void push_back(const value_type& x);
99    void push_back(value_type&& x);
100    template <class... Args>
101        void emplace_back(Args&&... args);
102    void pop_back();
103
104    template <class... Args> iterator emplace(const_iterator position, Args&&... args);
105    iterator insert(const_iterator position, const value_type& x);
106    iterator insert(const_iterator position, value_type&& x);
107    iterator insert(const_iterator position, size_type n, const value_type& x);
108    template <class InputIterator>
109        iterator insert(const_iterator position, InputIterator first, InputIterator last);
110    iterator insert(const_iterator position, initializer_list<value_type> il);
111
112    iterator erase(const_iterator position);
113    iterator erase(const_iterator first, const_iterator last);
114
115    void clear() noexcept;
116
117    void resize(size_type sz);
118    void resize(size_type sz, const value_type& c);
119
120    void swap(vector&)
121        noexcept(!allocator_type::propagate_on_container_swap::value ||
122                 __is_nothrow_swappable<allocator_type>::value);
123
124    bool __invariants() const;
125};
126
127template <class Allocator = allocator<T> >
128class vector<bool, Allocator>
129{
130public:
131    typedef bool                                     value_type;
132    typedef Allocator                                allocator_type;
133    typedef implementation-defined                   iterator;
134    typedef implementation-defined                   const_iterator;
135    typedef typename allocator_type::size_type       size_type;
136    typedef typename allocator_type::difference_type difference_type;
137    typedef iterator                                 pointer;
138    typedef const_iterator                           const_pointer;
139    typedef std::reverse_iterator<iterator>          reverse_iterator;
140    typedef std::reverse_iterator<const_iterator>    const_reverse_iterator;
141
142    class reference
143    {
144    public:
145        reference(const reference&) noexcept;
146        operator bool() const noexcept;
147        reference& operator=(const bool x) noexcept;
148        reference& operator=(const reference& x) noexcept;
149        iterator operator&() const noexcept;
150        void flip() noexcept;
151    };
152
153    class const_reference
154    {
155    public:
156        const_reference(const reference&) noexcept;
157        operator bool() const noexcept;
158        const_iterator operator&() const noexcept;
159    };
160
161    vector()
162        noexcept(is_nothrow_default_constructible<allocator_type>::value);
163    explicit vector(const allocator_type&);
164    explicit vector(size_type n, const value_type& value = value_type(), const allocator_type& = allocator_type());
165    template <class InputIterator>
166        vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
167    vector(const vector& x);
168    vector(vector&& x)
169        noexcept(is_nothrow_move_constructible<allocator_type>::value);
170    vector(initializer_list<value_type> il);
171    vector(initializer_list<value_type> il, const allocator_type& a);
172    ~vector();
173    vector& operator=(const vector& x);
174    vector& operator=(vector&& x)
175        noexcept(
176             allocator_type::propagate_on_container_move_assignment::value &&
177             is_nothrow_move_assignable<allocator_type>::value);
178    vector& operator=(initializer_list<value_type> il);
179    template <class InputIterator>
180        void assign(InputIterator first, InputIterator last);
181    void assign(size_type n, const value_type& u);
182    void assign(initializer_list<value_type> il);
183
184    allocator_type get_allocator() const noexcept;
185
186    iterator               begin() noexcept;
187    const_iterator         begin()   const noexcept;
188    iterator               end() noexcept;
189    const_iterator         end()     const noexcept;
190
191    reverse_iterator       rbegin() noexcept;
192    const_reverse_iterator rbegin()  const noexcept;
193    reverse_iterator       rend() noexcept;
194    const_reverse_iterator rend()    const noexcept;
195
196    const_iterator         cbegin()  const noexcept;
197    const_iterator         cend()    const noexcept;
198    const_reverse_iterator crbegin() const noexcept;
199    const_reverse_iterator crend()   const noexcept;
200
201    size_type size() const noexcept;
202    size_type max_size() const noexcept;
203    size_type capacity() const noexcept;
204    bool empty() const noexcept;
205    void reserve(size_type n);
206    void shrink_to_fit() noexcept;
207
208    reference       operator[](size_type n);
209    const_reference operator[](size_type n) const;
210    reference       at(size_type n);
211    const_reference at(size_type n) const;
212
213    reference       front();
214    const_reference front() const;
215    reference       back();
216    const_reference back() const;
217
218    void push_back(const value_type& x);
219    void pop_back();
220
221    iterator insert(const_iterator position, const value_type& x);
222    iterator insert(const_iterator position, size_type n, const value_type& x);
223    template <class InputIterator>
224        iterator insert(const_iterator position, InputIterator first, InputIterator last);
225    iterator insert(const_iterator position, initializer_list<value_type> il);
226
227    iterator erase(const_iterator position);
228    iterator erase(const_iterator first, const_iterator last);
229
230    void clear() noexcept;
231
232    void resize(size_type sz);
233    void resize(size_type sz, value_type x);
234
235    void swap(vector&)
236        noexcept(!allocator_type::propagate_on_container_swap::value ||
237                 __is_nothrow_swappable<allocator_type>::value);
238    void flip() noexcept;
239
240    bool __invariants() const;
241};
242
243template <class Allocator> struct hash<std::vector<bool, Allocator>>;
244
245template <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
246template <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
247template <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
248template <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
249template <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
250template <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
251
252template <class T, class Allocator>
253void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
254    noexcept(noexcept(x.swap(y)));
255
256}  // std
257
258*/
259
260#include <__config>
261#include <__bit_reference>
262#include <type_traits>
263#include <climits>
264#include <limits>
265#include <initializer_list>
266#include <memory>
267#include <stdexcept>
268#include <algorithm>
269#include <cstring>
270#include <__split_buffer>
271#include <__functional_base>
272
273#pragma GCC system_header
274
275_LIBCPP_BEGIN_NAMESPACE_STD
276
277template <bool>
278class __vector_base_common
279{
280protected:
281    _LIBCPP_ALWAYS_INLINE __vector_base_common() {}
282    void __throw_length_error() const;
283    void __throw_out_of_range() const;
284};
285
286template <bool __b>
287void
288__vector_base_common<__b>::__throw_length_error() const
289{
290#ifndef _LIBCPP_NO_EXCEPTIONS
291    throw length_error("vector");
292#else
293    assert(!"vector length_error");
294#endif
295}
296
297template <bool __b>
298void
299__vector_base_common<__b>::__throw_out_of_range() const
300{
301#ifndef _LIBCPP_NO_EXCEPTIONS
302    throw out_of_range("vector");
303#else
304    assert(!"vector out_of_range");
305#endif
306}
307
308extern template class __vector_base_common<true>;
309
310template <class _Tp, class _Allocator>
311class __vector_base
312    : protected __vector_base_common<true>
313{
314protected:
315    typedef _Tp                                      value_type;
316    typedef _Allocator                               allocator_type;
317    typedef allocator_traits<allocator_type>         __alloc_traits;
318    typedef value_type&                              reference;
319    typedef const value_type&                        const_reference;
320    typedef typename __alloc_traits::size_type       size_type;
321    typedef typename __alloc_traits::difference_type difference_type;
322    typedef typename __alloc_traits::pointer         pointer;
323    typedef typename __alloc_traits::const_pointer   const_pointer;
324    typedef pointer                                  iterator;
325    typedef const_pointer                            const_iterator;
326
327    pointer                                         __begin_;
328    pointer                                         __end_;
329    __compressed_pair<pointer, allocator_type> __end_cap_;
330
331    _LIBCPP_INLINE_VISIBILITY
332    allocator_type& __alloc() _NOEXCEPT
333        {return __end_cap_.second();}
334    _LIBCPP_INLINE_VISIBILITY
335    const allocator_type& __alloc() const _NOEXCEPT
336        {return __end_cap_.second();}
337    _LIBCPP_INLINE_VISIBILITY
338    pointer& __end_cap() _NOEXCEPT
339        {return __end_cap_.first();}
340    _LIBCPP_INLINE_VISIBILITY
341    const pointer& __end_cap() const _NOEXCEPT
342        {return __end_cap_.first();}
343
344    _LIBCPP_INLINE_VISIBILITY
345    __vector_base()
346        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
347    _LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
348    ~__vector_base();
349
350    _LIBCPP_INLINE_VISIBILITY
351    void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
352    _LIBCPP_INLINE_VISIBILITY
353    size_type capacity() const _NOEXCEPT
354        {return static_cast<size_type>(__end_cap() - __begin_);}
355
356    _LIBCPP_INLINE_VISIBILITY
357    void __destruct_at_end(const_pointer __new_last) _NOEXCEPT
358        {__destruct_at_end(__new_last, is_trivially_destructible<value_type>());}
359    _LIBCPP_INLINE_VISIBILITY
360    void __destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT;
361    _LIBCPP_INLINE_VISIBILITY
362    void __destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT;
363
364    _LIBCPP_INLINE_VISIBILITY
365    void __copy_assign_alloc(const __vector_base& __c)
366        {__copy_assign_alloc(__c, integral_constant<bool,
367                      __alloc_traits::propagate_on_container_copy_assignment::value>());}
368
369    _LIBCPP_INLINE_VISIBILITY
370    void __move_assign_alloc(__vector_base& __c)
371        _NOEXCEPT_(
372            !__alloc_traits::propagate_on_container_move_assignment::value ||
373            is_nothrow_move_assignable<allocator_type>::value)
374        {__move_assign_alloc(__c, integral_constant<bool,
375                      __alloc_traits::propagate_on_container_move_assignment::value>());}
376
377    _LIBCPP_INLINE_VISIBILITY
378    static void __swap_alloc(allocator_type& __x, allocator_type& __y)
379        _NOEXCEPT_(
380            !__alloc_traits::propagate_on_container_swap::value ||
381            __is_nothrow_swappable<allocator_type>::value)
382        {__swap_alloc(__x, __y, integral_constant<bool,
383                      __alloc_traits::propagate_on_container_swap::value>());}
384private:
385    _LIBCPP_INLINE_VISIBILITY
386    void __copy_assign_alloc(const __vector_base& __c, true_type)
387        {
388            if (__alloc() != __c.__alloc())
389            {
390                clear();
391                __alloc_traits::deallocate(__alloc(), __begin_, capacity());
392                __begin_ = __end_ = __end_cap() = nullptr;
393            }
394            __alloc() = __c.__alloc();
395        }
396
397    _LIBCPP_INLINE_VISIBILITY
398    void __copy_assign_alloc(const __vector_base& __c, false_type)
399        {}
400
401    _LIBCPP_INLINE_VISIBILITY
402    void __move_assign_alloc(__vector_base& __c, true_type)
403        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
404        {
405            __alloc() = _VSTD::move(__c.__alloc());
406        }
407
408    _LIBCPP_INLINE_VISIBILITY
409    void __move_assign_alloc(__vector_base& __c, false_type)
410        _NOEXCEPT
411        {}
412
413    _LIBCPP_INLINE_VISIBILITY
414    static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
415        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
416        {
417            using _VSTD::swap;
418            swap(__x, __y);
419        }
420    _LIBCPP_INLINE_VISIBILITY
421    static void __swap_alloc(allocator_type& __x, allocator_type& __y, false_type)
422        _NOEXCEPT
423        {}
424};
425
426template <class _Tp, class _Allocator>
427_LIBCPP_INLINE_VISIBILITY inline
428void
429__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT
430{
431    while (__new_last < __end_)
432        __alloc_traits::destroy(__alloc(), const_cast<pointer>(--__end_));
433}
434
435template <class _Tp, class _Allocator>
436_LIBCPP_INLINE_VISIBILITY inline
437void
438__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT
439{
440    __end_ = const_cast<pointer>(__new_last);
441}
442
443template <class _Tp, class _Allocator>
444_LIBCPP_INLINE_VISIBILITY inline
445__vector_base<_Tp, _Allocator>::__vector_base()
446        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
447    : __begin_(0),
448      __end_(0),
449      __end_cap_(0)
450{
451}
452
453template <class _Tp, class _Allocator>
454_LIBCPP_INLINE_VISIBILITY inline
455__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
456    : __begin_(0),
457      __end_(0),
458      __end_cap_(0, __a)
459{
460}
461
462template <class _Tp, class _Allocator>
463__vector_base<_Tp, _Allocator>::~__vector_base()
464{
465    if (__begin_ != 0)
466    {
467        clear();
468        __alloc_traits::deallocate(__alloc(), __begin_, capacity());
469    }
470}
471
472template <class _Tp, class _Allocator = allocator<_Tp> >
473class _LIBCPP_VISIBLE vector
474    : private __vector_base<_Tp, _Allocator>
475{
476private:
477    typedef __vector_base<_Tp, _Allocator>           __base;
478public:
479    typedef vector                                   __self;
480    typedef _Tp                                      value_type;
481    typedef _Allocator                               allocator_type;
482    typedef typename __base::__alloc_traits          __alloc_traits;
483    typedef typename __base::reference               reference;
484    typedef typename __base::const_reference         const_reference;
485    typedef typename __base::size_type               size_type;
486    typedef typename __base::difference_type         difference_type;
487    typedef typename __base::pointer                 pointer;
488    typedef typename __base::const_pointer           const_pointer;
489    typedef __wrap_iter<pointer>                     iterator;
490    typedef __wrap_iter<const_pointer>               const_iterator;
491    typedef _VSTD::reverse_iterator<iterator>         reverse_iterator;
492    typedef _VSTD::reverse_iterator<const_iterator>   const_reverse_iterator;
493
494    _LIBCPP_INLINE_VISIBILITY
495    vector()
496        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
497        {
498#if _LIBCPP_DEBUG_LEVEL >= 2
499            __get_db()->__insert_c(this);
500#endif
501        }
502    _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
503        : __base(__a)
504    {
505#if _LIBCPP_DEBUG_LEVEL >= 2
506        __get_db()->__insert_c(this);
507#endif
508    }
509    explicit vector(size_type __n);
510    vector(size_type __n, const_reference __x);
511    vector(size_type __n, const_reference __x, const allocator_type& __a);
512    template <class _InputIterator>
513        vector(_InputIterator __first, _InputIterator __last,
514               typename enable_if<__is_input_iterator  <_InputIterator>::value &&
515                                 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
516    template <class _InputIterator>
517        vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
518               typename enable_if<__is_input_iterator  <_InputIterator>::value &&
519                                 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
520    template <class _ForwardIterator>
521        vector(_ForwardIterator __first, _ForwardIterator __last,
522               typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
523    template <class _ForwardIterator>
524        vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
525               typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
526#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
527    _LIBCPP_INLINE_VISIBILITY
528    vector(initializer_list<value_type> __il);
529    _LIBCPP_INLINE_VISIBILITY
530    vector(initializer_list<value_type> __il, const allocator_type& __a);
531#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
532#if _LIBCPP_DEBUG_LEVEL >= 2
533    _LIBCPP_INLINE_VISIBILITY
534    ~vector()
535    {
536        __get_db()->__erase_c(this);
537    }
538#endif
539
540    vector(const vector& __x);
541    vector(const vector& __x, const allocator_type& __a);
542    _LIBCPP_INLINE_VISIBILITY
543    vector& operator=(const vector& __x);
544#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
545    _LIBCPP_INLINE_VISIBILITY
546    vector(vector&& __x)
547        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
548    _LIBCPP_INLINE_VISIBILITY
549    vector(vector&& __x, const allocator_type& __a);
550    _LIBCPP_INLINE_VISIBILITY
551    vector& operator=(vector&& __x)
552        _NOEXCEPT_(
553             __alloc_traits::propagate_on_container_move_assignment::value &&
554             is_nothrow_move_assignable<allocator_type>::value);
555#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
556#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
557    _LIBCPP_INLINE_VISIBILITY
558    vector& operator=(initializer_list<value_type> __il)
559        {assign(__il.begin(), __il.end()); return *this;}
560#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
561
562    template <class _InputIterator>
563        typename enable_if
564        <
565             __is_input_iterator  <_InputIterator>::value &&
566            !__is_forward_iterator<_InputIterator>::value,
567            void
568        >::type
569        assign(_InputIterator __first, _InputIterator __last);
570    template <class _ForwardIterator>
571        typename enable_if
572        <
573            __is_forward_iterator<_ForwardIterator>::value,
574            void
575        >::type
576        assign(_ForwardIterator __first, _ForwardIterator __last);
577
578    void assign(size_type __n, const_reference __u);
579#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
580    _LIBCPP_INLINE_VISIBILITY
581    void assign(initializer_list<value_type> __il)
582        {assign(__il.begin(), __il.end());}
583#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
584
585    _LIBCPP_INLINE_VISIBILITY
586    allocator_type get_allocator() const _NOEXCEPT
587        {return this->__alloc();}
588
589    _LIBCPP_INLINE_VISIBILITY iterator               begin() _NOEXCEPT;
590    _LIBCPP_INLINE_VISIBILITY const_iterator         begin()   const _NOEXCEPT;
591    _LIBCPP_INLINE_VISIBILITY iterator               end() _NOEXCEPT;
592    _LIBCPP_INLINE_VISIBILITY const_iterator         end()     const _NOEXCEPT;
593
594    _LIBCPP_INLINE_VISIBILITY
595    reverse_iterator       rbegin() _NOEXCEPT
596        {return       reverse_iterator(end());}
597    _LIBCPP_INLINE_VISIBILITY
598    const_reverse_iterator rbegin()  const _NOEXCEPT
599        {return const_reverse_iterator(end());}
600    _LIBCPP_INLINE_VISIBILITY
601    reverse_iterator       rend() _NOEXCEPT
602        {return       reverse_iterator(begin());}
603    _LIBCPP_INLINE_VISIBILITY
604    const_reverse_iterator rend()    const _NOEXCEPT
605        {return const_reverse_iterator(begin());}
606
607    _LIBCPP_INLINE_VISIBILITY
608    const_iterator         cbegin()  const _NOEXCEPT
609        {return begin();}
610    _LIBCPP_INLINE_VISIBILITY
611    const_iterator         cend()    const _NOEXCEPT
612        {return end();}
613    _LIBCPP_INLINE_VISIBILITY
614    const_reverse_iterator crbegin() const _NOEXCEPT
615        {return rbegin();}
616    _LIBCPP_INLINE_VISIBILITY
617    const_reverse_iterator crend()   const _NOEXCEPT
618        {return rend();}
619
620    _LIBCPP_INLINE_VISIBILITY
621    size_type size() const _NOEXCEPT
622        {return static_cast<size_type>(this->__end_ - this->__begin_);}
623    _LIBCPP_INLINE_VISIBILITY
624    size_type capacity() const _NOEXCEPT
625        {return __base::capacity();}
626    _LIBCPP_INLINE_VISIBILITY
627    bool empty() const _NOEXCEPT
628        {return this->__begin_ == this->__end_;}
629    size_type max_size() const _NOEXCEPT;
630    void reserve(size_type __n);
631    void shrink_to_fit() _NOEXCEPT;
632
633    _LIBCPP_INLINE_VISIBILITY reference       operator[](size_type __n);
634    _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const;
635    reference       at(size_type __n);
636    const_reference at(size_type __n) const;
637
638    _LIBCPP_INLINE_VISIBILITY reference       front()
639    {
640        _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
641        return *this->__begin_;
642    }
643    _LIBCPP_INLINE_VISIBILITY const_reference front() const
644    {
645        _LIBCPP_ASSERT(!empty(), "front() called for empty vector");
646        return *this->__begin_;
647    }
648    _LIBCPP_INLINE_VISIBILITY reference       back()
649    {
650        _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
651        return *(this->__end_ - 1);
652    }
653    _LIBCPP_INLINE_VISIBILITY const_reference back()  const
654    {
655        _LIBCPP_ASSERT(!empty(), "back() called for empty vector");
656        return *(this->__end_ - 1);
657    }
658
659    _LIBCPP_INLINE_VISIBILITY
660    value_type*       data() _NOEXCEPT
661        {return _VSTD::__to_raw_pointer(this->__begin_);}
662    _LIBCPP_INLINE_VISIBILITY
663    const value_type* data() const _NOEXCEPT
664        {return _VSTD::__to_raw_pointer(this->__begin_);}
665
666    _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
667#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
668    void push_back(value_type&& __x);
669#ifndef _LIBCPP_HAS_NO_VARIADICS
670    template <class... _Args>
671        void emplace_back(_Args&&... __args);
672#endif  // _LIBCPP_HAS_NO_VARIADICS
673#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
674    void pop_back();
675
676    iterator insert(const_iterator __position, const_reference __x);
677#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
678    iterator insert(const_iterator __position, value_type&& __x);
679#ifndef _LIBCPP_HAS_NO_VARIADICS
680    template <class... _Args>
681        iterator emplace(const_iterator __position, _Args&&... __args);
682#endif  // _LIBCPP_HAS_NO_VARIADICS
683#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
684    iterator insert(const_iterator __position, size_type __n, const_reference __x);
685    template <class _InputIterator>
686        typename enable_if
687        <
688             __is_input_iterator  <_InputIterator>::value &&
689            !__is_forward_iterator<_InputIterator>::value,
690            iterator
691        >::type
692        insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
693    template <class _ForwardIterator>
694        typename enable_if
695        <
696            __is_forward_iterator<_ForwardIterator>::value,
697            iterator
698        >::type
699        insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
700#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
701    _LIBCPP_INLINE_VISIBILITY
702    iterator insert(const_iterator __position, initializer_list<value_type> __il)
703        {return insert(__position, __il.begin(), __il.end());}
704#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
705
706    _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
707    iterator erase(const_iterator __first, const_iterator __last);
708
709    _LIBCPP_INLINE_VISIBILITY
710    void clear() _NOEXCEPT
711    {
712        __base::clear();
713        __invalidate_all_iterators();
714    }
715
716    void resize(size_type __sz);
717    void resize(size_type __sz, const_reference __x);
718
719    void swap(vector&)
720        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
721                   __is_nothrow_swappable<allocator_type>::value);
722
723    bool __invariants() const;
724
725#if _LIBCPP_DEBUG_LEVEL >= 2
726
727    bool __dereferenceable(const const_iterator* __i) const;
728    bool __decrementable(const const_iterator* __i) const;
729    bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
730    bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
731
732#endif  // _LIBCPP_DEBUG_LEVEL >= 2
733
734private:
735    _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
736    void allocate(size_type __n);
737    void deallocate() _NOEXCEPT;
738    _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
739    void __construct_at_end(size_type __n);
740    void __construct_at_end(size_type __n, const_reference __x);
741    template <class _ForwardIterator>
742        typename enable_if
743        <
744            __is_forward_iterator<_ForwardIterator>::value,
745            void
746        >::type
747        __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
748    void __move_construct_at_end(pointer __first, pointer __last);
749    void __append(size_type __n);
750    void __append(size_type __n, const_reference __x);
751    _LIBCPP_INLINE_VISIBILITY
752    iterator       __make_iter(pointer __p) _NOEXCEPT;
753    _LIBCPP_INLINE_VISIBILITY
754    const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
755    void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
756    pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
757    void __move_range(pointer __from_s, pointer __from_e, pointer __to);
758    void __move_assign(vector& __c, true_type)
759        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
760    void __move_assign(vector& __c, false_type);
761    _LIBCPP_INLINE_VISIBILITY
762    void __destruct_at_end(const_pointer __new_last) _NOEXCEPT
763    {
764#if _LIBCPP_DEBUG_LEVEL >= 2
765        __c_node* __c = __get_db()->__find_c_and_lock(this);
766        for (__i_node** __p = __c->end_; __p != __c->beg_; )
767        {
768            --__p;
769            const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
770            if (__i->base() > __new_last)
771            {
772                (*__p)->__c_ = nullptr;
773                if (--__c->end_ != __p)
774                    memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
775            }
776        }
777        __get_db()->unlock();
778#endif
779        __base::__destruct_at_end(__new_last);
780    }
781};
782
783template <class _Tp, class _Allocator>
784void
785vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
786{
787    for (pointer __p = this->__end_; this->__begin_ < __p;)
788        __v.push_front(_VSTD::move_if_noexcept(*--__p));
789    _VSTD::swap(this->__begin_, __v.__begin_);
790    _VSTD::swap(this->__end_, __v.__end_);
791    _VSTD::swap(this->__end_cap(), __v.__end_cap());
792    __v.__first_ = __v.__begin_;
793    __invalidate_all_iterators();
794}
795
796template <class _Tp, class _Allocator>
797typename vector<_Tp, _Allocator>::pointer
798vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
799{
800    pointer __r = __v.__begin_;
801    for (pointer __i = __p; this->__begin_ < __i;)
802        __v.push_front(_VSTD::move_if_noexcept(*--__i));
803    for (pointer __i = __p; __i < this->__end_; ++__i)
804        __v.push_back(_VSTD::move_if_noexcept(*__i));
805    _VSTD::swap(this->__begin_, __v.__begin_);
806    _VSTD::swap(this->__end_, __v.__end_);
807    _VSTD::swap(this->__end_cap(), __v.__end_cap());
808    __v.__first_ = __v.__begin_;
809    __invalidate_all_iterators();
810    return __r;
811}
812
813//  Allocate space for __n objects
814//  throws length_error if __n > max_size()
815//  throws (probably bad_alloc) if memory run out
816//  Precondition:  __begin_ == __end_ == __end_cap() == 0
817//  Precondition:  __n > 0
818//  Postcondition:  capacity() == __n
819//  Postcondition:  size() == 0
820template <class _Tp, class _Allocator>
821void
822vector<_Tp, _Allocator>::allocate(size_type __n)
823{
824    if (__n > max_size())
825        this->__throw_length_error();
826    this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
827    this->__end_cap() = this->__begin_ + __n;
828}
829
830template <class _Tp, class _Allocator>
831void
832vector<_Tp, _Allocator>::deallocate() _NOEXCEPT
833{
834    if (this->__begin_ != 0)
835    {
836        clear();
837        __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
838        this->__begin_ = this->__end_ = this->__end_cap() = 0;
839    }
840}
841
842template <class _Tp, class _Allocator>
843typename vector<_Tp, _Allocator>::size_type
844vector<_Tp, _Allocator>::max_size() const _NOEXCEPT
845{
846    return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()), numeric_limits<size_type>::max() / 2);  // end() >= begin(), always
847}
848
849//  Precondition:  __new_size > capacity()
850template <class _Tp, class _Allocator>
851_LIBCPP_INLINE_VISIBILITY inline
852typename vector<_Tp, _Allocator>::size_type
853vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
854{
855    const size_type __ms = max_size();
856    if (__new_size > __ms)
857        this->__throw_length_error();
858    const size_type __cap = capacity();
859    if (__cap >= __ms / 2)
860        return __ms;
861    return _VSTD::max<size_type>(2*__cap, __new_size);
862}
863
864//  Default constructs __n objects starting at __end_
865//  throws if construction throws
866//  Precondition:  __n > 0
867//  Precondition:  size() + __n <= capacity()
868//  Postcondition:  size() == size() + __n
869template <class _Tp, class _Allocator>
870void
871vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
872{
873    allocator_type& __a = this->__alloc();
874    do
875    {
876        __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_));
877        ++this->__end_;
878        --__n;
879    } while (__n > 0);
880}
881
882//  Copy constructs __n objects starting at __end_ from __x
883//  throws if construction throws
884//  Precondition:  __n > 0
885//  Precondition:  size() + __n <= capacity()
886//  Postcondition:  size() == old size() + __n
887//  Postcondition:  [i] == __x for all i in [size() - __n, __n)
888template <class _Tp, class _Allocator>
889_LIBCPP_INLINE_VISIBILITY inline
890void
891vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
892{
893    allocator_type& __a = this->__alloc();
894    do
895    {
896        __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x);
897        ++this->__end_;
898        --__n;
899    } while (__n > 0);
900}
901
902template <class _Tp, class _Allocator>
903template <class _ForwardIterator>
904typename enable_if
905<
906    __is_forward_iterator<_ForwardIterator>::value,
907    void
908>::type
909vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
910{
911    allocator_type& __a = this->__alloc();
912    for (; __first != __last; ++__first)
913    {
914        __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first);
915        ++this->__end_;
916    }
917}
918
919template <class _Tp, class _Allocator>
920void
921vector<_Tp, _Allocator>::__move_construct_at_end(pointer __first, pointer __last)
922{
923    allocator_type& __a = this->__alloc();
924    for (; __first != __last; ++__first)
925    {
926        __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
927                                  _VSTD::move(*__first));
928        ++this->__end_;
929    }
930}
931
932//  Default constructs __n objects starting at __end_
933//  throws if construction throws
934//  Postcondition:  size() == size() + __n
935//  Exception safety: strong.
936template <class _Tp, class _Allocator>
937void
938vector<_Tp, _Allocator>::__append(size_type __n)
939{
940    if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
941        this->__construct_at_end(__n);
942    else
943    {
944        allocator_type& __a = this->__alloc();
945        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
946        __v.__construct_at_end(__n);
947        __swap_out_circular_buffer(__v);
948    }
949}
950
951//  Default constructs __n objects starting at __end_
952//  throws if construction throws
953//  Postcondition:  size() == size() + __n
954//  Exception safety: strong.
955template <class _Tp, class _Allocator>
956void
957vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
958{
959    if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
960        this->__construct_at_end(__n, __x);
961    else
962    {
963        allocator_type& __a = this->__alloc();
964        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
965        __v.__construct_at_end(__n, __x);
966        __swap_out_circular_buffer(__v);
967    }
968}
969
970template <class _Tp, class _Allocator>
971vector<_Tp, _Allocator>::vector(size_type __n)
972{
973#if _LIBCPP_DEBUG_LEVEL >= 2
974    __get_db()->__insert_c(this);
975#endif
976    if (__n > 0)
977    {
978        allocate(__n);
979        __construct_at_end(__n);
980    }
981}
982
983template <class _Tp, class _Allocator>
984vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x)
985{
986#if _LIBCPP_DEBUG_LEVEL >= 2
987    __get_db()->__insert_c(this);
988#endif
989    if (__n > 0)
990    {
991        allocate(__n);
992        __construct_at_end(__n, __x);
993    }
994}
995
996template <class _Tp, class _Allocator>
997vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a)
998    : __base(__a)
999{
1000#if _LIBCPP_DEBUG_LEVEL >= 2
1001    __get_db()->__insert_c(this);
1002#endif
1003    if (__n > 0)
1004    {
1005        allocate(__n);
1006        __construct_at_end(__n, __x);
1007    }
1008}
1009
1010template <class _Tp, class _Allocator>
1011template <class _InputIterator>
1012vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
1013       typename enable_if<__is_input_iterator  <_InputIterator>::value &&
1014                         !__is_forward_iterator<_InputIterator>::value>::type*)
1015{
1016#if _LIBCPP_DEBUG_LEVEL >= 2
1017    __get_db()->__insert_c(this);
1018#endif
1019    for (; __first != __last; ++__first)
1020        push_back(*__first);
1021}
1022
1023template <class _Tp, class _Allocator>
1024template <class _InputIterator>
1025vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
1026       typename enable_if<__is_input_iterator  <_InputIterator>::value &&
1027                         !__is_forward_iterator<_InputIterator>::value>::type*)
1028    : __base(__a)
1029{
1030#if _LIBCPP_DEBUG_LEVEL >= 2
1031    __get_db()->__insert_c(this);
1032#endif
1033    for (; __first != __last; ++__first)
1034        push_back(*__first);
1035}
1036
1037template <class _Tp, class _Allocator>
1038template <class _ForwardIterator>
1039vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
1040                                typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
1041{
1042#if _LIBCPP_DEBUG_LEVEL >= 2
1043    __get_db()->__insert_c(this);
1044#endif
1045    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
1046    if (__n > 0)
1047    {
1048        allocate(__n);
1049        __construct_at_end(__first, __last);
1050    }
1051}
1052
1053template <class _Tp, class _Allocator>
1054template <class _ForwardIterator>
1055vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
1056                                typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
1057    : __base(__a)
1058{
1059#if _LIBCPP_DEBUG_LEVEL >= 2
1060    __get_db()->__insert_c(this);
1061#endif
1062    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
1063    if (__n > 0)
1064    {
1065        allocate(__n);
1066        __construct_at_end(__first, __last);
1067    }
1068}
1069
1070template <class _Tp, class _Allocator>
1071vector<_Tp, _Allocator>::vector(const vector& __x)
1072    : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
1073{
1074#if _LIBCPP_DEBUG_LEVEL >= 2
1075    __get_db()->__insert_c(this);
1076#endif
1077    size_type __n = __x.size();
1078    if (__n > 0)
1079    {
1080        allocate(__n);
1081        __construct_at_end(__x.__begin_, __x.__end_);
1082    }
1083}
1084
1085template <class _Tp, class _Allocator>
1086vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
1087    : __base(__a)
1088{
1089#if _LIBCPP_DEBUG_LEVEL >= 2
1090    __get_db()->__insert_c(this);
1091#endif
1092    size_type __n = __x.size();
1093    if (__n > 0)
1094    {
1095        allocate(__n);
1096        __construct_at_end(__x.__begin_, __x.__end_);
1097    }
1098}
1099
1100#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1101
1102template <class _Tp, class _Allocator>
1103_LIBCPP_INLINE_VISIBILITY inline
1104vector<_Tp, _Allocator>::vector(vector&& __x)
1105        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
1106    : __base(_VSTD::move(__x.__alloc()))
1107{
1108#if _LIBCPP_DEBUG_LEVEL >= 2
1109    __get_db()->__insert_c(this);
1110    __get_db()->swap(this, &__x);
1111#endif
1112    this->__begin_ = __x.__begin_;
1113    this->__end_ = __x.__end_;
1114    this->__end_cap() = __x.__end_cap();
1115    __x.__begin_ = __x.__end_ = __x.__end_cap() = 0;
1116}
1117
1118template <class _Tp, class _Allocator>
1119_LIBCPP_INLINE_VISIBILITY inline
1120vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
1121    : __base(__a)
1122{
1123#if _LIBCPP_DEBUG_LEVEL >= 2
1124    __get_db()->__insert_c(this);
1125#endif
1126    if (__a == __x.__alloc())
1127    {
1128        this->__begin_ = __x.__begin_;
1129        this->__end_ = __x.__end_;
1130        this->__end_cap() = __x.__end_cap();
1131        __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1132#if _LIBCPP_DEBUG_LEVEL >= 2
1133        __get_db()->swap(this, &__x);
1134#endif
1135    }
1136    else
1137    {
1138        typedef move_iterator<iterator> _I;
1139        assign(_I(__x.begin()), _I(__x.end()));
1140    }
1141}
1142
1143#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1144
1145template <class _Tp, class _Allocator>
1146_LIBCPP_INLINE_VISIBILITY inline
1147vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
1148{
1149#if _LIBCPP_DEBUG_LEVEL >= 2
1150    __get_db()->__insert_c(this);
1151#endif
1152    if (__il.size() > 0)
1153    {
1154        allocate(__il.size());
1155        __construct_at_end(__il.begin(), __il.end());
1156    }
1157}
1158
1159template <class _Tp, class _Allocator>
1160_LIBCPP_INLINE_VISIBILITY inline
1161vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
1162    : __base(__a)
1163{
1164#if _LIBCPP_DEBUG_LEVEL >= 2
1165    __get_db()->__insert_c(this);
1166#endif
1167    if (__il.size() > 0)
1168    {
1169        allocate(__il.size());
1170        __construct_at_end(__il.begin(), __il.end());
1171    }
1172}
1173
1174#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1175
1176template <class _Tp, class _Allocator>
1177_LIBCPP_INLINE_VISIBILITY inline
1178vector<_Tp, _Allocator>&
1179vector<_Tp, _Allocator>::operator=(vector&& __x)
1180        _NOEXCEPT_(
1181             __alloc_traits::propagate_on_container_move_assignment::value &&
1182             is_nothrow_move_assignable<allocator_type>::value)
1183{
1184    __move_assign(__x, integral_constant<bool,
1185          __alloc_traits::propagate_on_container_move_assignment::value>());
1186    return *this;
1187}
1188
1189template <class _Tp, class _Allocator>
1190void
1191vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
1192{
1193    if (__base::__alloc() != __c.__alloc())
1194    {
1195        typedef move_iterator<iterator> _I;
1196        assign(_I(__c.begin()), _I(__c.end()));
1197    }
1198    else
1199        __move_assign(__c, true_type());
1200}
1201
1202template <class _Tp, class _Allocator>
1203void
1204vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
1205    _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1206{
1207    deallocate();
1208    this->__begin_ = __c.__begin_;
1209    this->__end_ = __c.__end_;
1210    this->__end_cap() = __c.__end_cap();
1211    __base::__move_assign_alloc(__c);
1212    __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
1213#if _LIBCPP_DEBUG_LEVEL >= 2
1214    __get_db()->swap(this, &__c);
1215#endif
1216}
1217
1218#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1219
1220template <class _Tp, class _Allocator>
1221_LIBCPP_INLINE_VISIBILITY inline
1222vector<_Tp, _Allocator>&
1223vector<_Tp, _Allocator>::operator=(const vector& __x)
1224{
1225    if (this != &__x)
1226    {
1227        __base::__copy_assign_alloc(__x);
1228        assign(__x.__begin_, __x.__end_);
1229    }
1230    return *this;
1231}
1232
1233template <class _Tp, class _Allocator>
1234template <class _InputIterator>
1235typename enable_if
1236<
1237     __is_input_iterator  <_InputIterator>::value &&
1238    !__is_forward_iterator<_InputIterator>::value,
1239    void
1240>::type
1241vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
1242{
1243    clear();
1244    for (; __first != __last; ++__first)
1245        push_back(*__first);
1246}
1247
1248template <class _Tp, class _Allocator>
1249template <class _ForwardIterator>
1250typename enable_if
1251<
1252    __is_forward_iterator<_ForwardIterator>::value,
1253    void
1254>::type
1255vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
1256{
1257    typename iterator_traits<_ForwardIterator>::difference_type __new_size = _VSTD::distance(__first, __last);
1258    if (static_cast<size_type>(__new_size) <= capacity())
1259    {
1260        _ForwardIterator __mid = __last;
1261        bool __growing = false;
1262        if (static_cast<size_type>(__new_size) > size())
1263        {
1264            __growing = true;
1265            __mid =  __first;
1266            _VSTD::advance(__mid, size());
1267        }
1268        pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
1269        if (__growing)
1270            __construct_at_end(__mid, __last);
1271        else
1272            this->__destruct_at_end(__m);
1273    }
1274    else
1275    {
1276        deallocate();
1277        allocate(__recommend(static_cast<size_type>(__new_size)));
1278        __construct_at_end(__first, __last);
1279    }
1280}
1281
1282template <class _Tp, class _Allocator>
1283void
1284vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
1285{
1286    if (__n <= capacity())
1287    {
1288        size_type __s = size();
1289        _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
1290        if (__n > __s)
1291            __construct_at_end(__n - __s, __u);
1292        else
1293            this->__destruct_at_end(this->__begin_ + __n);
1294    }
1295    else
1296    {
1297        deallocate();
1298        allocate(__recommend(static_cast<size_type>(__n)));
1299        __construct_at_end(__n, __u);
1300    }
1301}
1302
1303template <class _Tp, class _Allocator>
1304_LIBCPP_INLINE_VISIBILITY inline
1305typename vector<_Tp, _Allocator>::iterator
1306vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
1307{
1308#if _LIBCPP_DEBUG_LEVEL >= 2
1309    return iterator(this, __p);
1310#else
1311    return iterator(__p);
1312#endif
1313}
1314
1315template <class _Tp, class _Allocator>
1316_LIBCPP_INLINE_VISIBILITY inline
1317typename vector<_Tp, _Allocator>::const_iterator
1318vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
1319{
1320#if _LIBCPP_DEBUG_LEVEL >= 2
1321    return const_iterator(this, __p);
1322#else
1323    return const_iterator(__p);
1324#endif
1325}
1326
1327template <class _Tp, class _Allocator>
1328_LIBCPP_INLINE_VISIBILITY inline
1329typename vector<_Tp, _Allocator>::iterator
1330vector<_Tp, _Allocator>::begin() _NOEXCEPT
1331{
1332    return __make_iter(this->__begin_);
1333}
1334
1335template <class _Tp, class _Allocator>
1336_LIBCPP_INLINE_VISIBILITY inline
1337typename vector<_Tp, _Allocator>::const_iterator
1338vector<_Tp, _Allocator>::begin() const _NOEXCEPT
1339{
1340    return __make_iter(this->__begin_);
1341}
1342
1343template <class _Tp, class _Allocator>
1344_LIBCPP_INLINE_VISIBILITY inline
1345typename vector<_Tp, _Allocator>::iterator
1346vector<_Tp, _Allocator>::end() _NOEXCEPT
1347{
1348    return __make_iter(this->__end_);
1349}
1350
1351template <class _Tp, class _Allocator>
1352_LIBCPP_INLINE_VISIBILITY inline
1353typename vector<_Tp, _Allocator>::const_iterator
1354vector<_Tp, _Allocator>::end() const _NOEXCEPT
1355{
1356    return __make_iter(this->__end_);
1357}
1358
1359template <class _Tp, class _Allocator>
1360_LIBCPP_INLINE_VISIBILITY inline
1361typename vector<_Tp, _Allocator>::reference
1362vector<_Tp, _Allocator>::operator[](size_type __n)
1363{
1364    _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
1365    return this->__begin_[__n];
1366}
1367
1368template <class _Tp, class _Allocator>
1369_LIBCPP_INLINE_VISIBILITY inline
1370typename vector<_Tp, _Allocator>::const_reference
1371vector<_Tp, _Allocator>::operator[](size_type __n) const
1372{
1373    _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
1374    return this->__begin_[__n];
1375}
1376
1377template <class _Tp, class _Allocator>
1378typename vector<_Tp, _Allocator>::reference
1379vector<_Tp, _Allocator>::at(size_type __n)
1380{
1381    if (__n >= size())
1382        this->__throw_out_of_range();
1383    return this->__begin_[__n];
1384}
1385
1386template <class _Tp, class _Allocator>
1387typename vector<_Tp, _Allocator>::const_reference
1388vector<_Tp, _Allocator>::at(size_type __n) const
1389{
1390    if (__n >= size())
1391        this->__throw_out_of_range();
1392    return this->__begin_[__n];
1393}
1394
1395template <class _Tp, class _Allocator>
1396void
1397vector<_Tp, _Allocator>::reserve(size_type __n)
1398{
1399    if (__n > capacity())
1400    {
1401        allocator_type& __a = this->__alloc();
1402        __split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
1403        __swap_out_circular_buffer(__v);
1404    }
1405}
1406
1407template <class _Tp, class _Allocator>
1408void
1409vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
1410{
1411    if (capacity() > size())
1412    {
1413#ifndef _LIBCPP_NO_EXCEPTIONS
1414        try
1415        {
1416#endif  // _LIBCPP_NO_EXCEPTIONS
1417            allocator_type& __a = this->__alloc();
1418            __split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
1419            __swap_out_circular_buffer(__v);
1420#ifndef _LIBCPP_NO_EXCEPTIONS
1421        }
1422        catch (...)
1423        {
1424        }
1425#endif  // _LIBCPP_NO_EXCEPTIONS
1426    }
1427}
1428
1429template <class _Tp, class _Allocator>
1430void
1431vector<_Tp, _Allocator>::push_back(const_reference __x)
1432{
1433    if (this->__end_ < this->__end_cap())
1434    {
1435        __alloc_traits::construct(this->__alloc(),
1436                                  _VSTD::__to_raw_pointer(this->__end_), __x);
1437        ++this->__end_;
1438    }
1439    else
1440    {
1441        allocator_type& __a = this->__alloc();
1442        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1443        __v.push_back(__x);
1444        __swap_out_circular_buffer(__v);
1445    }
1446}
1447
1448#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1449
1450template <class _Tp, class _Allocator>
1451void
1452vector<_Tp, _Allocator>::push_back(value_type&& __x)
1453{
1454    if (this->__end_ < this->__end_cap())
1455    {
1456        __alloc_traits::construct(this->__alloc(),
1457                                  _VSTD::__to_raw_pointer(this->__end_),
1458                                  _VSTD::move(__x));
1459        ++this->__end_;
1460    }
1461    else
1462    {
1463        allocator_type& __a = this->__alloc();
1464        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1465        __v.push_back(_VSTD::move(__x));
1466        __swap_out_circular_buffer(__v);
1467    }
1468}
1469
1470#ifndef _LIBCPP_HAS_NO_VARIADICS
1471
1472template <class _Tp, class _Allocator>
1473template <class... _Args>
1474void
1475vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
1476{
1477    if (this->__end_ < this->__end_cap())
1478    {
1479        __alloc_traits::construct(this->__alloc(),
1480                                  _VSTD::__to_raw_pointer(this->__end_),
1481                                  _VSTD::forward<_Args>(__args)...);
1482        ++this->__end_;
1483    }
1484    else
1485    {
1486        allocator_type& __a = this->__alloc();
1487        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
1488        __v.emplace_back(_VSTD::forward<_Args>(__args)...);
1489        __swap_out_circular_buffer(__v);
1490    }
1491}
1492
1493#endif  // _LIBCPP_HAS_NO_VARIADICS
1494#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1495
1496template <class _Tp, class _Allocator>
1497_LIBCPP_INLINE_VISIBILITY inline
1498void
1499vector<_Tp, _Allocator>::pop_back()
1500{
1501    _LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector");
1502    this->__destruct_at_end(this->__end_ - 1);
1503}
1504
1505template <class _Tp, class _Allocator>
1506_LIBCPP_INLINE_VISIBILITY inline
1507typename vector<_Tp, _Allocator>::iterator
1508vector<_Tp, _Allocator>::erase(const_iterator __position)
1509{
1510#if _LIBCPP_DEBUG_LEVEL >= 2
1511    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1512        "vector::erase(iterator) called with an iterator not"
1513        " referring to this vector");
1514#endif
1515    pointer __p = const_cast<pointer>(&*__position);
1516    iterator __r = __make_iter(__p);
1517    this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
1518    return __r;
1519}
1520
1521template <class _Tp, class _Allocator>
1522typename vector<_Tp, _Allocator>::iterator
1523vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
1524{
1525#if _LIBCPP_DEBUG_LEVEL >= 2
1526    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
1527        "vector::erase(iterator,  iterator) called with an iterator not"
1528        " referring to this vector");
1529#endif
1530    _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
1531    pointer __p = this->__begin_ + (__first - begin());
1532    iterator __r = __make_iter(__p);
1533    this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
1534    return __r;
1535}
1536
1537template <class _Tp, class _Allocator>
1538void
1539vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
1540{
1541    pointer __old_last = this->__end_;
1542    difference_type __n = __old_last - __to;
1543    for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_)
1544        __alloc_traits::construct(this->__alloc(),
1545                                  _VSTD::__to_raw_pointer(this->__end_),
1546                                  _VSTD::move(*__i));
1547    _VSTD::move_backward(__from_s, __from_s + __n, __old_last);
1548}
1549
1550template <class _Tp, class _Allocator>
1551typename vector<_Tp, _Allocator>::iterator
1552vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
1553{
1554#if _LIBCPP_DEBUG_LEVEL >= 2
1555    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1556        "vector::insert(iterator, x) called with an iterator not"
1557        " referring to this vector");
1558#endif
1559    pointer __p = this->__begin_ + (__position - begin());
1560    if (this->__end_ < this->__end_cap())
1561    {
1562        if (__p == this->__end_)
1563        {
1564            __alloc_traits::construct(this->__alloc(),
1565                                      _VSTD::__to_raw_pointer(this->__end_), __x);
1566            ++this->__end_;
1567        }
1568        else
1569        {
1570            __move_range(__p, this->__end_, __p + 1);
1571            const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1572            if (__p <= __xr && __xr < this->__end_)
1573                ++__xr;
1574            *__p = *__xr;
1575        }
1576    }
1577    else
1578    {
1579        allocator_type& __a = this->__alloc();
1580        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1581        __v.push_back(__x);
1582        __p = __swap_out_circular_buffer(__v, __p);
1583    }
1584    return __make_iter(__p);
1585}
1586
1587#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1588
1589template <class _Tp, class _Allocator>
1590typename vector<_Tp, _Allocator>::iterator
1591vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
1592{
1593#if _LIBCPP_DEBUG_LEVEL >= 2
1594    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1595        "vector::insert(iterator, x) called with an iterator not"
1596        " referring to this vector");
1597#endif
1598    pointer __p = this->__begin_ + (__position - begin());
1599    if (this->__end_ < this->__end_cap())
1600    {
1601        if (__p == this->__end_)
1602        {
1603            __alloc_traits::construct(this->__alloc(),
1604                                      _VSTD::__to_raw_pointer(this->__end_),
1605                                      _VSTD::move(__x));
1606            ++this->__end_;
1607        }
1608        else
1609        {
1610            __move_range(__p, this->__end_, __p + 1);
1611            *__p = _VSTD::move(__x);
1612        }
1613    }
1614    else
1615    {
1616        allocator_type& __a = this->__alloc();
1617        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1618        __v.push_back(_VSTD::move(__x));
1619        __p = __swap_out_circular_buffer(__v, __p);
1620    }
1621    return __make_iter(__p);
1622}
1623
1624#ifndef _LIBCPP_HAS_NO_VARIADICS
1625
1626template <class _Tp, class _Allocator>
1627template <class... _Args>
1628typename vector<_Tp, _Allocator>::iterator
1629vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
1630{
1631#if _LIBCPP_DEBUG_LEVEL >= 2
1632    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1633        "vector::emplace(iterator, x) called with an iterator not"
1634        " referring to this vector");
1635#endif
1636    pointer __p = this->__begin_ + (__position - begin());
1637    if (this->__end_ < this->__end_cap())
1638    {
1639        if (__p == this->__end_)
1640        {
1641            __alloc_traits::construct(this->__alloc(),
1642                                      _VSTD::__to_raw_pointer(this->__end_),
1643                                      _VSTD::forward<_Args>(__args)...);
1644            ++this->__end_;
1645        }
1646        else
1647        {
1648            __move_range(__p, this->__end_, __p + 1);
1649            *__p = value_type(_VSTD::forward<_Args>(__args)...);
1650        }
1651    }
1652    else
1653    {
1654        allocator_type& __a = this->__alloc();
1655        __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
1656        __v.emplace_back(_VSTD::forward<_Args>(__args)...);
1657        __p = __swap_out_circular_buffer(__v, __p);
1658    }
1659    return __make_iter(__p);
1660}
1661
1662#endif  // _LIBCPP_HAS_NO_VARIADICS
1663#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1664
1665template <class _Tp, class _Allocator>
1666typename vector<_Tp, _Allocator>::iterator
1667vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
1668{
1669#if _LIBCPP_DEBUG_LEVEL >= 2
1670    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1671        "vector::insert(iterator, n, x) called with an iterator not"
1672        " referring to this vector");
1673#endif
1674    pointer __p = this->__begin_ + (__position - begin());
1675    if (__n > 0)
1676    {
1677        if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
1678        {
1679            size_type __old_n = __n;
1680            pointer __old_last = this->__end_;
1681            if (__n > static_cast<size_type>(this->__end_ - __p))
1682            {
1683                size_type __cx = __n - (this->__end_ - __p);
1684                __construct_at_end(__cx, __x);
1685                __n -= __cx;
1686            }
1687            if (__n > 0)
1688            {
1689                __move_range(__p, __old_last, __p + __old_n);
1690                const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
1691                if (__p <= __xr && __xr < this->__end_)
1692                    __xr += __old_n;
1693                _VSTD::fill_n(__p, __n, *__xr);
1694            }
1695        }
1696        else
1697        {
1698            allocator_type& __a = this->__alloc();
1699            __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1700            __v.__construct_at_end(__n, __x);
1701            __p = __swap_out_circular_buffer(__v, __p);
1702        }
1703    }
1704    return __make_iter(__p);
1705}
1706
1707template <class _Tp, class _Allocator>
1708template <class _InputIterator>
1709typename enable_if
1710<
1711     __is_input_iterator  <_InputIterator>::value &&
1712    !__is_forward_iterator<_InputIterator>::value,
1713    typename vector<_Tp, _Allocator>::iterator
1714>::type
1715vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
1716{
1717#if _LIBCPP_DEBUG_LEVEL >= 2
1718    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1719        "vector::insert(iterator, range) called with an iterator not"
1720        " referring to this vector");
1721#endif
1722    difference_type __off = __position - begin();
1723    pointer __p = this->__begin_ + __off;
1724    allocator_type& __a = this->__alloc();
1725    pointer __old_last = this->__end_;
1726    for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
1727    {
1728        __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_),
1729                                  *__first);
1730        ++this->__end_;
1731    }
1732    __split_buffer<value_type, allocator_type&> __v(__a);
1733    if (__first != __last)
1734    {
1735#ifndef _LIBCPP_NO_EXCEPTIONS
1736        try
1737        {
1738#endif  // _LIBCPP_NO_EXCEPTIONS
1739            __v.__construct_at_end(__first, __last);
1740            difference_type __old_size = __old_last - this->__begin_;
1741            difference_type __old_p = __p - this->__begin_;
1742            reserve(__recommend(size() + __v.size()));
1743            __p = this->__begin_ + __old_p;
1744            __old_last = this->__begin_ + __old_size;
1745#ifndef _LIBCPP_NO_EXCEPTIONS
1746        }
1747        catch (...)
1748        {
1749            erase(__make_iter(__old_last), end());
1750            throw;
1751        }
1752#endif  // _LIBCPP_NO_EXCEPTIONS
1753    }
1754    __p = _VSTD::rotate(__p, __old_last, this->__end_);
1755    insert(__make_iter(__p), make_move_iterator(__v.begin()),
1756                                    make_move_iterator(__v.end()));
1757    return begin() + __off;
1758}
1759
1760template <class _Tp, class _Allocator>
1761template <class _ForwardIterator>
1762typename enable_if
1763<
1764    __is_forward_iterator<_ForwardIterator>::value,
1765    typename vector<_Tp, _Allocator>::iterator
1766>::type
1767vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
1768{
1769#if _LIBCPP_DEBUG_LEVEL >= 2
1770    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
1771        "vector::insert(iterator, range) called with an iterator not"
1772        " referring to this vector");
1773#endif
1774    pointer __p = this->__begin_ + (__position - begin());
1775    difference_type __n = _VSTD::distance(__first, __last);
1776    if (__n > 0)
1777    {
1778        if (__n <= this->__end_cap() - this->__end_)
1779        {
1780            size_type __old_n = __n;
1781            pointer __old_last = this->__end_;
1782            _ForwardIterator __m = __last;
1783            difference_type __dx = this->__end_ - __p;
1784            if (__n > __dx)
1785            {
1786                __m = __first;
1787                _VSTD::advance(__m, this->__end_ - __p);
1788                __construct_at_end(__m, __last);
1789                __n = __dx;
1790            }
1791            if (__n > 0)
1792            {
1793                __move_range(__p, __old_last, __p + __old_n);
1794                _VSTD::copy(__first, __m, __p);
1795            }
1796        }
1797        else
1798        {
1799            allocator_type& __a = this->__alloc();
1800            __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
1801            __v.__construct_at_end(__first, __last);
1802            __p = __swap_out_circular_buffer(__v, __p);
1803        }
1804    }
1805    return __make_iter(__p);
1806}
1807
1808template <class _Tp, class _Allocator>
1809void
1810vector<_Tp, _Allocator>::resize(size_type __sz)
1811{
1812    size_type __cs = size();
1813    if (__cs < __sz)
1814        this->__append(__sz - __cs);
1815    else if (__cs > __sz)
1816        this->__destruct_at_end(this->__begin_ + __sz);
1817}
1818
1819template <class _Tp, class _Allocator>
1820void
1821vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
1822{
1823    size_type __cs = size();
1824    if (__cs < __sz)
1825        this->__append(__sz - __cs, __x);
1826    else if (__cs > __sz)
1827        this->__destruct_at_end(this->__begin_ + __sz);
1828}
1829
1830template <class _Tp, class _Allocator>
1831void
1832vector<_Tp, _Allocator>::swap(vector& __x)
1833        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1834                   __is_nothrow_swappable<allocator_type>::value)
1835{
1836    _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
1837                   this->__alloc() == __x.__alloc(),
1838                   "vector::swap: Either propagate_on_container_swap must be true"
1839                   " or the allocators must compare equal");
1840    _VSTD::swap(this->__begin_, __x.__begin_);
1841    _VSTD::swap(this->__end_, __x.__end_);
1842    _VSTD::swap(this->__end_cap(), __x.__end_cap());
1843    __base::__swap_alloc(this->__alloc(), __x.__alloc());
1844#if _LIBCPP_DEBUG_LEVEL >= 2
1845    __get_db()->swap(this, &__x);
1846#endif  // _LIBCPP_DEBUG_LEVEL >= 2
1847}
1848
1849template <class _Tp, class _Allocator>
1850bool
1851vector<_Tp, _Allocator>::__invariants() const
1852{
1853    if (this->__begin_ == 0)
1854    {
1855        if (this->__end_ != 0 || this->__end_cap() != 0)
1856            return false;
1857    }
1858    else
1859    {
1860        if (this->__begin_ > this->__end_)
1861            return false;
1862        if (this->__begin_ == this->__end_cap())
1863            return false;
1864        if (this->__end_ > this->__end_cap())
1865            return false;
1866    }
1867    return true;
1868}
1869
1870#if _LIBCPP_DEBUG_LEVEL >= 2
1871
1872template <class _Tp, class _Allocator>
1873bool
1874vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
1875{
1876    return this->__begin_ <= __i->base() && __i->base() < this->__end_;
1877}
1878
1879template <class _Tp, class _Allocator>
1880bool
1881vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
1882{
1883    return this->__begin_ < __i->base() && __i->base() <= this->__end_;
1884}
1885
1886template <class _Tp, class _Allocator>
1887bool
1888vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
1889{
1890    const_pointer __p = __i->base() + __n;
1891    return this->__begin_ <= __p && __p <= this->__end_;
1892}
1893
1894template <class _Tp, class _Allocator>
1895bool
1896vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
1897{
1898    const_pointer __p = __i->base() + __n;
1899    return this->__begin_ <= __p && __p < this->__end_;
1900}
1901
1902#endif  // _LIBCPP_DEBUG_LEVEL >= 2
1903
1904template <class _Tp, class _Allocator>
1905_LIBCPP_INLINE_VISIBILITY inline
1906void
1907vector<_Tp, _Allocator>::__invalidate_all_iterators()
1908{
1909#if _LIBCPP_DEBUG_LEVEL >= 2
1910    __get_db()->__invalidate_all(this);
1911#endif  // _LIBCPP_DEBUG_LEVEL >= 2
1912}
1913
1914// vector<bool>
1915
1916template <class _Allocator> class vector<bool, _Allocator>;
1917
1918template <class _Allocator> struct hash<vector<bool, _Allocator> >;
1919
1920template <class _Allocator>
1921struct __has_storage_type<vector<bool, _Allocator> >
1922{
1923    static const bool value = true;
1924};
1925
1926template <class _Allocator>
1927class _LIBCPP_VISIBLE vector<bool, _Allocator>
1928    : private __vector_base_common<true>
1929{
1930public:
1931    typedef vector                                   __self;
1932    typedef bool                                     value_type;
1933    typedef _Allocator                               allocator_type;
1934    typedef allocator_traits<allocator_type>         __alloc_traits;
1935    typedef typename __alloc_traits::size_type       size_type;
1936    typedef typename __alloc_traits::difference_type difference_type;
1937    typedef __bit_iterator<vector, false>            pointer;
1938    typedef __bit_iterator<vector, true>             const_pointer;
1939#ifdef _LIBCPP_DEBUG
1940    typedef __debug_iter<vector, pointer>            iterator;
1941    typedef __debug_iter<vector, const_pointer>      const_iterator;
1942
1943    friend class __debug_iter<vector, pointer>;
1944    friend class __debug_iter<vector, const_pointer>;
1945
1946    pair<iterator*, const_iterator*> __iterator_list_;
1947
1948    _LIBCPP_INLINE_VISIBILITY iterator*&       __get_iterator_list(iterator*)       {return __iterator_list_.first;}
1949    _LIBCPP_INLINE_VISIBILITY const_iterator*& __get_iterator_list(const_iterator*) {return __iterator_list_.second;}
1950#else  // _LIBCPP_DEBUG
1951    typedef pointer                                  iterator;
1952    typedef const_pointer                            const_iterator;
1953#endif  // _LIBCPP_DEBUG
1954    typedef _VSTD::reverse_iterator<iterator>         reverse_iterator;
1955    typedef _VSTD::reverse_iterator<const_iterator>   const_reverse_iterator;
1956
1957private:
1958    typedef size_type __storage_type;
1959    typedef typename __alloc_traits::template
1960#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1961                rebind_alloc<__storage_type>
1962#else
1963                rebind_alloc<__storage_type>::other
1964#endif
1965                                                     __storage_allocator;
1966    typedef allocator_traits<__storage_allocator>    __storage_traits;
1967    typedef typename __storage_traits::pointer       __storage_pointer;
1968    typedef typename __storage_traits::const_pointer __const_storage_pointer;
1969
1970    __storage_pointer                                      __begin_;
1971    size_type                                              __size_;
1972    __compressed_pair<size_type, __storage_allocator> __cap_alloc_;
1973public:
1974    typedef __bit_reference<vector>                  reference;
1975    typedef __bit_const_reference<vector>            const_reference;
1976private:
1977    _LIBCPP_INLINE_VISIBILITY
1978    size_type& __cap() _NOEXCEPT
1979        {return __cap_alloc_.first();}
1980    _LIBCPP_INLINE_VISIBILITY
1981    const size_type& __cap() const _NOEXCEPT
1982        {return __cap_alloc_.first();}
1983    _LIBCPP_INLINE_VISIBILITY
1984    __storage_allocator& __alloc() _NOEXCEPT
1985        {return __cap_alloc_.second();}
1986    _LIBCPP_INLINE_VISIBILITY
1987    const __storage_allocator& __alloc() const _NOEXCEPT
1988        {return __cap_alloc_.second();}
1989
1990    static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
1991
1992    _LIBCPP_INLINE_VISIBILITY
1993    static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
1994        {return __n * __bits_per_word;}
1995    _LIBCPP_INLINE_VISIBILITY
1996    static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
1997        {return (__n - 1) / __bits_per_word + 1;}
1998
1999public:
2000    _LIBCPP_INLINE_VISIBILITY
2001    vector()
2002        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
2003    _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a);
2004    ~vector();
2005    explicit vector(size_type __n);
2006    vector(size_type __n, const value_type& __v);
2007    vector(size_type __n, const value_type& __v, const allocator_type& __a);
2008    template <class _InputIterator>
2009        vector(_InputIterator __first, _InputIterator __last,
2010               typename enable_if<__is_input_iterator  <_InputIterator>::value &&
2011                                 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2012    template <class _InputIterator>
2013        vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2014               typename enable_if<__is_input_iterator  <_InputIterator>::value &&
2015                                 !__is_forward_iterator<_InputIterator>::value>::type* = 0);
2016    template <class _ForwardIterator>
2017        vector(_ForwardIterator __first, _ForwardIterator __last,
2018               typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2019    template <class _ForwardIterator>
2020        vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2021               typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
2022
2023    vector(const vector& __v);
2024    vector(const vector& __v, const allocator_type& __a);
2025    vector& operator=(const vector& __v);
2026#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2027    vector(initializer_list<value_type> __il);
2028    vector(initializer_list<value_type> __il, const allocator_type& __a);
2029#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2030
2031#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2032    _LIBCPP_INLINE_VISIBILITY
2033    vector(vector&& __v)
2034        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
2035    vector(vector&& __v, const allocator_type& __a);
2036    _LIBCPP_INLINE_VISIBILITY
2037    vector& operator=(vector&& __v)
2038        _NOEXCEPT_(
2039             __alloc_traits::propagate_on_container_move_assignment::value &&
2040             is_nothrow_move_assignable<allocator_type>::value);
2041#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2042#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2043    _LIBCPP_INLINE_VISIBILITY
2044    vector& operator=(initializer_list<value_type> __il)
2045        {assign(__il.begin(), __il.end()); return *this;}
2046#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2047
2048    template <class _InputIterator>
2049        typename enable_if
2050        <
2051            __is_input_iterator<_InputIterator>::value &&
2052           !__is_forward_iterator<_InputIterator>::value,
2053           void
2054        >::type
2055        assign(_InputIterator __first, _InputIterator __last);
2056    template <class _ForwardIterator>
2057        typename enable_if
2058        <
2059            __is_forward_iterator<_ForwardIterator>::value,
2060           void
2061        >::type
2062        assign(_ForwardIterator __first, _ForwardIterator __last);
2063
2064    void assign(size_type __n, const value_type& __x);
2065#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2066    _LIBCPP_INLINE_VISIBILITY
2067    void assign(initializer_list<value_type> __il)
2068        {assign(__il.begin(), __il.end());}
2069#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2070
2071    _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
2072        {return allocator_type(this->__alloc());}
2073
2074    size_type max_size() const _NOEXCEPT;
2075    _LIBCPP_INLINE_VISIBILITY
2076    size_type capacity() const _NOEXCEPT
2077        {return __internal_cap_to_external(__cap());}
2078    _LIBCPP_INLINE_VISIBILITY
2079    size_type size() const _NOEXCEPT
2080        {return __size_;}
2081    _LIBCPP_INLINE_VISIBILITY
2082    bool empty() const _NOEXCEPT
2083        {return __size_ == 0;}
2084    void reserve(size_type __n);
2085    void shrink_to_fit() _NOEXCEPT;
2086
2087    _LIBCPP_INLINE_VISIBILITY
2088    iterator begin() _NOEXCEPT
2089        {return __make_iter(0);}
2090    _LIBCPP_INLINE_VISIBILITY
2091    const_iterator begin() const _NOEXCEPT
2092        {return __make_iter(0);}
2093    _LIBCPP_INLINE_VISIBILITY
2094    iterator end() _NOEXCEPT
2095        {return __make_iter(__size_);}
2096    _LIBCPP_INLINE_VISIBILITY
2097    const_iterator end()   const _NOEXCEPT
2098        {return __make_iter(__size_);}
2099
2100    _LIBCPP_INLINE_VISIBILITY
2101    reverse_iterator rbegin() _NOEXCEPT
2102        {return       reverse_iterator(end());}
2103    _LIBCPP_INLINE_VISIBILITY
2104    const_reverse_iterator rbegin() const _NOEXCEPT
2105        {return const_reverse_iterator(end());}
2106    _LIBCPP_INLINE_VISIBILITY
2107    reverse_iterator rend() _NOEXCEPT
2108        {return       reverse_iterator(begin());}
2109    _LIBCPP_INLINE_VISIBILITY
2110    const_reverse_iterator rend()   const _NOEXCEPT
2111        {return const_reverse_iterator(begin());}
2112
2113    _LIBCPP_INLINE_VISIBILITY
2114    const_iterator         cbegin()  const _NOEXCEPT
2115        {return __make_iter(0);}
2116    _LIBCPP_INLINE_VISIBILITY
2117    const_iterator         cend()    const _NOEXCEPT
2118        {return __make_iter(__size_);}
2119    _LIBCPP_INLINE_VISIBILITY
2120    const_reverse_iterator crbegin() const _NOEXCEPT
2121        {return rbegin();}
2122    _LIBCPP_INLINE_VISIBILITY
2123    const_reverse_iterator crend()   const _NOEXCEPT
2124        {return rend();}
2125
2126    _LIBCPP_INLINE_VISIBILITY reference       operator[](size_type __n)       {return __make_ref(__n);}
2127    _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
2128    reference       at(size_type __n);
2129    const_reference at(size_type __n) const;
2130
2131    _LIBCPP_INLINE_VISIBILITY reference       front()       {return __make_ref(0);}
2132    _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
2133    _LIBCPP_INLINE_VISIBILITY reference       back()        {return __make_ref(__size_ - 1);}
2134    _LIBCPP_INLINE_VISIBILITY const_reference back()  const {return __make_ref(__size_ - 1);}
2135
2136    void push_back(const value_type& __x);
2137    _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
2138
2139    iterator insert(const_iterator __position, const value_type& __x);
2140    iterator insert(const_iterator __position, size_type __n, const value_type& __x);
2141    iterator insert(const_iterator __position, size_type __n, const_reference __x);
2142    template <class _InputIterator>
2143        typename enable_if
2144        <
2145             __is_input_iterator  <_InputIterator>::value &&
2146            !__is_forward_iterator<_InputIterator>::value,
2147            iterator
2148        >::type
2149        insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
2150    template <class _ForwardIterator>
2151        typename enable_if
2152        <
2153            __is_forward_iterator<_ForwardIterator>::value,
2154            iterator
2155        >::type
2156        insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
2157#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2158    _LIBCPP_INLINE_VISIBILITY
2159    iterator insert(const_iterator __position, initializer_list<value_type> __il)
2160        {return insert(__position, __il.begin(), __il.end());}
2161#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2162
2163    _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
2164    iterator erase(const_iterator __first, const_iterator __last);
2165
2166    _LIBCPP_INLINE_VISIBILITY
2167    void clear() _NOEXCEPT {__size_ = 0;}
2168
2169    void swap(vector&)
2170        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2171                   __is_nothrow_swappable<allocator_type>::value);
2172
2173    void resize(size_type __sz, value_type __x = false);
2174    void flip() _NOEXCEPT;
2175
2176    bool __invariants() const;
2177
2178private:
2179    _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
2180    void allocate(size_type __n);
2181    void deallocate() _NOEXCEPT;
2182    _LIBCPP_INLINE_VISIBILITY
2183    static size_type __align(size_type __new_size) _NOEXCEPT
2184        {return __new_size + (__bits_per_word-1) & ~(__bits_per_word-1);};
2185    _LIBCPP_INLINE_VISIBILITY  size_type __recommend(size_type __new_size) const;
2186    _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
2187    template <class _ForwardIterator>
2188        typename enable_if
2189        <
2190            __is_forward_iterator<_ForwardIterator>::value,
2191            void
2192        >::type
2193        __construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
2194    void __append(size_type __n, const_reference __x);
2195    _LIBCPP_INLINE_VISIBILITY
2196    reference __make_ref(size_type __pos) _NOEXCEPT
2197        {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2198    _LIBCPP_INLINE_VISIBILITY
2199    const_reference __make_ref(size_type __pos) const _NOEXCEPT
2200        {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
2201#ifdef _LIBCPP_DEBUG
2202    _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_type __pos)
2203        {return iterator(this, pointer(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word)));}
2204    _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_type __pos) const
2205        {return const_iterator(this, const_pointer(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word)));}
2206    _LIBCPP_INLINE_VISIBILITY iterator __const_iterator_cast(const_iterator __p)
2207        {return iterator(this, pointer(const_cast<__storage_pointer>(__p.base().__seg_), __p.base().__ctz_));}
2208#else  // _LIBCPP_DEBUG
2209    _LIBCPP_INLINE_VISIBILITY
2210    iterator __make_iter(size_type __pos) _NOEXCEPT
2211        {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2212    _LIBCPP_INLINE_VISIBILITY
2213    const_iterator __make_iter(size_type __pos) const _NOEXCEPT
2214        {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2215    _LIBCPP_INLINE_VISIBILITY
2216    iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
2217        {return iterator(const_cast<__storage_pointer>(__p.__seg_), __p.__ctz_);}
2218#endif  // _LIBCPP_DEBUG
2219
2220    _LIBCPP_INLINE_VISIBILITY
2221    void __copy_assign_alloc(const vector& __v)
2222        {__copy_assign_alloc(__v, integral_constant<bool,
2223                      __storage_traits::propagate_on_container_copy_assignment::value>());}
2224    _LIBCPP_INLINE_VISIBILITY
2225    void __copy_assign_alloc(const vector& __c, true_type)
2226        {
2227            if (__alloc() != __c.__alloc())
2228                deallocate();
2229            __alloc() = __c.__alloc();
2230        }
2231
2232    _LIBCPP_INLINE_VISIBILITY
2233    void __copy_assign_alloc(const vector& __c, false_type)
2234        {}
2235
2236    void __move_assign(vector& __c, false_type);
2237    void __move_assign(vector& __c, true_type)
2238        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
2239    _LIBCPP_INLINE_VISIBILITY
2240    void __move_assign_alloc(vector& __c)
2241        _NOEXCEPT_(
2242            !__storage_traits::propagate_on_container_move_assignment::value ||
2243            is_nothrow_move_assignable<allocator_type>::value)
2244        {__move_assign_alloc(__c, integral_constant<bool,
2245                      __storage_traits::propagate_on_container_move_assignment::value>());}
2246    _LIBCPP_INLINE_VISIBILITY
2247    void __move_assign_alloc(vector& __c, true_type)
2248        _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2249        {
2250            __alloc() = _VSTD::move(__c.__alloc());
2251        }
2252
2253    _LIBCPP_INLINE_VISIBILITY
2254    void __move_assign_alloc(vector& __c, false_type)
2255        _NOEXCEPT
2256        {}
2257
2258    _LIBCPP_INLINE_VISIBILITY
2259    static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y)
2260        _NOEXCEPT_(
2261            !__storage_traits::propagate_on_container_swap::value ||
2262            __is_nothrow_swappable<allocator_type>::value)
2263        {__swap_alloc(__x, __y, integral_constant<bool,
2264                      __storage_traits::propagate_on_container_swap::value>());}
2265
2266    _LIBCPP_INLINE_VISIBILITY
2267    static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, true_type)
2268        _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
2269        {
2270            using _VSTD::swap;
2271            swap(__x, __y);
2272        }
2273    _LIBCPP_INLINE_VISIBILITY
2274    static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, false_type)
2275        _NOEXCEPT
2276        {}
2277
2278    size_t __hash_code() const _NOEXCEPT;
2279
2280    friend class __bit_reference<vector>;
2281    friend class __bit_const_reference<vector>;
2282    friend class __bit_iterator<vector, false>;
2283    friend class __bit_iterator<vector, true>;
2284    friend class __bit_array<vector>;
2285    friend struct _LIBCPP_VISIBLE hash<vector>;
2286};
2287
2288template <class _Allocator>
2289#ifndef _LIBCPP_DEBUG
2290_LIBCPP_INLINE_VISIBILITY inline
2291#endif
2292void
2293vector<bool, _Allocator>::__invalidate_all_iterators()
2294{
2295#ifdef _LIBCPP_DEBUG
2296    iterator::__remove_all(this);
2297    const_iterator::__remove_all(this);
2298#endif  // _LIBCPP_DEBUG
2299}
2300
2301//  Allocate space for __n objects
2302//  throws length_error if __n > max_size()
2303//  throws (probably bad_alloc) if memory run out
2304//  Precondition:  __begin_ == __end_ == __cap() == 0
2305//  Precondition:  __n > 0
2306//  Postcondition:  capacity() == __n
2307//  Postcondition:  size() == 0
2308template <class _Allocator>
2309void
2310vector<bool, _Allocator>::allocate(size_type __n)
2311{
2312    if (__n > max_size())
2313        this->__throw_length_error();
2314    __n = __external_cap_to_internal(__n);
2315    this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
2316    this->__size_ = 0;
2317    this->__cap() = __n;
2318}
2319
2320template <class _Allocator>
2321void
2322vector<bool, _Allocator>::deallocate() _NOEXCEPT
2323{
2324    if (this->__begin_ != 0)
2325    {
2326        __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2327        __invalidate_all_iterators();
2328        this->__begin_ = 0;
2329        this->__size_ = this->__cap() = 0;
2330    }
2331}
2332
2333template <class _Allocator>
2334typename vector<bool, _Allocator>::size_type
2335vector<bool, _Allocator>::max_size() const _NOEXCEPT
2336{
2337    size_type __amax = __storage_traits::max_size(__alloc());
2338    size_type __nmax = numeric_limits<size_type>::max() / 2;  // end() >= begin(), always
2339    if (__nmax / __bits_per_word <= __amax)
2340        return __nmax;
2341    return __internal_cap_to_external(__amax);
2342}
2343
2344//  Precondition:  __new_size > capacity()
2345template <class _Allocator>
2346_LIBCPP_INLINE_VISIBILITY inline
2347typename vector<bool, _Allocator>::size_type
2348vector<bool, _Allocator>::__recommend(size_type __new_size) const
2349{
2350    const size_type __ms = max_size();
2351    if (__new_size > __ms)
2352        this->__throw_length_error();
2353    const size_type __cap = capacity();
2354    if (__cap >= __ms / 2)
2355        return __ms;
2356    return _VSTD::max(2*__cap, __align(__new_size));
2357}
2358
2359//  Default constructs __n objects starting at __end_
2360//  Precondition:  __n > 0
2361//  Precondition:  size() + __n <= capacity()
2362//  Postcondition:  size() == size() + __n
2363template <class _Allocator>
2364_LIBCPP_INLINE_VISIBILITY inline
2365void
2366vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
2367{
2368    size_type __old_size = this->__size_;
2369    this->__size_ += __n;
2370    _VSTD::fill_n(__make_iter(__old_size), __n, __x);
2371}
2372
2373template <class _Allocator>
2374template <class _ForwardIterator>
2375typename enable_if
2376<
2377    __is_forward_iterator<_ForwardIterator>::value,
2378    void
2379>::type
2380vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
2381{
2382    size_type __old_size = this->__size_;
2383    this->__size_ += _VSTD::distance(__first, __last);
2384    _VSTD::copy(__first, __last, __make_iter(__old_size));
2385}
2386
2387template <class _Allocator>
2388_LIBCPP_INLINE_VISIBILITY inline
2389vector<bool, _Allocator>::vector()
2390        _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
2391    : __begin_(0),
2392      __size_(0),
2393      __cap_alloc_(0)
2394{
2395}
2396
2397template <class _Allocator>
2398_LIBCPP_INLINE_VISIBILITY inline
2399vector<bool, _Allocator>::vector(const allocator_type& __a)
2400    : __begin_(0),
2401      __size_(0),
2402      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2403{
2404}
2405
2406template <class _Allocator>
2407vector<bool, _Allocator>::vector(size_type __n)
2408    : __begin_(0),
2409      __size_(0),
2410      __cap_alloc_(0)
2411{
2412    if (__n > 0)
2413    {
2414        allocate(__n);
2415        __construct_at_end(__n, false);
2416    }
2417}
2418
2419template <class _Allocator>
2420vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
2421    : __begin_(0),
2422      __size_(0),
2423      __cap_alloc_(0)
2424{
2425    if (__n > 0)
2426    {
2427        allocate(__n);
2428        __construct_at_end(__n, __x);
2429    }
2430}
2431
2432template <class _Allocator>
2433vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
2434    : __begin_(0),
2435      __size_(0),
2436      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2437{
2438    if (__n > 0)
2439    {
2440        allocate(__n);
2441        __construct_at_end(__n, __x);
2442    }
2443}
2444
2445template <class _Allocator>
2446template <class _InputIterator>
2447vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2448       typename enable_if<__is_input_iterator  <_InputIterator>::value &&
2449                         !__is_forward_iterator<_InputIterator>::value>::type*)
2450    : __begin_(0),
2451      __size_(0),
2452      __cap_alloc_(0)
2453{
2454#ifndef _LIBCPP_NO_EXCEPTIONS
2455    try
2456    {
2457#endif  // _LIBCPP_NO_EXCEPTIONS
2458        for (; __first != __last; ++__first)
2459            push_back(*__first);
2460#ifndef _LIBCPP_NO_EXCEPTIONS
2461    }
2462    catch (...)
2463    {
2464        if (__begin_ != 0)
2465            __storage_traits::deallocate(__alloc(), __begin_, __cap());
2466        __invalidate_all_iterators();
2467        throw;
2468    }
2469#endif  // _LIBCPP_NO_EXCEPTIONS
2470}
2471
2472template <class _Allocator>
2473template <class _InputIterator>
2474vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2475       typename enable_if<__is_input_iterator  <_InputIterator>::value &&
2476                         !__is_forward_iterator<_InputIterator>::value>::type*)
2477    : __begin_(0),
2478      __size_(0),
2479      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2480{
2481#ifndef _LIBCPP_NO_EXCEPTIONS
2482    try
2483    {
2484#endif  // _LIBCPP_NO_EXCEPTIONS
2485        for (; __first != __last; ++__first)
2486            push_back(*__first);
2487#ifndef _LIBCPP_NO_EXCEPTIONS
2488    }
2489    catch (...)
2490    {
2491        if (__begin_ != 0)
2492            __storage_traits::deallocate(__alloc(), __begin_, __cap());
2493        __invalidate_all_iterators();
2494        throw;
2495    }
2496#endif  // _LIBCPP_NO_EXCEPTIONS
2497}
2498
2499template <class _Allocator>
2500template <class _ForwardIterator>
2501vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2502                                typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2503    : __begin_(0),
2504      __size_(0),
2505      __cap_alloc_(0)
2506{
2507    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2508    if (__n > 0)
2509    {
2510        allocate(__n);
2511        __construct_at_end(__first, __last);
2512    }
2513}
2514
2515template <class _Allocator>
2516template <class _ForwardIterator>
2517vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2518                                typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2519    : __begin_(0),
2520      __size_(0),
2521      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2522{
2523    size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2524    if (__n > 0)
2525    {
2526        allocate(__n);
2527        __construct_at_end(__first, __last);
2528    }
2529}
2530
2531#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2532
2533template <class _Allocator>
2534vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
2535    : __begin_(0),
2536      __size_(0),
2537      __cap_alloc_(0)
2538{
2539    size_type __n = static_cast<size_type>(__il.size());
2540    if (__n > 0)
2541    {
2542        allocate(__n);
2543        __construct_at_end(__il.begin(), __il.end());
2544    }
2545}
2546
2547template <class _Allocator>
2548vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
2549    : __begin_(0),
2550      __size_(0),
2551      __cap_alloc_(0, static_cast<__storage_allocator>(__a))
2552{
2553    size_type __n = static_cast<size_type>(__il.size());
2554    if (__n > 0)
2555    {
2556        allocate(__n);
2557        __construct_at_end(__il.begin(), __il.end());
2558    }
2559}
2560
2561#endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2562
2563template <class _Allocator>
2564vector<bool, _Allocator>::~vector()
2565{
2566    if (__begin_ != 0)
2567        __storage_traits::deallocate(__alloc(), __begin_, __cap());
2568#ifdef _LIBCPP_DEBUG
2569    __invalidate_all_iterators();
2570#endif
2571}
2572
2573template <class _Allocator>
2574vector<bool, _Allocator>::vector(const vector& __v)
2575    : __begin_(0),
2576      __size_(0),
2577      __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
2578{
2579    if (__v.size() > 0)
2580    {
2581        allocate(__v.size());
2582        __construct_at_end(__v.begin(), __v.end());
2583    }
2584}
2585
2586template <class _Allocator>
2587vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
2588    : __begin_(0),
2589      __size_(0),
2590      __cap_alloc_(0, __a)
2591{
2592    if (__v.size() > 0)
2593    {
2594        allocate(__v.size());
2595        __construct_at_end(__v.begin(), __v.end());
2596    }
2597}
2598
2599template <class _Allocator>
2600vector<bool, _Allocator>&
2601vector<bool, _Allocator>::operator=(const vector& __v)
2602{
2603    if (this != &__v)
2604    {
2605        __copy_assign_alloc(__v);
2606        if (__v.__size_)
2607        {
2608            if (__v.__size_ > capacity())
2609            {
2610                deallocate();
2611                allocate(__v.__size_);
2612            }
2613            _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
2614        }
2615        __size_ = __v.__size_;
2616    }
2617    return *this;
2618}
2619
2620#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2621
2622template <class _Allocator>
2623_LIBCPP_INLINE_VISIBILITY inline
2624vector<bool, _Allocator>::vector(vector&& __v)
2625        _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
2626    : __begin_(__v.__begin_),
2627      __size_(__v.__size_),
2628      __cap_alloc_(__v.__cap_alloc_)
2629{
2630    __v.__begin_ = 0;
2631    __v.__size_ = 0;
2632    __v.__cap() = 0;
2633}
2634
2635template <class _Allocator>
2636vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
2637    : __begin_(0),
2638      __size_(0),
2639      __cap_alloc_(0, __a)
2640{
2641    if (__a == allocator_type(__v.__alloc()))
2642    {
2643        this->__begin_ = __v.__begin_;
2644        this->__size_ = __v.__size_;
2645        this->__cap() = __v.__cap();
2646        __v.__begin_ = nullptr;
2647        __v.__cap() = __v.__size_ = 0;
2648    }
2649    else if (__v.size() > 0)
2650    {
2651        allocate(__v.size());
2652        __construct_at_end(__v.begin(), __v.end());
2653    }
2654}
2655
2656template <class _Allocator>
2657_LIBCPP_INLINE_VISIBILITY inline
2658vector<bool, _Allocator>&
2659vector<bool, _Allocator>::operator=(vector&& __v)
2660        _NOEXCEPT_(
2661             __alloc_traits::propagate_on_container_move_assignment::value &&
2662             is_nothrow_move_assignable<allocator_type>::value)
2663{
2664    __move_assign(__v, integral_constant<bool,
2665          __storage_traits::propagate_on_container_move_assignment::value>());
2666}
2667
2668template <class _Allocator>
2669void
2670vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
2671{
2672    if (__alloc() != __c.__alloc())
2673        assign(__c.begin(), __c.end());
2674    else
2675        __move_assign(__c, true_type());
2676}
2677
2678template <class _Allocator>
2679void
2680vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
2681    _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2682{
2683    deallocate();
2684    this->__begin_ = __c.__begin_;
2685    this->__size_ = __c.__size_;
2686    this->__cap() = __c.__cap();
2687    __move_assign_alloc(__c);
2688    __c.__begin_ = nullptr;
2689    __c.__cap() = __c.__size_ = 0;
2690}
2691
2692#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2693
2694template <class _Allocator>
2695void
2696vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
2697{
2698    __size_ = 0;
2699    if (__n > 0)
2700    {
2701        size_type __c = capacity();
2702        if (__n <= __c)
2703            __size_ = __n;
2704        else
2705        {
2706            vector __v(__alloc());
2707            __v.reserve(__recommend(__n));
2708            __v.__size_ = __n;
2709            swap(__v);
2710        }
2711        _VSTD::fill_n(begin(), __n, __x);
2712    }
2713}
2714
2715template <class _Allocator>
2716template <class _InputIterator>
2717typename enable_if
2718<
2719    __is_input_iterator<_InputIterator>::value &&
2720   !__is_forward_iterator<_InputIterator>::value,
2721   void
2722>::type
2723vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2724{
2725    clear();
2726    for (; __first != __last; ++__first)
2727        push_back(*__first);
2728}
2729
2730template <class _Allocator>
2731template <class _ForwardIterator>
2732typename enable_if
2733<
2734    __is_forward_iterator<_ForwardIterator>::value,
2735   void
2736>::type
2737vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2738{
2739    clear();
2740    difference_type __n = _VSTD::distance(__first, __last);
2741    if (__n)
2742    {
2743        if (__n > capacity())
2744        {
2745            deallocate();
2746            allocate(__n);
2747        }
2748        __construct_at_end(__first, __last);
2749    }
2750}
2751
2752template <class _Allocator>
2753void
2754vector<bool, _Allocator>::reserve(size_type __n)
2755{
2756    if (__n > capacity())
2757    {
2758        vector __v(this->__alloc());
2759        __v.allocate(__n);
2760        __v.__construct_at_end(this->begin(), this->end());
2761        swap(__v);
2762        __invalidate_all_iterators();
2763    }
2764}
2765
2766template <class _Allocator>
2767void
2768vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
2769{
2770    if (__external_cap_to_internal(size()) > __cap())
2771    {
2772#ifndef _LIBCPP_NO_EXCEPTIONS
2773        try
2774        {
2775#endif  // _LIBCPP_NO_EXCEPTIONS
2776            vector(*this, allocator_type(__alloc())).swap(*this);
2777#ifndef _LIBCPP_NO_EXCEPTIONS
2778        }
2779        catch (...)
2780        {
2781        }
2782#endif  // _LIBCPP_NO_EXCEPTIONS
2783    }
2784}
2785
2786template <class _Allocator>
2787typename vector<bool, _Allocator>::reference
2788vector<bool, _Allocator>::at(size_type __n)
2789{
2790    if (__n >= size())
2791        this->__throw_out_of_range();
2792    return (*this)[__n];
2793}
2794
2795template <class _Allocator>
2796typename vector<bool, _Allocator>::const_reference
2797vector<bool, _Allocator>::at(size_type __n) const
2798{
2799    if (__n >= size())
2800        this->__throw_out_of_range();
2801    return (*this)[__n];
2802}
2803
2804template <class _Allocator>
2805void
2806vector<bool, _Allocator>::push_back(const value_type& __x)
2807{
2808    if (this->__size_ == this->capacity())
2809        reserve(__recommend(this->__size_ + 1));
2810    ++this->__size_;
2811    back() = __x;
2812}
2813
2814template <class _Allocator>
2815typename vector<bool, _Allocator>::iterator
2816vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
2817{
2818    iterator __r;
2819    if (size() < capacity())
2820    {
2821        const_iterator __old_end = end();
2822        ++__size_;
2823        _VSTD::copy_backward(__position, __old_end, end());
2824        __r = __const_iterator_cast(__position);
2825    }
2826    else
2827    {
2828        vector __v(__alloc());
2829        __v.reserve(__recommend(__size_ + 1));
2830        __v.__size_ = __size_ + 1;
2831        __r = _VSTD::copy(cbegin(), __position, __v.begin());
2832        _VSTD::copy_backward(__position, cend(), __v.end());
2833        swap(__v);
2834    }
2835    *__r = __x;
2836    return __r;
2837}
2838
2839template <class _Allocator>
2840typename vector<bool, _Allocator>::iterator
2841vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
2842{
2843    iterator __r;
2844    size_type __c = capacity();
2845    if (__n <= __c && size() <= __c - __n)
2846    {
2847        const_iterator __old_end = end();
2848        __size_ += __n;
2849        _VSTD::copy_backward(__position, __old_end, end());
2850        __r = __const_iterator_cast(__position);
2851    }
2852    else
2853    {
2854        vector __v(__alloc());
2855        __v.reserve(__recommend(__size_ + __n));
2856        __v.__size_ = __size_ + __n;
2857        __r = _VSTD::copy(cbegin(), __position, __v.begin());
2858        _VSTD::copy_backward(__position, cend(), __v.end());
2859        swap(__v);
2860    }
2861    _VSTD::fill_n(__r, __n, __x);
2862    return __r;
2863}
2864
2865template <class _Allocator>
2866template <class _InputIterator>
2867typename enable_if
2868<
2869     __is_input_iterator  <_InputIterator>::value &&
2870    !__is_forward_iterator<_InputIterator>::value,
2871    typename vector<bool, _Allocator>::iterator
2872>::type
2873vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
2874{
2875    difference_type __off = __position - begin();
2876    iterator __p = __const_iterator_cast(__position);
2877    iterator __old_end = end();
2878    for (; size() != capacity() && __first != __last; ++__first)
2879    {
2880        ++this->__size_;
2881        back() = *__first;
2882    }
2883    vector __v(__alloc());
2884    if (__first != __last)
2885    {
2886#ifndef _LIBCPP_NO_EXCEPTIONS
2887        try
2888        {
2889#endif  // _LIBCPP_NO_EXCEPTIONS
2890            __v.assign(__first, __last);
2891            difference_type __old_size = static_cast<difference_type>(__old_end - begin());
2892            difference_type __old_p = __p - begin();
2893            reserve(__recommend(size() + __v.size()));
2894            __p = begin() + __old_p;
2895            __old_end = begin() + __old_size;
2896#ifndef _LIBCPP_NO_EXCEPTIONS
2897        }
2898        catch (...)
2899        {
2900            erase(__old_end, end());
2901            throw;
2902        }
2903#endif  // _LIBCPP_NO_EXCEPTIONS
2904    }
2905    __p = _VSTD::rotate(__p, __old_end, end());
2906    insert(__p, __v.begin(), __v.end());
2907    return begin() + __off;
2908}
2909
2910template <class _Allocator>
2911template <class _ForwardIterator>
2912typename enable_if
2913<
2914    __is_forward_iterator<_ForwardIterator>::value,
2915    typename vector<bool, _Allocator>::iterator
2916>::type
2917vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
2918{
2919    difference_type __n = _VSTD::distance(__first, __last);
2920    iterator __r;
2921    size_type __c = capacity();
2922    if (__n <= __c && size() <= __c - __n)
2923    {
2924        const_iterator __old_end = end();
2925        __size_ += __n;
2926        _VSTD::copy_backward(__position, __old_end, end());
2927        __r = __const_iterator_cast(__position);
2928    }
2929    else
2930    {
2931        vector __v(__alloc());
2932        __v.reserve(__recommend(__size_ + __n));
2933        __v.__size_ = __size_ + __n;
2934        __r = _VSTD::copy(cbegin(), __position, __v.begin());
2935        _VSTD::copy_backward(__position, cend(), __v.end());
2936        swap(__v);
2937    }
2938    _VSTD::copy(__first, __last, __r);
2939    return __r;
2940}
2941
2942template <class _Allocator>
2943_LIBCPP_INLINE_VISIBILITY inline
2944typename vector<bool, _Allocator>::iterator
2945vector<bool, _Allocator>::erase(const_iterator __position)
2946{
2947    iterator __r = __const_iterator_cast(__position);
2948    _VSTD::copy(__position + 1, this->cend(), __r);
2949    --__size_;
2950    return __r;
2951}
2952
2953template <class _Allocator>
2954typename vector<bool, _Allocator>::iterator
2955vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
2956{
2957    iterator __r = __const_iterator_cast(__first);
2958    difference_type __d = __last - __first;
2959    _VSTD::copy(__last, this->cend(), __r);
2960    __size_ -= __d;
2961    return __r;
2962}
2963
2964template <class _Allocator>
2965void
2966vector<bool, _Allocator>::swap(vector& __x)
2967        _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
2968                   __is_nothrow_swappable<allocator_type>::value)
2969{
2970    _VSTD::swap(this->__begin_, __x.__begin_);
2971    _VSTD::swap(this->__size_, __x.__size_);
2972    _VSTD::swap(this->__cap(), __x.__cap());
2973    __swap_alloc(this->__alloc(), __x.__alloc());
2974#ifdef _LIBCPP_DEBUG
2975    iterator::swap(this, &__x);
2976    const_iterator::swap(this, &__x);
2977#endif  // _LIBCPP_DEBUG
2978}
2979
2980template <class _Allocator>
2981void
2982vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
2983{
2984    size_type __cs = size();
2985    if (__cs < __sz)
2986    {
2987        iterator __r;
2988        size_type __c = capacity();
2989        size_type __n = __sz - __cs;
2990        if (__n <= __c && __cs <= __c - __n)
2991        {
2992            __r = end();
2993            __size_ += __n;
2994        }
2995        else
2996        {
2997            vector __v(__alloc());
2998            __v.reserve(__recommend(__size_ + __n));
2999            __v.__size_ = __size_ + __n;
3000            __r = _VSTD::copy(cbegin(), cend(), __v.begin());
3001            swap(__v);
3002        }
3003        _VSTD::fill_n(__r, __n, __x);
3004    }
3005    else
3006        __size_ = __sz;
3007}
3008
3009template <class _Allocator>
3010void
3011vector<bool, _Allocator>::flip() _NOEXCEPT
3012{
3013    // do middle whole words
3014    size_type __n = __size_;
3015    __storage_pointer __p = __begin_;
3016    for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3017        *__p = ~*__p;
3018    // do last partial word
3019    if (__n > 0)
3020    {
3021        __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3022        __storage_type __b = *__p & __m;
3023        *__p &= ~__m;
3024        *__p |= ~__b & __m;
3025    }
3026}
3027
3028template <class _Allocator>
3029bool
3030vector<bool, _Allocator>::__invariants() const
3031{
3032    if (this->__begin_ == 0)
3033    {
3034        if (this->__size_ != 0 || this->__cap() != 0)
3035            return false;
3036    }
3037    else
3038    {
3039        if (this->__cap() == 0)
3040            return false;
3041        if (this->__size_ > this->capacity())
3042            return false;
3043    }
3044    return true;
3045}
3046
3047template <class _Allocator>
3048size_t
3049vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
3050{
3051    size_t __h = 0;
3052    // do middle whole words
3053    size_type __n = __size_;
3054    __storage_pointer __p = __begin_;
3055    for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
3056        __h ^= *__p;
3057    // do last partial word
3058    if (__n > 0)
3059    {
3060        const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
3061        __h ^= *__p & __m;
3062    }
3063    return __h;
3064}
3065
3066template <class _Allocator>
3067struct _LIBCPP_VISIBLE hash<vector<bool, _Allocator> >
3068    : public unary_function<vector<bool, _Allocator>, size_t>
3069{
3070    _LIBCPP_INLINE_VISIBILITY
3071    size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
3072        {return __vec.__hash_code();}
3073};
3074
3075template <class _Tp, class _Allocator>
3076_LIBCPP_INLINE_VISIBILITY inline
3077bool
3078operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3079{
3080    const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
3081    return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
3082}
3083
3084template <class _Tp, class _Allocator>
3085_LIBCPP_INLINE_VISIBILITY inline
3086bool
3087operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3088{
3089    return !(__x == __y);
3090}
3091
3092template <class _Tp, class _Allocator>
3093_LIBCPP_INLINE_VISIBILITY inline
3094bool
3095operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3096{
3097    return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
3098}
3099
3100template <class _Tp, class _Allocator>
3101_LIBCPP_INLINE_VISIBILITY inline
3102bool
3103operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3104{
3105    return __y < __x;
3106}
3107
3108template <class _Tp, class _Allocator>
3109_LIBCPP_INLINE_VISIBILITY inline
3110bool
3111operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3112{
3113    return !(__x < __y);
3114}
3115
3116template <class _Tp, class _Allocator>
3117_LIBCPP_INLINE_VISIBILITY inline
3118bool
3119operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
3120{
3121    return !(__y < __x);
3122}
3123
3124template <class _Tp, class _Allocator>
3125_LIBCPP_INLINE_VISIBILITY inline
3126void
3127swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
3128    _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
3129{
3130    __x.swap(__y);
3131}
3132
3133_LIBCPP_END_NAMESPACE_STD
3134
3135#endif  // _LIBCPP_VECTOR
3136