Advertisement
Guest User

Untitled

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