Advertisement
Guest User

WindowsUtils.h

a guest
Jan 12th, 2013
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 54.77 KB | None | 0 0
  1. // list standard header
  2. #pragma once
  3. #ifndef _LIST_
  4. #define _LIST_
  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. _STD_BEGIN
  16.         // TEMPLATE CLASS _List_unchecked_const_iterator
  17. template<class _Mylist,
  18.     class _Base = _Iterator_base0>
  19.     class _List_unchecked_const_iterator
  20.         : public _Iterator012<bidirectional_iterator_tag,
  21.             typename _Mylist::value_type,
  22.             typename _Mylist::difference_type,
  23.             typename _Mylist::const_pointer,
  24.             typename _Mylist::const_reference,
  25.             _Base>
  26.     {   // unchecked iterator for nonmutable list
  27. public:
  28.     typedef _List_unchecked_const_iterator<_Mylist, _Base> _Myiter;
  29.     typedef bidirectional_iterator_tag iterator_category;
  30.  
  31.     typedef typename _Mylist::_Nodeptr _Nodeptr;
  32.     typedef typename _Mylist::value_type value_type;
  33.     typedef typename _Mylist::difference_type difference_type;
  34.     typedef typename _Mylist::const_pointer pointer;
  35.     typedef typename _Mylist::const_reference reference;
  36.  
  37.     _List_unchecked_const_iterator()
  38.         : _Ptr(0)
  39.         {   // construct with null node pointer
  40.         }
  41.  
  42.     _List_unchecked_const_iterator(_Nodeptr _Pnode, const _Mylist *_Plist)
  43.         : _Ptr(_Pnode)
  44.         {   // construct with node pointer _Pnode
  45.         this->_Adopt(_Plist);
  46.         }
  47.  
  48.     reference operator*() const
  49.         {   // return designated value
  50.         return (_Mylist::_Myval(_Ptr));
  51.         }
  52.  
  53.     pointer operator->() const
  54.         {   // return pointer to class object
  55.         return (_STD pointer_traits<pointer>::pointer_to(**this));
  56.         }
  57.  
  58.     _Myiter& operator++()
  59.         {   // preincrement
  60.         _Ptr = _Mylist::_Nextnode(_Ptr);
  61.         return (*this);
  62.         }
  63.  
  64.     _Myiter operator++(int)
  65.         {   // postincrement
  66.         _Myiter _Tmp = *this;
  67.         ++*this;
  68.         return (_Tmp);
  69.         }
  70.  
  71.     _Myiter& operator--()
  72.         {   // predecrement
  73.         _Ptr = _Mylist::_Prevnode(_Ptr);
  74.         return (*this);
  75.         }
  76.  
  77.     _Myiter operator--(int)
  78.         {   // postdecrement
  79.         _Myiter _Tmp = *this;
  80.         --*this;
  81.         return (_Tmp);
  82.         }
  83.  
  84.     bool operator==(const _Myiter& _Right) const
  85.         {   // test for iterator equality
  86.         return (_Ptr == _Right._Ptr);
  87.         }
  88.  
  89.     bool operator!=(const _Myiter& _Right) const
  90.         {   // test for iterator inequality
  91.         return (!(*this == _Right));
  92.         }
  93.  
  94.     _Nodeptr _Mynode() const
  95.         {   // return node pointer
  96.         return (_Ptr);
  97.         }
  98.  
  99.     _Nodeptr _Ptr;  // pointer to node
  100.     };
  101.  
  102.     // TEMPLATE CLASS _List_unchecked_iterator
  103. template<class _Mylist>
  104.     class _List_unchecked_iterator
  105.         : public _List_unchecked_const_iterator<_Mylist>
  106.     {   // unchecked iterator for mutable list
  107. public:
  108.     typedef _List_unchecked_iterator<_Mylist> _Myiter;
  109.     typedef _List_unchecked_const_iterator<_Mylist> _Mybase;
  110.     typedef bidirectional_iterator_tag iterator_category;
  111.  
  112.     typedef typename _Mylist::_Nodeptr _Nodeptr;
  113.     typedef typename _Mylist::value_type value_type;
  114.     typedef typename _Mylist::difference_type difference_type;
  115.     typedef typename _Mylist::pointer pointer;
  116.     typedef typename _Mylist::reference reference;
  117.  
  118.     _List_unchecked_iterator()
  119.         {   // construct with null node
  120.         }
  121.  
  122.     _List_unchecked_iterator(_Nodeptr _Pnode, const _Mylist *_Plist)
  123.         : _Mybase(_Pnode, _Plist)
  124.         {   // construct with node pointer _Pnode
  125.         }
  126.  
  127.     reference operator*() const
  128.         {   // return designated value
  129.         return ((reference)**(_Mybase *)this);
  130.         }
  131.  
  132.     pointer operator->() const
  133.         {   // return pointer to class object
  134.         return (_STD pointer_traits<pointer>::pointer_to(**this));
  135.         }
  136.  
  137.     _Myiter& operator++()
  138.         {   // preincrement
  139.         ++(*(_Mybase *)this);
  140.         return (*this);
  141.         }
  142.  
  143.     _Myiter operator++(int)
  144.         {   // postincrement
  145.         _Myiter _Tmp = *this;
  146.         ++*this;
  147.         return (_Tmp);
  148.         }
  149.  
  150.     _Myiter& operator--()
  151.         {   // predecrement
  152.         --(*(_Mybase *)this);
  153.         return (*this);
  154.         }
  155.  
  156.     _Myiter operator--(int)
  157.         {   // postdecrement
  158.         _Myiter _Tmp = *this;
  159.         --*this;
  160.         return (_Tmp);
  161.         }
  162.     };
  163.  
  164.     // TEMPLATE CLASS _List_const_iterator
  165. template<class _Mylist>
  166.     class _List_const_iterator
  167.         : public _List_unchecked_const_iterator<_Mylist, _Iterator_base>
  168.     {   // iterator for nonmutable list
  169. public:
  170.     typedef _List_const_iterator<_Mylist> _Myiter;
  171.     typedef _List_unchecked_const_iterator<_Mylist, _Iterator_base> _Mybase;
  172.     typedef bidirectional_iterator_tag iterator_category;
  173.  
  174.     typedef typename _Mylist::_Nodeptr _Nodeptr;
  175.     typedef typename _Mylist::value_type value_type;
  176.     typedef typename _Mylist::difference_type difference_type;
  177.     typedef typename _Mylist::const_pointer pointer;
  178.     typedef typename _Mylist::const_reference reference;
  179.  
  180.     _List_const_iterator()
  181.         : _Mybase()
  182.         {   // construct with null node pointer
  183.         }
  184.  
  185.     _List_const_iterator(_Nodeptr _Pnode, const _Mylist *_Plist)
  186.         : _Mybase(_Pnode, _Plist)
  187.         {   // construct with node pointer _Pnode
  188.         }
  189.  
  190.     typedef _List_unchecked_const_iterator<_Mylist> _Unchecked_type;
  191.  
  192.     _Myiter& _Rechecked(_Unchecked_type _Right)
  193.         {   // reset from unchecked iterator
  194.         this->_Ptr = _Right._Ptr;
  195.         return (*this);
  196.         }
  197.  
  198.     _Unchecked_type _Unchecked() const
  199.         {   // make an unchecked iterator
  200.         return (_Unchecked_type(this->_Ptr, (_Mylist *)this->_Getcont()));
  201.         }
  202.  
  203.     reference operator*() const
  204.         {   // return designated value
  205.  #if _ITERATOR_DEBUG_LEVEL == 2
  206.         if (this->_Getcont() == 0
  207.             || this->_Ptr == 0
  208.             || this->_Ptr == ((_Mylist *)this->_Getcont())->_Myhead)
  209.             {   // report error
  210.             _DEBUG_ERROR("list iterator not dereferencable");
  211.             _SCL_SECURE_OUT_OF_RANGE;
  212.             }
  213.  
  214.  #elif _ITERATOR_DEBUG_LEVEL == 1
  215.         _SCL_SECURE_VALIDATE(this->_Getcont() != 0 && this->_Ptr != 0);
  216.         _SCL_SECURE_VALIDATE_RANGE(this->_Ptr !=
  217.             ((_Mylist *)this->_Getcont())->_Myhead);
  218.  #endif /* _ITERATOR_DEBUG_LEVEL */
  219.  
  220.         return (_Mylist::_Myval(this->_Ptr));
  221.         }
  222.  
  223.     _Myiter& operator++()
  224.         {   // preincrement
  225.  #if _ITERATOR_DEBUG_LEVEL == 2
  226.         if (this->_Getcont() == 0
  227.             || this->_Ptr == 0
  228.             || this->_Ptr == ((_Mylist *)this->_Getcont())->_Myhead)
  229.             {   // report error
  230.             _DEBUG_ERROR("list iterator not incrementable");
  231.             _SCL_SECURE_OUT_OF_RANGE;
  232.             }
  233.  
  234.  #elif _ITERATOR_DEBUG_LEVEL == 1
  235.         _SCL_SECURE_VALIDATE(this->_Getcont() != 0 && this->_Ptr != 0);
  236.         _SCL_SECURE_VALIDATE_RANGE(this->_Ptr !=
  237.             ((_Mylist *)this->_Getcont())->_Myhead);
  238.  #endif /* _ITERATOR_DEBUG_LEVEL */
  239.  
  240.         this->_Ptr = _Mylist::_Nextnode(this->_Ptr);
  241.         return (*this);
  242.         }
  243.  
  244.     _Myiter operator++(int)
  245.         {   // postincrement
  246.         _Myiter _Tmp = *this;
  247.         ++*this;
  248.         return (_Tmp);
  249.         }
  250.  
  251.     _Myiter& operator--()
  252.         {   // predecrement
  253.  #if _ITERATOR_DEBUG_LEVEL == 2
  254.         if (this->_Getcont() == 0
  255.             || this->_Ptr == 0
  256.             || (this->_Ptr = _Mylist::_Prevnode(this->_Ptr))
  257.                 == ((_Mylist *)this->_Getcont())->_Myhead)
  258.             {   // report error
  259.             _DEBUG_ERROR("list iterator not decrementable");
  260.             _SCL_SECURE_OUT_OF_RANGE;
  261.             }
  262.  
  263.  #elif _ITERATOR_DEBUG_LEVEL == 1
  264.         _SCL_SECURE_VALIDATE(this->_Getcont() != 0 && this->_Ptr != 0);
  265.         this->_Ptr = _Mylist::_Prevnode(this->_Ptr);
  266.         _SCL_SECURE_VALIDATE_RANGE(this->_Ptr !=
  267.             ((_Mylist *)this->_Getcont())->_Myhead);
  268.  
  269.  #else /* _ITERATOR_DEBUG_LEVEL */
  270.         this->_Ptr = _Mylist::_Prevnode(this->_Ptr);
  271.  #endif /* _ITERATOR_DEBUG_LEVEL */
  272.  
  273.         return (*this);
  274.         }
  275.  
  276.     _Myiter operator--(int)
  277.         {   // postdecrement
  278.         _Myiter _Tmp = *this;
  279.         --*this;
  280.         return (_Tmp);
  281.         }
  282.  
  283.     bool operator==(const _Myiter& _Right) const
  284.         {   // test for iterator equality
  285.  #if _ITERATOR_DEBUG_LEVEL == 2
  286.         if (this->_Getcont() == 0
  287.             || this->_Getcont() != _Right._Getcont())
  288.             {   // report error
  289.             _DEBUG_ERROR("list iterators incompatible");
  290.             _SCL_SECURE_INVALID_ARGUMENT;
  291.             }
  292.  
  293.  #elif _ITERATOR_DEBUG_LEVEL == 1
  294.         _SCL_SECURE_VALIDATE(this->_Getcont() != 0
  295.             && this->_Getcont() == _Right._Getcont());
  296.  #endif /* _ITERATOR_DEBUG_LEVEL */
  297.  
  298.         return (this->_Ptr == _Right._Ptr);
  299.         }
  300.  
  301.     bool operator!=(const _Myiter& _Right) const
  302.         {   // test for iterator inequality
  303.         return (!(*this == _Right));
  304.         }
  305.     };
  306.  
  307. template<class _Mylist> inline
  308.     typename _List_const_iterator<_Mylist>::_Unchecked_type
  309.         _Unchecked(_List_const_iterator<_Mylist> _Iter)
  310.     {   // convert to unchecked
  311.     return (_Iter._Unchecked());
  312.     }
  313.  
  314. template<class _Mylist> inline
  315.     _List_const_iterator<_Mylist>&
  316.         _Rechecked(_List_const_iterator<_Mylist>& _Iter,
  317.             typename _List_const_iterator<_Mylist>
  318.                 ::_Unchecked_type _Right)
  319.     {   // convert to checked
  320.     return (_Iter._Rechecked(_Right));
  321.     }
  322.  
  323.     // TEMPLATE CLASS _List_iterator
  324. template<class _Mylist>
  325.     class _List_iterator
  326.         : public _List_const_iterator<_Mylist>
  327.     {   // iterator for mutable list
  328. public:
  329.     typedef _List_iterator<_Mylist> _Myiter;
  330.     typedef _List_const_iterator<_Mylist> _Mybase;
  331.     typedef bidirectional_iterator_tag iterator_category;
  332.  
  333.     typedef typename _Mylist::_Nodeptr _Nodeptr;
  334.     typedef typename _Mylist::value_type value_type;
  335.     typedef typename _Mylist::difference_type difference_type;
  336.     typedef typename _Mylist::pointer pointer;
  337.     typedef typename _Mylist::reference reference;
  338.  
  339.     _List_iterator()
  340.         {   // construct with null node
  341.         }
  342.  
  343.     _List_iterator(_Nodeptr _Pnode, const _Mylist *_Plist)
  344.         : _Mybase(_Pnode, _Plist)
  345.         {   // construct with node pointer _Pnode
  346.         }
  347.  
  348.     typedef _List_unchecked_iterator<_Mylist> _Unchecked_type;
  349.  
  350.     _Myiter& _Rechecked(_Unchecked_type _Right)
  351.         {   // reset from unchecked iterator
  352.         this->_Ptr = _Right._Ptr;
  353.         return (*this);
  354.         }
  355.  
  356.     _Unchecked_type _Unchecked() const
  357.         {   // make an unchecked iterator
  358.         return (_Unchecked_type(this->_Ptr, (_Mylist *)this->_Getcont()));
  359.         }
  360.  
  361.     reference operator*() const
  362.         {   // return designated value
  363.         return ((reference)**(_Mybase *)this);
  364.         }
  365.  
  366.     pointer operator->() const
  367.         {   // return pointer to class object
  368.         return (_STD pointer_traits<pointer>::pointer_to(**this));
  369.         }
  370.  
  371.     _Myiter& operator++()
  372.         {   // preincrement
  373.         ++(*(_Mybase *)this);
  374.         return (*this);
  375.         }
  376.  
  377.     _Myiter operator++(int)
  378.         {   // postincrement
  379.         _Myiter _Tmp = *this;
  380.         ++*this;
  381.         return (_Tmp);
  382.         }
  383.  
  384.     _Myiter& operator--()
  385.         {   // predecrement
  386.         --(*(_Mybase *)this);
  387.         return (*this);
  388.         }
  389.  
  390.     _Myiter operator--(int)
  391.         {   // postdecrement
  392.         _Myiter _Tmp = *this;
  393.         --*this;
  394.         return (_Tmp);
  395.         }
  396.     };
  397.  
  398. template<class _Mylist> inline
  399.     typename _List_iterator<_Mylist>::_Unchecked_type
  400.         _Unchecked(_List_iterator<_Mylist> _Iter)
  401.     {   // convert to unchecked
  402.     return (_Iter._Unchecked());
  403.     }
  404.  
  405. template<class _Mylist> inline
  406.     _List_iterator<_Mylist>&
  407.         _Rechecked(_List_iterator<_Mylist>& _Iter,
  408.             typename _List_iterator<_Mylist>
  409.                 ::_Unchecked_type _Right)
  410.     {   // convert to checked
  411.     return (_Iter._Rechecked(_Right));
  412.     }
  413.  
  414.         // list TYPE WRAPPERS
  415. template<class _Value_type,
  416.     class _Size_type,
  417.     class _Difference_type,
  418.     class _Pointer,
  419.     class _Const_pointer,
  420.     class _Reference,
  421.     class _Const_reference,
  422.     class _Nodeptr_type>
  423.     struct _List_iter_types
  424.     {   // wraps types needed by iterators
  425.     typedef _Value_type value_type;
  426.     typedef _Size_type size_type;
  427.     typedef _Difference_type difference_type;
  428.     typedef _Pointer pointer;
  429.     typedef _Const_pointer const_pointer;
  430.     typedef _Reference reference;
  431.     typedef _Const_reference const_reference;
  432.     typedef _Nodeptr_type _Nodeptr;
  433.     };
  434.  
  435. template<class _Value_type,
  436.     class _Voidptr>
  437.     struct _List_node
  438.         {   // list node
  439.         _Voidptr _Next; // successor node, or first element if head
  440.         _Voidptr _Prev; // predecessor node, or last element if head
  441.         _Value_type _Myval; // the stored value, unused if head
  442.  
  443.     private:
  444.         _List_node& operator=(const _List_node&);
  445.         };
  446.  
  447. template<class _Value_type>
  448.     struct _List_node<_Value_type, void *>
  449.         {   // list node
  450.         typedef _List_node<_Value_type, void *> *_Nodeptr;
  451.         _Nodeptr _Next; // successor node, or first element if head
  452.         _Nodeptr _Prev; // predecessor node, or last element if head
  453.         _Value_type _Myval; // the stored value, unused if head
  454.  
  455.     private:
  456.         _List_node& operator=(const _List_node&);
  457.         };
  458.  
  459. template<class _Ty>
  460.     struct _List_simple_types
  461.         : public _Simple_types<_Ty>
  462.     {   // wraps types needed by iterators
  463.     typedef _List_node<_Ty, void *> _Node;
  464.     typedef _Node *_Nodeptr;
  465.     };
  466.  
  467. template<class _Ty,
  468.     class _Alloc0>
  469.     struct _List_base_types
  470.     {   // types needed for a container base
  471.     typedef _Alloc0 _Alloc;
  472.     typedef _List_base_types<_Ty, _Alloc> _Myt;
  473.  
  474.  #if _HAS_CPP0X
  475.     typedef _Wrap_alloc<_Alloc> _Alty0;
  476.     typedef typename _Alty0::template rebind<_Ty>::other _Alty;
  477.  
  478.  #else /* _HAS_CPP0X */
  479.     typedef typename _Alloc::template rebind<_Ty>::other _Alty;
  480.  #endif /* _HAS_CPP0X */
  481.  
  482.     typedef typename _Get_voidptr<_Alty, typename _Alty::pointer>::type
  483.         _Voidptr;
  484.     typedef _List_node<typename _Alty::value_type,
  485.         _Voidptr> _Node;
  486.  
  487.     typedef typename _Alty::template rebind<_Node>::other _Alnod_type;
  488.     typedef typename _Alnod_type::pointer _Nodeptr;
  489.     typedef _Nodeptr& _Nodepref;
  490.  
  491.     typedef typename _If<_Is_simple_alloc<_Alty>::value,
  492.         _List_simple_types<typename _Alty::value_type>,
  493.         _List_iter_types<typename _Alty::value_type,
  494.             typename _Alty::size_type,
  495.             typename _Alty::difference_type,
  496.             typename _Alty::pointer,
  497.             typename _Alty::const_pointer,
  498.             typename _Alty::reference,
  499.             typename _Alty::const_reference,
  500.             _Nodeptr> >::type
  501.         _Val_types;
  502.     };
  503.  
  504.         // TEMPLATE CLASS _List_val
  505. template<class _Val_types>
  506.     class _List_val
  507.         : public _Container_base
  508.     {   // base class for list to hold data
  509. public:
  510.     typedef _List_val<_Val_types> _Myt;
  511.  
  512.     typedef typename _Val_types::_Nodeptr _Nodeptr;
  513.     typedef _Nodeptr& _Nodepref;
  514.  
  515.     typedef typename _Val_types::value_type value_type;
  516.     typedef typename _Val_types::size_type size_type;
  517.     typedef typename _Val_types::difference_type difference_type;
  518.     typedef typename _Val_types::pointer pointer;
  519.     typedef typename _Val_types::const_pointer const_pointer;
  520.     typedef typename _Val_types::reference reference;
  521.     typedef typename _Val_types::const_reference const_reference;
  522.  
  523.     typedef _List_const_iterator<_Myt> const_iterator;
  524.     typedef _List_iterator<_Myt> iterator;
  525.  
  526.     typedef _List_unchecked_const_iterator<_Myt> _Unchecked_const_iterator;
  527.     typedef _List_unchecked_iterator<_Myt> _Unchecked_iterator;
  528.  
  529.     _List_val()
  530.         {   // initialize data
  531.         this->_Myhead = 0;
  532.         this->_Mysize = 0;
  533.         }
  534.  
  535.     static _Nodepref _Nextnode(_Nodeptr _Pnode)
  536.         {   // return reference to successor pointer in node
  537.         return ((_Nodepref)_Pnode->_Next);
  538.         }
  539.  
  540.     static _Nodepref _Prevnode(_Nodeptr _Pnode)
  541.         {   // return reference to predecessor pointer in node
  542.         return ((_Nodepref)_Pnode->_Prev);
  543.         }
  544.  
  545.     static reference _Myval(_Nodeptr _Pnode)
  546.         {   // return reference to value in node
  547.         return ((reference)_Pnode->_Myval);
  548.         }
  549.  
  550.     _Nodeptr _Myhead;   // pointer to head node
  551.     size_type _Mysize;  // number of elements
  552.     };
  553.  
  554.         // TEMPLATE CLASS _List_alloc
  555. template<bool _Al_has_storage,
  556.     class _Alloc_types>
  557.     class _List_alloc
  558.         : public _List_val<typename _Alloc_types::_Val_types>
  559.     {   // base class for list to hold allocator with storage
  560. public:
  561.     typedef _List_alloc<_Al_has_storage, _Alloc_types> _Myt;
  562.     typedef _List_val<typename _Alloc_types::_Val_types> _Mybase;
  563.     typedef typename _Alloc_types::_Alloc _Alloc;
  564.     typedef typename _Alloc_types::_Alnod_type _Alty;
  565.     typedef typename _Alloc_types::_Node _Node;
  566.     typedef typename _Alloc_types::_Nodeptr _Nodeptr;
  567.  
  568.  #if _ITERATOR_DEBUG_LEVEL == 0
  569.     _List_alloc(const _Alloc& _Al = _Alloc())
  570.         : _Alnod(_Al)
  571.         {   // construct head node, allocator from _Al
  572.         this->_Myhead = _Buyheadnode();
  573.         }
  574.  
  575.     ~_List_alloc() _NOEXCEPT
  576.         {   // destroy head node
  577.         _Freeheadnode(this->_Myhead);
  578.         }
  579.  
  580.     void _Change_alloc(const _Alty& _Al)
  581.         {   // replace old allocator
  582.         _Alnod = _Al;
  583.         }
  584.  
  585.     void _Swap_alloc(_Myt& _Right)
  586.         {   // swap allocators
  587.         _Swap_adl(_Alnod, _Right._Alnod);
  588.         }
  589.  
  590.  #else /* _ITERATOR_DEBUG_LEVEL == 0 */
  591.     _List_alloc(const _Alloc& _Al = _Alloc())
  592.         : _Alnod(_Al)
  593.         {   // construct head node, allocator from _Al
  594.         this->_Myhead = _Buyheadnode();
  595.         _TRY_BEGIN
  596.         _Alloc_proxy();
  597.         _CATCH_ALL
  598.         _Freeheadnode(this->_Myhead);
  599.         _RERAISE;
  600.         _CATCH_END
  601.         }
  602.  
  603.     ~_List_alloc() _NOEXCEPT
  604.         {   // destroy proxy
  605.         _Freeheadnode(this->_Myhead);
  606.         _Free_proxy();
  607.         }
  608.  
  609.     void _Change_alloc(const _Alty& _Al)
  610.         {   // replace old allocator
  611.         _Free_proxy();
  612.         _Alnod = _Al;
  613.         _Alloc_proxy();
  614.         }
  615.  
  616.     void _Swap_alloc(_Myt& _Right)
  617.         {   // swap allocators
  618.         _Swap_adl(_Alnod, _Right._Alnod);
  619.         _Swap_adl(this->_Myproxy, _Right._Myproxy);
  620.         }
  621.  
  622.     void _Alloc_proxy()
  623.         {   // construct proxy from _Alnod
  624.         typename _Alty::template rebind<_Container_proxy>::other
  625.             _Alproxy(_Alnod);
  626.         this->_Myproxy = _Alproxy.allocate(1);
  627.         _Alproxy.construct(this->_Myproxy, _Container_proxy());
  628.         this->_Myproxy->_Mycont = this;
  629.         }
  630.  
  631.     void _Free_proxy()
  632.         {   // destroy proxy
  633.         typename _Alty::template rebind<_Container_proxy>::other
  634.             _Alproxy(_Alnod);
  635.         this->_Orphan_all();
  636.         _Alproxy.destroy(this->_Myproxy);
  637.         _Alproxy.deallocate(this->_Myproxy, 1);
  638.         this->_Myproxy = 0;
  639.         }
  640.  #endif /* _ITERATOR_DEBUG_LEVEL == 0 */
  641.  
  642.     _Nodeptr _Buyheadnode()
  643.         {   // get head node using current allocator
  644.         return (_Buynode0(_Nodeptr(), _Nodeptr()));
  645.         }
  646.  
  647.     void _Freeheadnode(_Nodeptr _Pnode)
  648.         {   // free head node using current allocator
  649.         _Alnod.destroy(
  650.             _STD addressof(this->_Nextnode(_Pnode)));
  651.         _Alnod.destroy(
  652.             _STD addressof(this->_Prevnode(_Pnode)));
  653.         _Alnod.deallocate(_Pnode, 1);
  654.         }
  655.  
  656.     _Nodeptr _Buynode0(_Nodeptr _Next,
  657.         _Nodeptr _Prev)
  658.         {   // allocate a node and set links
  659.         _Nodeptr _Pnode = _Alnod.allocate(1);
  660.  
  661.         if (_Next == _Nodeptr())
  662.             {   // point at self
  663.             _Next = _Pnode;
  664.             _Prev = _Pnode;
  665.             }
  666.         _TRY_BEGIN
  667.         _Alnod.construct(
  668.             _STD addressof(this->_Nextnode(_Pnode)), _Next);
  669.         _Alnod.construct(
  670.             _STD addressof(this->_Prevnode(_Pnode)), _Prev);
  671.         _CATCH_ALL
  672.         _Alnod.deallocate(_Pnode, 1);
  673.         _RERAISE;
  674.         _CATCH_END
  675.  
  676.         return (_Pnode);
  677.         }
  678.  
  679.     _Alty& _Getal()
  680.         {   // get reference to allocator
  681.         return (_Alnod);
  682.         }
  683.  
  684.     const _Alty& _Getal() const
  685.         {   // get reference to allocator
  686.         return (_Alnod);
  687.         }
  688.  
  689.     _Alty _Alnod;   // allocator object for stored elements
  690.     };
  691.  
  692.         // TEMPLATE CLASS _List_alloc
  693. template<class _Alloc_types>
  694.     class _List_alloc<false, _Alloc_types>
  695.         : public _List_val<typename _Alloc_types::_Val_types>
  696.     {   // base class for list to hold allocator with no storage
  697. public:
  698.     typedef _List_alloc<false, _Alloc_types> _Myt;
  699.     typedef _List_val<typename _Alloc_types::_Val_types> _Mybase;
  700.     typedef typename _Alloc_types::_Alloc _Alloc;
  701.     typedef typename _Alloc_types::_Alnod_type _Alty;
  702.     typedef typename _Alloc_types::_Node _Node;
  703.     typedef typename _Alloc_types::_Nodeptr _Nodeptr;
  704.  
  705.  #if _ITERATOR_DEBUG_LEVEL == 0
  706.     _List_alloc(const _Alloc& = _Alloc())
  707.         {   // construct head node, allocator from _Al
  708.         this->_Myhead = _Buyheadnode();
  709.         }
  710.  
  711.     ~_List_alloc() _NOEXCEPT
  712.         {   // destroy head node
  713.         _Freeheadnode(this->_Myhead);
  714.         }
  715.  
  716.     void _Change_alloc(const _Alty&)
  717.         {   // replace old allocator
  718.         }
  719.  
  720.     void _Swap_alloc(_Myt&)
  721.         {   // swap allocators
  722.         }
  723.  
  724.  #else /* _ITERATOR_DEBUG_LEVEL == 0 */
  725.     _List_alloc(const _Alloc& = _Alloc())
  726.         {   // construct allocators from _Al
  727.         this->_Myhead = _Buyheadnode();
  728.         _TRY_BEGIN
  729.         _Alloc_proxy();
  730.         _CATCH_ALL
  731.         _Freeheadnode(this->_Myhead);
  732.         _RERAISE;
  733.         _CATCH_END
  734.         }
  735.  
  736.     ~_List_alloc() _NOEXCEPT
  737.         {   // destroy proxy
  738.         _Freeheadnode(this->_Myhead);
  739.         _Free_proxy();
  740.         }
  741.  
  742.     void _Change_alloc(const _Alty&)
  743.         {   // replace old allocator
  744.         }
  745.  
  746.     void _Swap_alloc(_Myt& _Right)
  747.         {   // swap allocators
  748.         _Swap_adl(this->_Myproxy, _Right._Myproxy);
  749.         }
  750.  
  751.     void _Alloc_proxy()
  752.         {   // construct proxy from _Alnod
  753.         typename _Alty::template rebind<_Container_proxy>::other
  754.             _Alproxy;
  755.         this->_Myproxy = _Alproxy.allocate(1);
  756.         _Alproxy.construct(this->_Myproxy, _Container_proxy());
  757.         this->_Myproxy->_Mycont = this;
  758.         }
  759.  
  760.     void _Free_proxy()
  761.         {   // destroy proxy
  762.         typename _Alty::template rebind<_Container_proxy>::other
  763.             _Alproxy;
  764.         this->_Orphan_all();
  765.         _Alproxy.destroy(this->_Myproxy);
  766.         _Alproxy.deallocate(this->_Myproxy, 1);
  767.         this->_Myproxy = 0;
  768.         }
  769.  #endif /* _ITERATOR_DEBUG_LEVEL == 0 */
  770.  
  771.     _Nodeptr _Buyheadnode()
  772.         {   // get head node using current allocator
  773.         return (_Buynode0(_Nodeptr(), _Nodeptr()));
  774.         }
  775.  
  776.     void _Freeheadnode(_Nodeptr _Pnode)
  777.         {   // free head node using current allocator
  778.         this->_Getal().destroy(
  779.             _STD addressof(this->_Nextnode(_Pnode)));
  780.         this->_Getal().destroy(
  781.             _STD addressof(this->_Prevnode(_Pnode)));
  782.         this->_Getal().deallocate(_Pnode, 1);
  783.         }
  784.  
  785.     _Nodeptr _Buynode0(_Nodeptr _Next,
  786.         _Nodeptr _Prev)
  787.         {   // allocate a node and set links
  788.         _Nodeptr _Pnode = this->_Getal().allocate(1);
  789.  
  790.         if (_Next == _Nodeptr())
  791.             {   // point at self
  792.             _Next = _Pnode;
  793.             _Prev = _Pnode;
  794.             }
  795.         _TRY_BEGIN
  796.         this->_Getal().construct(
  797.             _STD addressof(this->_Nextnode(_Pnode)), _Next);
  798.         this->_Getal().construct(
  799.             _STD addressof(this->_Prevnode(_Pnode)), _Prev);
  800.         _CATCH_ALL
  801.         this->_Getal().deallocate(_Pnode, 1);
  802.         _RERAISE;
  803.         _CATCH_END
  804.  
  805.         return (_Pnode);
  806.         }
  807.  
  808.     _Alty _Getal() const
  809.         {   // get reference to allocator
  810.         return (_Alty());
  811.         }
  812.     };
  813.  
  814.         // TEMPLATE CLASS _List_buy
  815. template<class _Ty,
  816.     class _Alloc>
  817.     class _List_buy
  818.         : public _List_alloc<!is_empty<_Alloc>::value,
  819.             _List_base_types<_Ty, _Alloc> >
  820.     {   // base class for list to hold buynode/freenode functions
  821. public:
  822.     typedef _List_alloc<!is_empty<_Alloc>::value,
  823.         _List_base_types<_Ty, _Alloc> > _Mybase;
  824.     typedef typename _Mybase::_Alty _Alty;
  825.     typedef typename _Mybase::_Nodeptr _Nodeptr;
  826.  
  827.     _List_buy(const _Alloc& _Al = _Alloc())
  828.         : _Mybase(_Al)
  829.         {   // construct from allocator
  830.         }
  831.  
  832. #define _LIST_BUYNODE( \
  833.     TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  834.     TEMPLATE_LIST(_CLASS_TYPE) \
  835.         _Nodeptr _Buynode(_Nodeptr _Next, \
  836.             _Nodeptr _Prev COMMA LIST(_TYPE_REFREF_ARG)) \
  837.         {   /* allocate a node and set links and value */ \
  838.         _Nodeptr _Pnode = this->_Buynode0(_Next, _Prev); \
  839.         _TRY_BEGIN \
  840.         this->_Getal().construct( \
  841.             _STD addressof(this->_Myval(_Pnode)) \
  842.                 COMMA LIST(_FORWARD_ARG)); \
  843.         _CATCH_ALL \
  844.         this->_Getal().deallocate(_Pnode, 1); \
  845.         _RERAISE; \
  846.         _CATCH_END \
  847.         return (_Pnode); \
  848.         }
  849.  
  850. _VARIADIC_EXPAND_0X(_LIST_BUYNODE, , , , )
  851. #undef _LIST_BUYNODE
  852.  
  853.     void _Freenode(_Nodeptr _Pnode)
  854.         {   // give node back
  855.         this->_Getal().destroy(
  856.             _STD addressof(this->_Nextnode(_Pnode)));
  857.         this->_Getal().destroy(
  858.             _STD addressof(this->_Prevnode(_Pnode)));
  859.         this->_Getal().destroy(
  860.             _STD addressof(this->_Myval(_Pnode)));
  861.         this->_Getal().deallocate(_Pnode, 1);
  862.         }
  863.     };
  864.  
  865.         // TEMPLATE CLASS list
  866. template<class _Ty,
  867.     class _Alloc = allocator<_Ty> >
  868.     class list
  869.         : public _List_buy<_Ty, _Alloc>
  870.     {   // bidirectional linked list
  871. public:
  872.     typedef list<_Ty, _Alloc> _Myt;
  873.     typedef _List_buy<_Ty, _Alloc> _Mybase;
  874.     typedef typename _Mybase::_Node _Node;
  875.     typedef typename _Mybase::_Nodeptr _Nodeptr;
  876.     typedef typename _Mybase::_Alty _Alty;
  877.  
  878.     typedef _Alloc allocator_type;
  879.     typedef typename _Mybase::size_type size_type;
  880.     typedef typename _Mybase::difference_type difference_type;
  881.     typedef typename _Mybase::pointer pointer;
  882.     typedef typename _Mybase::const_pointer const_pointer;
  883.     typedef typename _Mybase::reference reference;
  884.     typedef typename _Mybase::const_reference const_reference;
  885.     typedef typename _Mybase::value_type value_type;
  886.  
  887.     typedef typename _Mybase::const_iterator const_iterator;
  888.     typedef typename _Mybase::iterator iterator;
  889.     typedef typename _Mybase::_Unchecked_const_iterator
  890.         _Unchecked_const_iterator;
  891.     typedef typename _Mybase::_Unchecked_iterator
  892.         _Unchecked_iterator;
  893.  
  894.     typedef _STD reverse_iterator<iterator> reverse_iterator;
  895.     typedef _STD reverse_iterator<const_iterator> const_reverse_iterator;
  896.  
  897.     list()
  898.         : _Mybase()
  899.         {   // construct empty list
  900.         }
  901.  
  902.     explicit list(const _Alloc& _Al)
  903.         : _Mybase(_Al)
  904.         {   // construct empty list, allocator
  905.         }
  906.  
  907.     explicit list(size_type _Count)
  908.         : _Mybase()
  909.         {   // construct list from _Count * _Ty()
  910.         resize(_Count);
  911.         }
  912.  
  913.     list(size_type _Count, const _Ty& _Val)
  914.         : _Mybase()
  915.         {   // construct list from _Count * _Val
  916.         _Construct_n(_Count, _Val);
  917.         }
  918.  
  919.     list(size_type _Count, const _Ty& _Val, const _Alloc& _Al)
  920.         : _Mybase(_Al)
  921.         {   // construct list from _Count * _Val, allocator
  922.         _Construct_n(_Count, _Val);
  923.         }
  924.  
  925.     list(const _Myt& _Right)
  926.  
  927.  #if _HAS_CPP0X
  928.         : _Mybase(_Right._Getal().select_on_container_copy_construction())
  929.  
  930.  #else /* _HAS_CPP0X */
  931.         : _Mybase(_Right._Getal())
  932.  #endif /* _HAS_CPP0X */
  933.  
  934.         {   // construct list by copying _Right
  935.         _TRY_BEGIN
  936.         insert(begin(), _Right.begin(), _Right.end());
  937.         _CATCH_ALL
  938.         _Tidy();
  939.         _RERAISE;
  940.         _CATCH_END
  941.         }
  942.  
  943.     list(const _Myt& _Right, const _Alloc& _Al)
  944.         : _Mybase(_Al)
  945.         {   // construct list by copying _Right, allocator
  946.         _TRY_BEGIN
  947.         insert(begin(), _Right.begin(), _Right.end());
  948.         _CATCH_ALL
  949.         _Tidy();
  950.         _RERAISE;
  951.         _CATCH_END
  952.         }
  953.  
  954.     template<class _Iter>
  955.         list(_Iter _First, _Iter _Last,
  956.             typename enable_if<_Is_iterator<_Iter>::value,
  957.                 void>::type ** = 0)
  958.         : _Mybase()
  959.         {   // construct list from [_First, _Last,
  960.         _Construct(_First, _Last);
  961.         }
  962.  
  963.     template<class _Iter>
  964.         list(_Iter _First, _Iter _Last, const _Alloc& _Al,
  965.             typename enable_if<_Is_iterator<_Iter>::value,
  966.                 void>::type ** = 0)
  967.         : _Mybase(_Al)
  968.         {   // construct list, allocator from [_First, _Last)
  969.         _Construct(_First, _Last);
  970.         }
  971.  
  972.     template<class _Iter>
  973.         void _Construct(_Iter _First, _Iter _Last)
  974.         {   // construct list from [_First, _Last), input iterators
  975.         _TRY_BEGIN
  976.         insert(begin(), _First, _Last);
  977.         _CATCH_ALL
  978.         _Tidy();
  979.         _RERAISE;
  980.         _CATCH_END
  981.         }
  982.  
  983.     void _Construct_n(size_type _Count,
  984.         const _Ty& _Val)
  985.         {   // construct from _Count * _Val
  986.         _TRY_BEGIN
  987.         _Insert_n(_Unchecked_begin(), _Count, _Val);
  988.         _CATCH_ALL
  989.         _Tidy();
  990.         _RERAISE;
  991.         _CATCH_END
  992.         }
  993.  
  994.     list(_Myt&& _Right)
  995.         : _Mybase(_Right._Getal())
  996.         {   // construct list by moving _Right
  997.         _Assign_rv(_STD forward<_Myt>(_Right));
  998.         }
  999.  
  1000.     list(_Myt&& _Right, const _Alloc& _Al)
  1001.         : _Mybase(_Al)
  1002.         {   // construct list by moving _Right, allocator
  1003.         _Assign_rv(_STD forward<_Myt>(_Right));
  1004.         }
  1005.  
  1006.     _Myt& operator=(_Myt&& _Right)
  1007.         {   // assign by moving _Right
  1008.         if (this != &_Right)
  1009.             {   // different, assign it
  1010.             clear();
  1011.  
  1012.  #if _HAS_CPP0X
  1013.             if (this->_Getal() != _Right._Getal()
  1014.                 && _Alty::propagate_on_container_move_assignment::value)
  1015.                 this->_Change_alloc(_Right._Getal());
  1016.  #endif /* _HAS_CPP0X */
  1017.  
  1018.             _Assign_rv(_STD forward<_Myt>(_Right));
  1019.             }
  1020.         return (*this);
  1021.         }
  1022.  
  1023.     void _Assign_rv(_Myt&& _Right)
  1024.         {   // swap with empty *this, same allocator
  1025.         this->_Swap_all(_Right);
  1026.         _Swap_adl(this->_Myhead, _Right._Myhead);
  1027.         _STD swap(this->_Mysize, _Right._Mysize);
  1028.         }
  1029.  
  1030.     void push_front(_Ty&& _Val)
  1031.         {   // insert element at beginning
  1032.         _Insert(_Unchecked_begin(), _STD forward<_Ty>(_Val));
  1033.         }
  1034.  
  1035.     void push_back(_Ty&& _Val)
  1036.         {   // insert element at end
  1037.         _Insert(_Unchecked_end(), _STD forward<_Ty>(_Val));
  1038.         }
  1039.  
  1040.     iterator insert(const_iterator _Where, _Ty&& _Val)
  1041.         {   // insert _Val at _Where
  1042.         return (emplace(_Where, _STD forward<_Ty>(_Val)));
  1043.         }
  1044.  
  1045. #define _LIST_EMPLACE_INSERT( \
  1046.     TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
  1047.     TEMPLATE_LIST(_CLASS_TYPE) \
  1048.         void emplace_front(LIST(_TYPE_REFREF_ARG)) \
  1049.         {   /* insert element at beginning */ \
  1050.         _Insert(_Unchecked_begin() COMMA LIST(_FORWARD_ARG)); \
  1051.         } \
  1052.     TEMPLATE_LIST(_CLASS_TYPE) \
  1053.         void emplace_back(LIST(_TYPE_REFREF_ARG)) \
  1054.         {   /* insert element at end */ \
  1055.         _Insert(_Unchecked_end() COMMA LIST(_FORWARD_ARG)); \
  1056.         } \
  1057.     TEMPLATE_LIST(_CLASS_TYPE) \
  1058.         iterator emplace(const_iterator _Where \
  1059.             COMMA LIST(_TYPE_REFREF_ARG)) \
  1060.         {   /* insert element at _Where */ \
  1061.         _LIST_EMPLACE_CHECK \
  1062.         _Insert(_Where._Unchecked() COMMA LIST(_FORWARD_ARG)); \
  1063.         return (_Make_iter(--_Where)); \
  1064.         } \
  1065.     TEMPLATE_LIST(_CLASS_TYPE) \
  1066.         void _Insert(_Unchecked_const_iterator _Where \
  1067.             COMMA LIST(_TYPE_REFREF_ARG)) \
  1068.         {   /* insert element at _Where */ \
  1069.         _Nodeptr _Pnode = _Where._Mynode(); \
  1070.         _Nodeptr _Newnode = this->_Buynode(_Pnode, \
  1071.             this->_Prevnode(_Pnode) COMMA LIST(_FORWARD_ARG)); \
  1072.         _Incsize(1); \
  1073.         this->_Prevnode(_Pnode) = _Newnode; \
  1074.         this->_Nextnode(this->_Prevnode(_Newnode)) = _Newnode; \
  1075.         }
  1076.  
  1077.  #if _ITERATOR_DEBUG_LEVEL == 2
  1078. #define _LIST_EMPLACE_CHECK \
  1079.         if (_Where._Getcont() != this) \
  1080.             _DEBUG_ERROR("list emplace iterator outside range");
  1081.  
  1082.  #else /* _ITERATOR_DEBUG_LEVEL == 2 */
  1083. #define _LIST_EMPLACE_CHECK
  1084.  #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
  1085.  
  1086. _VARIADIC_EXPAND_0X(_LIST_EMPLACE_INSERT, , , , )
  1087. #undef _LIST_EMPLACE_CHECK
  1088. #undef _LIST_EMPLACE_INSERT
  1089.  
  1090.     ~list() _NOEXCEPT
  1091.         {   // destroy the object
  1092.         _Tidy();
  1093.         }
  1094.  
  1095.     _Myt& operator=(const _Myt& _Right)
  1096.         {   // assign _Right
  1097.         if (this != &_Right)
  1098.             {   // different, assign it
  1099.  #if _HAS_CPP0X
  1100.             if (this->_Getal() != _Right._Getal()
  1101.                 && _Alty::propagate_on_container_copy_assignment::value)
  1102.                 {   // change allocator before copying
  1103.                 clear();
  1104.                 this->_Change_alloc(_Right._Getal());
  1105.                 }
  1106.  #endif /* _HAS_CPP0X */
  1107.  
  1108.             assign(_Right.begin(), _Right.end());
  1109.             }
  1110.         return (*this);
  1111.         }
  1112.  
  1113.     iterator begin() _NOEXCEPT
  1114.         {   // return iterator for beginning of mutable sequence
  1115.         return (iterator(this->_Nextnode(this->_Myhead), this));
  1116.         }
  1117.  
  1118.     const_iterator begin() const _NOEXCEPT
  1119.         {   // return iterator for beginning of nonmutable sequence
  1120.         return (const_iterator(this->_Nextnode(this->_Myhead), this));
  1121.         }
  1122.  
  1123.     iterator end() _NOEXCEPT
  1124.         {   // return iterator for end of mutable sequence
  1125.         return (iterator(this->_Myhead, this));
  1126.         }
  1127.  
  1128.     const_iterator end() const _NOEXCEPT
  1129.         {   // return iterator for end of nonmutable sequence
  1130.         return (const_iterator(this->_Myhead, this));
  1131.         }
  1132.  
  1133.     _Unchecked_iterator _Unchecked_begin()
  1134.         {   // return iterator for beginning of mutable sequence
  1135.         return (_Unchecked_iterator(this->_Nextnode(this->_Myhead),
  1136.             this));
  1137.         }
  1138.  
  1139.     _Unchecked_const_iterator _Unchecked_begin() const
  1140.         {   // return iterator for beginning of nonmutable sequence
  1141.         return (_Unchecked_const_iterator(this->_Nextnode(this->_Myhead),
  1142.             this));
  1143.         }
  1144.  
  1145.     _Unchecked_iterator _Unchecked_end()
  1146.         {   // return unchecked iterator for end of mutable sequence
  1147.         return (_Unchecked_iterator(this->_Myhead, this));
  1148.         }
  1149.  
  1150.     _Unchecked_const_iterator _Unchecked_end() const
  1151.         {   // return unchecked iterator for end of nonmutable sequence
  1152.         return (_Unchecked_const_iterator(this->_Myhead, this));
  1153.         }
  1154.  
  1155.     iterator _Make_iter(const_iterator _Where) const _NOEXCEPT
  1156.         {   // make iterator from const_iterator
  1157.         return (iterator(_Where._Ptr, this));
  1158.         }
  1159.  
  1160.     iterator _Make_iter(_Unchecked_const_iterator _Where) const
  1161.         {   // make iterator from _Unchecked_const_iterator
  1162.         return (iterator(_Where._Ptr, this));
  1163.         }
  1164.  
  1165.     reverse_iterator rbegin() _NOEXCEPT
  1166.         {   // return iterator for beginning of reversed mutable sequence
  1167.         return (reverse_iterator(end()));
  1168.         }
  1169.  
  1170.     const_reverse_iterator rbegin() const _NOEXCEPT
  1171.         {   // return iterator for beginning of reversed nonmutable sequence
  1172.         return (const_reverse_iterator(end()));
  1173.         }
  1174.  
  1175.     reverse_iterator rend() _NOEXCEPT
  1176.         {   // return iterator for end of reversed mutable sequence
  1177.         return (reverse_iterator(begin()));
  1178.         }
  1179.  
  1180.     const_reverse_iterator rend() const _NOEXCEPT
  1181.         {   // return iterator for end of reversed nonmutable sequence
  1182.         return (const_reverse_iterator(begin()));
  1183.         }
  1184.  
  1185.  #if _HAS_CPP0X
  1186.     const_iterator cbegin() const _NOEXCEPT
  1187.         {   // return iterator for beginning of nonmutable sequence
  1188.         return (((const _Myt *)this)->begin());
  1189.         }
  1190.  
  1191.     const_iterator cend() const _NOEXCEPT
  1192.         {   // return iterator for end of nonmutable sequence
  1193.         return (((const _Myt *)this)->end());
  1194.         }
  1195.  
  1196.     const_reverse_iterator crbegin() const _NOEXCEPT
  1197.         {   // return iterator for beginning of reversed nonmutable sequence
  1198.         return (((const _Myt *)this)->rbegin());
  1199.         }
  1200.  
  1201.     const_reverse_iterator crend() const _NOEXCEPT
  1202.         {   // return iterator for end of reversed nonmutable sequence
  1203.         return (((const _Myt *)this)->rend());
  1204.         }
  1205.  #endif /* _HAS_CPP0X */
  1206.  
  1207.     void resize(size_type _Newsize)
  1208.         {   // determine new length, padding with _Ty() elements as needed
  1209.         if (this->_Mysize < _Newsize)
  1210.             {   // pad to make larger
  1211.             size_type _Count = 0;
  1212.             _TRY_BEGIN
  1213.             for (; this->_Mysize < _Newsize; ++_Count)
  1214.                 _Insert(_Unchecked_end());
  1215.             _CATCH_ALL
  1216.             for (; 0 < _Count; --_Count)
  1217.                 pop_back(); // undo inserts
  1218.             _RERAISE;
  1219.             _CATCH_END
  1220.             }
  1221.         else
  1222.             while (_Newsize < this->_Mysize)
  1223.                 pop_back();
  1224.         }
  1225.  
  1226.     void resize(size_type _Newsize, const _Ty& _Val)
  1227.         {   // determine new length, padding with _Val elements as needed
  1228.         if (this->_Mysize < _Newsize)
  1229.             _Insert_n(_Unchecked_end(), _Newsize - this->_Mysize, _Val);
  1230.         else
  1231.             while (_Newsize < this->_Mysize)
  1232.                 pop_back();
  1233.         }
  1234.  
  1235.     size_type size() const _NOEXCEPT
  1236.         {   // return length of sequence
  1237.         return (this->_Mysize);
  1238.         }
  1239.  
  1240.     size_type max_size() const _NOEXCEPT
  1241.         {   // return maximum possible length of sequence
  1242.         return (this->_Getal().max_size());
  1243.         }
  1244.  
  1245.     bool empty() const _NOEXCEPT
  1246.         {   // test if sequence is empty
  1247.         return (this->_Mysize == 0);
  1248.         }
  1249.  
  1250.     allocator_type get_allocator() const _NOEXCEPT
  1251.         {   // return allocator object for values
  1252.         return (this->_Getal());
  1253.         }
  1254.  
  1255.     reference front()
  1256.         {   // return first element of mutable sequence
  1257.         return (*begin());
  1258.         }
  1259.  
  1260.     const_reference front() const
  1261.         {   // return first element of nonmutable sequence
  1262.         return (*begin());
  1263.         }
  1264.  
  1265.     reference back()
  1266.         {   // return last element of mutable sequence
  1267.         return (*(--end()));
  1268.         }
  1269.  
  1270.     const_reference back() const
  1271.         {   // return last element of nonmutable sequence
  1272.         return (*(--end()));
  1273.         }
  1274.  
  1275.     void push_front(const _Ty& _Val)
  1276.         {   // insert element at beginning
  1277.         _Insert(_Unchecked_begin(), _Val);
  1278.         }
  1279.  
  1280.     void pop_front()
  1281.         {   // erase element at beginning
  1282.         erase(begin());
  1283.         }
  1284.  
  1285.     void push_back(const _Ty& _Val)
  1286.         {   // insert element at end
  1287.         _Insert(_Unchecked_end(), _Val);
  1288.         }
  1289.  
  1290.     void pop_back()
  1291.         {   // erase element at end
  1292.         erase(--end());
  1293.         }
  1294.  
  1295.     template<class _Iter>
  1296.         typename enable_if<_Is_iterator<_Iter>::value,
  1297.             void>::type
  1298.         assign(_Iter _First, _Iter _Last)
  1299.         {   // assign [_First, _Last), input iterators
  1300.         iterator _Old = begin();
  1301.         _TRY_BEGIN
  1302.         for (; _First != _Last && _Old != end(); ++_First, ++_Old)
  1303.             *_Old = *_First;
  1304.         for (; _First != _Last; ++_First)
  1305.             _Insert(_Unchecked_end(), *_First);
  1306.         _CATCH_ALL
  1307.         clear();
  1308.         _RERAISE;
  1309.         _CATCH_END
  1310.         erase(_Old, end());
  1311.         }
  1312.  
  1313.     void assign(size_type _Count, const _Ty& _Val)
  1314.         {   // assign _Count * _Val
  1315.         _Assign_n(_Count, _Val);
  1316.         }
  1317.  
  1318.     iterator insert(const_iterator _Where, const _Ty& _Val)
  1319.         {   // insert _Val at _Where
  1320.  #if _ITERATOR_DEBUG_LEVEL == 2
  1321.         if (_Where._Getcont() != this)
  1322.             _DEBUG_ERROR("list insert iterator outside range");
  1323.  #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
  1324.  
  1325.         _Insert(_Where._Unchecked(), _Val);
  1326.         return (_Make_iter(--_Where));
  1327.         }
  1328.  
  1329.     iterator insert(const_iterator _Where, size_type _Count, const _Ty& _Val)
  1330.         {   // insert _Count * _Val at _Where
  1331.  #if _ITERATOR_DEBUG_LEVEL == 2
  1332.         if (_Where._Getcont() != this)
  1333.             _DEBUG_ERROR("list insert iterator outside range");
  1334.  #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
  1335.  
  1336.         iterator _Prev = _Make_iter(_Where);
  1337.         if (_Prev == begin())
  1338.             {   // insert sequence at beginning
  1339.             _Insert_n(_Where._Unchecked(), _Count, _Val);
  1340.             return (begin());
  1341.             }
  1342.         else
  1343.             {   // insert sequence not at beginning
  1344.             --_Prev;
  1345.             _Insert_n(_Where._Unchecked(), _Count, _Val);
  1346.             return (++_Prev);
  1347.             }
  1348.         }
  1349.  
  1350.     template<class _Iter>
  1351.         typename enable_if<_Is_iterator<_Iter>::value,
  1352.             iterator>::type
  1353.         insert(const_iterator _Where, _Iter _First, _Iter _Last)
  1354.         {   // insert [_First, _Last) at _Where
  1355.  #if _ITERATOR_DEBUG_LEVEL == 2
  1356.         if (_Where._Getcont() != this)
  1357.             _DEBUG_ERROR("list insert iterator outside range");
  1358.  #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
  1359.  
  1360.         iterator _Prev = _Make_iter(_Where);
  1361.         if (_Prev == begin())
  1362.             {   // insert sequence at beginning
  1363.             _Insert_range(_Where._Unchecked(), _First, _Last,
  1364.                 _Iter_cat(_First));
  1365.             return (begin());
  1366.             }
  1367.         else
  1368.             {   // insert sequence not at beginning
  1369.             --_Prev;
  1370.             _Insert_range(_Where._Unchecked(), _First, _Last,
  1371.                 _Iter_cat(_First));
  1372.             return (++_Prev);
  1373.             }
  1374.         }
  1375.  
  1376.     template<class _Iter>
  1377.         void _Insert_range(_Unchecked_const_iterator _Where,
  1378.             _Iter _First, _Iter _Last, input_iterator_tag)
  1379.         {   // insert [_First, _Last) at _Where, input iterators
  1380.         size_type _Num = 0;
  1381.  
  1382.         _TRY_BEGIN
  1383.         for (; _First != _Last; ++_First, ++_Num)
  1384.             _Insert(_Where, *_First);
  1385.         _CATCH_ALL
  1386.         for (; 0 < _Num; --_Num)
  1387.             {   // undo inserts
  1388.             _Unchecked_const_iterator _Before = _Where;
  1389.             _Unchecked_erase(--_Before);
  1390.             }
  1391.         _RERAISE;
  1392.         _CATCH_END
  1393.         }
  1394.  
  1395.     template<class _Iter>
  1396.         void _Insert_range(_Unchecked_const_iterator _Where,
  1397.             _Iter _First, _Iter _Last, forward_iterator_tag)
  1398.         {   // insert [_First, _Last) at _Where, forward iterators
  1399.         _DEBUG_RANGE(_First, _Last);
  1400.         _Iter _Next = _First;
  1401.  
  1402.         _TRY_BEGIN
  1403.         for (; _First != _Last; ++_First)
  1404.             _Insert(_Where, *_First);
  1405.         _CATCH_ALL
  1406.         for (; _Next != _First; ++_Next)
  1407.             {   // undo inserts
  1408.             _Unchecked_const_iterator _Before = _Where;
  1409.             _Unchecked_erase(--_Before);
  1410.             }
  1411.         _RERAISE;
  1412.         _CATCH_END
  1413.         }
  1414.  
  1415.     iterator erase(const_iterator _Where)
  1416.         {   // erase element at _Where
  1417.  #if _ITERATOR_DEBUG_LEVEL == 2
  1418.         if (_Where._Getcont() != this || _Where._Ptr == this->_Myhead)
  1419.             _DEBUG_ERROR("list erase iterator outside range");
  1420.         _Nodeptr _Pnode = (_Where++)._Mynode();
  1421.         _Orphan_ptr(*this, _Pnode);
  1422.  
  1423.  #else /* _ITERATOR_DEBUG_LEVEL == 2 */
  1424.         _Nodeptr _Pnode = (_Where++)._Mynode();
  1425.  #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
  1426.  
  1427.         if (_Pnode != this->_Myhead)
  1428.             {   // not list head, safe to erase
  1429.             this->_Nextnode(this->_Prevnode(_Pnode)) =
  1430.                 this->_Nextnode(_Pnode);
  1431.             this->_Prevnode(this->_Nextnode(_Pnode)) =
  1432.                 this->_Prevnode(_Pnode);
  1433.             this->_Freenode(_Pnode);
  1434.             --this->_Mysize;
  1435.             }
  1436.         return (_Make_iter(_Where));
  1437.         }
  1438.  
  1439.     void _Unchecked_erase(_Unchecked_const_iterator _Where)
  1440.         {   // erase element at _Where
  1441.         _Nodeptr _Pnode = _Where._Mynode();
  1442.  
  1443.         if (_Pnode != this->_Myhead)
  1444.             {   // not list head, safe to erase
  1445.             this->_Nextnode(this->_Prevnode(_Pnode)) =
  1446.                 this->_Nextnode(_Pnode);
  1447.             this->_Prevnode(this->_Nextnode(_Pnode)) =
  1448.                 this->_Prevnode(_Pnode);
  1449.             this->_Freenode(_Pnode);
  1450.             --this->_Mysize;
  1451.             }
  1452.         }
  1453.  
  1454.     iterator erase(const_iterator _First, const_iterator _Last)
  1455.         {   // erase [_First, _Last)
  1456.         if (_First == begin() && _Last == end())
  1457.             {   // erase all and return fresh iterator
  1458.             clear();
  1459.             return (end());
  1460.             }
  1461.         else
  1462.             {   // erase subrange
  1463.             while (_First != _Last)
  1464.                 _First = erase(_First);
  1465.             return (_Make_iter(_Last));
  1466.             }
  1467.         }
  1468.  
  1469.     void clear() _NOEXCEPT
  1470.         {   // erase all
  1471.  #if _ITERATOR_DEBUG_LEVEL == 2
  1472.         this->_Orphan_all();
  1473.  #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
  1474.  
  1475.         _Nodeptr _Pnode = this->_Nextnode(this->_Myhead);
  1476.         this->_Nextnode(this->_Myhead) = this->_Myhead;
  1477.         this->_Prevnode(this->_Myhead) = this->_Myhead;
  1478.         this->_Mysize = 0;
  1479.  
  1480.         for (_Nodeptr _Pnext; _Pnode != this->_Myhead; _Pnode = _Pnext)
  1481.             {   // delete an element
  1482.             _Pnext = this->_Nextnode(_Pnode);
  1483.             this->_Freenode(_Pnode);
  1484.             }
  1485.         }
  1486.  
  1487.     void swap(_Myt& _Right)
  1488.         {   // exchange contents with _Right
  1489.         if (this == &_Right)
  1490.             ;   // same object, do nothing
  1491.         else if (this->_Getal() == _Right._Getal())
  1492.             {   // same allocator, swap control information
  1493.             this->_Swap_all(_Right);
  1494.             _Swap_adl(this->_Myhead, _Right._Myhead);
  1495.             _STD swap(this->_Mysize, _Right._Mysize);
  1496.             }
  1497.  
  1498.  #if _HAS_CPP0X
  1499.         else if (_Alty::propagate_on_container_swap::value)
  1500.             {   // swap allocators and control information
  1501.             this->_Swap_alloc(_Right);
  1502.             _Swap_adl(this->_Myhead, _Right._Myhead);
  1503.             _STD swap(this->_Mysize, _Right._Mysize);
  1504.             }
  1505.  #endif /* _HAS_CPP0X */
  1506.  
  1507.         else
  1508.             {   // different allocator, do splices
  1509.             iterator _Where = begin();
  1510.             splice(_Where, _Right);
  1511.             _Right.splice(_Right.begin(), *this, _Where, end());
  1512.             }
  1513.         }
  1514.  
  1515.     void splice(const_iterator _Where, _Myt& _Right)
  1516.         {   // splice all of _Right at _Where
  1517.         if (this != &_Right && !_Right.empty())
  1518.             {   // worth splicing, do it
  1519.             _Splice(_Where, _Right, _Right.begin(), _Right.end(),
  1520.                 _Right._Mysize);
  1521.             }
  1522.         }
  1523.  
  1524.     void splice(const_iterator _Where, _Myt&& _Right)
  1525.         {   // splice all of _Right at _Where
  1526.         splice(_Where, (_Myt&)_Right);
  1527.         }
  1528.  
  1529.     void splice(const_iterator _Where, _Myt& _Right,
  1530.         const_iterator _First)
  1531.         {   // splice _Right [_First, _First + 1) at _Where
  1532.  #if _ITERATOR_DEBUG_LEVEL == 2
  1533.         if (_First == _Right.end())
  1534.             _DEBUG_ERROR("list splice iterator outside range");
  1535.         else
  1536.  
  1537.  #else /* _ITERATOR_DEBUG_LEVEL == 2 */
  1538.         if (_First != _Right.end())
  1539.  #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
  1540.  
  1541.             {   // element exists, try splice
  1542.             const_iterator _Last = _First;
  1543.             ++_Last;
  1544.             if (this != &_Right
  1545.                 || (_Where != _First && _Where != _Last))
  1546.                 _Splice(_Where, _Right, _First, _Last, 1);
  1547.             }
  1548.         }
  1549.  
  1550.     void splice(const_iterator _Where, _Myt&& _Right,
  1551.         const_iterator _First)
  1552.         {   // splice _Right [_First, _First + 1) at _Where
  1553.         splice(_Where, (_Myt&)_Right, _First);
  1554.         }
  1555.  
  1556.     void splice(const_iterator _Where,
  1557.         _Myt& _Right, const_iterator _First, const_iterator _Last)
  1558.         {   // splice _Right [_First, _Last) at _Where
  1559.         if (_First != _Last && (this != &_Right || _Where != _Last))
  1560.             {   // worth splicing, do it
  1561.             size_type _Count = 0;
  1562.  
  1563.             if (this == &_Right)
  1564.                 ;   // just rearrange this list
  1565.             else if (_First == _Right.begin() && _Last == _Right.end())
  1566.                 _Count = _Right._Mysize;    // splice in whole list
  1567.             else
  1568.                 {   // count nodes and check for knot
  1569.                 const_iterator _Next = _First;
  1570.  
  1571.                 for (; _Next != _Last; ++_Next, ++_Count)
  1572.                     if (_Next == _Right.end())
  1573.                         _Xlength_error("list<T> bad splice");
  1574.                 }
  1575.             _Splice(_Where, _Right, _First, _Last, _Count);
  1576.             }
  1577.         }
  1578.  
  1579.     void splice(const_iterator _Where,
  1580.         _Myt&& _Right, const_iterator _First, const_iterator _Last)
  1581.         {   // splice _Right [_First, _Last) at _Where
  1582.         splice(_Where, (_Myt&)_Right, _First, _Last);
  1583.         }
  1584.  
  1585.     void remove(const _Ty& _Val_arg)
  1586.         {   // erase each element matching _Val
  1587.         const _Ty _Val = _Val_arg;  // in case it's removed along the way
  1588.         const _Nodeptr _Phead = this->_Myhead;
  1589.         _Nodeptr _Pnode = this->_Nextnode(_Phead);
  1590.  
  1591.         while (_Pnode != _Phead)
  1592.             if (_Pnode->_Myval == _Val)
  1593.                 {   // match, remove it
  1594.                 const _Nodeptr _Pprev = this->_Prevnode(_Pnode);
  1595.                 const _Nodeptr _Perase = _Pnode;
  1596.                 _Pnode = this->_Nextnode(_Pnode);
  1597.  
  1598.                 this->_Nextnode(_Pprev) = _Pnode;
  1599.                 this->_Prevnode(_Pnode) = _Pprev;
  1600.                 this->_Freenode(_Perase);
  1601.  
  1602.                 --this->_Mysize;
  1603.                 }
  1604.             else
  1605.                 _Pnode = this->_Nextnode(_Pnode);
  1606.         }
  1607.  
  1608.     template<class _Pr1>
  1609.         void remove_if(_Pr1 _Pred)
  1610.         {   // erase each element satisfying _Pred
  1611.         const _Nodeptr _Phead = this->_Myhead;
  1612.         _Nodeptr _Pnode = this->_Nextnode(_Phead);
  1613.  
  1614.         while (_Pnode != _Phead)
  1615.             if (_Pred(_Pnode->_Myval))
  1616.                 {   // match, remove it
  1617.                 const _Nodeptr _Pprev = this->_Prevnode(_Pnode);
  1618.                 const _Nodeptr _Perase = _Pnode;
  1619.                 _Pnode = this->_Nextnode(_Pnode);
  1620.  
  1621.                 this->_Nextnode(_Pprev) = _Pnode;
  1622.                 this->_Prevnode(_Pnode) = _Pprev;
  1623.                 this->_Freenode(_Perase);
  1624.  
  1625.                 --this->_Mysize;
  1626.                 }
  1627.             else
  1628.                 _Pnode = this->_Nextnode(_Pnode);
  1629.         }
  1630.  
  1631.     void unique()
  1632.         {   // erase each element matching previous
  1633.         const _Nodeptr _Phead = this->_Myhead;
  1634.         _Nodeptr _Pprev = this->_Nextnode(_Phead);
  1635.         _Nodeptr _Pnode = this->_Nextnode(_Pprev);
  1636.  
  1637.         while (_Pnode != _Phead)
  1638.             if (_Pprev->_Myval == _Pnode->_Myval)
  1639.                 {   // match, remove it
  1640.                 const _Nodeptr _Perase = _Pnode;
  1641.                 _Pnode = this->_Nextnode(_Pnode);
  1642.  
  1643.                 this->_Nextnode(_Pprev) = _Pnode;
  1644.                 this->_Prevnode(_Pnode) = _Pprev;
  1645.                 this->_Freenode(_Perase);
  1646.  
  1647.                 --this->_Mysize;
  1648.                 }
  1649.             else
  1650.                 {   // no match, advance
  1651.                 _Pprev = _Pnode;
  1652.                 _Pnode = this->_Nextnode(_Pnode);
  1653.                 }
  1654.         }
  1655.  
  1656.     template<class _Pr2>
  1657.         void unique(_Pr2 _Pred)
  1658.         {   // erase each element satisfying _Pred with previous
  1659.         const _Nodeptr _Phead = this->_Myhead;
  1660.         _Nodeptr _Pprev = this->_Nextnode(_Phead);
  1661.         _Nodeptr _Pnode = this->_Nextnode(_Pprev);
  1662.  
  1663.         while (_Pnode != _Phead)
  1664.             if (_Pred(_Pprev->_Myval, _Pnode->_Myval))
  1665.                 {   // match, remove it
  1666.                 const _Nodeptr _Perase = _Pnode;
  1667.                 _Pnode = this->_Nextnode(_Pnode);
  1668.  
  1669.                 this->_Nextnode(_Pprev) = _Pnode;
  1670.                 this->_Prevnode(_Pnode) = _Pprev;
  1671.                 this->_Freenode(_Perase);
  1672.  
  1673.                 --this->_Mysize;
  1674.                 }
  1675.             else
  1676.                 {   // no match, advance
  1677.                 _Pprev = _Pnode;
  1678.                 _Pnode = this->_Nextnode(_Pnode);
  1679.                 }
  1680.         }
  1681.  
  1682.     void merge(_Myt& _Right)
  1683.         {   // merge in elements from _Right, both ordered by operator<
  1684.         if (&_Right != this)
  1685.             {   // safe to merge, do it
  1686.             iterator _First1 = begin(), _Last1 = end();
  1687.             iterator _First2 = _Right.begin(), _Last2 = _Right.end();
  1688.             _DEBUG_ORDER(_First1, _Last1);
  1689.             _DEBUG_ORDER(_First2, _Last2);
  1690.  
  1691.             while (_First1 != _Last1 && _First2 != _Last2)
  1692.                 if (_DEBUG_LT(*_First2, *_First1))
  1693.                     {   // splice in an element from _Right
  1694.                     iterator _Mid2 = _First2;
  1695.                     _Splice(_First1, _Right, _First2, ++_Mid2, 1);
  1696.                     _First2 = _Mid2;
  1697.                     }
  1698.                 else
  1699.                     ++_First1;
  1700.  
  1701.             if (_First2 != _Last2)
  1702.                 _Splice(_Last1, _Right, _First2, _Last2,
  1703.                     _Right._Mysize);    // splice remainder of _Right
  1704.             }
  1705.         }
  1706.  
  1707.     void merge(_Myt&& _Right)
  1708.         {   // merge in elements from _Right, both ordered by operator<
  1709.         merge((_Myt&)_Right);
  1710.         }
  1711.  
  1712.     template<class _Pr2>
  1713.         void merge(_Myt& _Right, _Pr2 _Pred)
  1714.         {   // merge in elements from _Right, both ordered by _Pred
  1715.         if (&_Right != this)
  1716.             {   // safe to merge, do it
  1717.             iterator _First1 = begin(), _Last1 = end();
  1718.             iterator _First2 = _Right.begin(), _Last2 = _Right.end();
  1719.             _DEBUG_ORDER_PRED(_First1, _Last1, _Pred);
  1720.             _DEBUG_ORDER_PRED(_First2, _Last2, _Pred);
  1721.  
  1722.             while (_First1 != _Last1 && _First2 != _Last2)
  1723.                 if (_DEBUG_LT_PRED(_Pred, *_First2, *_First1))
  1724.                     {   // splice in an element from _Right
  1725.                     iterator _Mid2 = _First2;
  1726.                     _Splice(_First1, _Right, _First2, ++_Mid2, 1);
  1727.                     _First2 = _Mid2;
  1728.                     }
  1729.                 else
  1730.                     ++_First1;
  1731.  
  1732.             if (_First2 != _Last2)
  1733.                 _Splice(_Last1, _Right, _First2, _Last2,
  1734.                     _Right._Mysize);    // splice remainder of _Right
  1735.             }
  1736.         }
  1737.  
  1738.     template<class _Pr2>
  1739.         void merge(_Myt&& _Right, _Pr2 _Pred)
  1740.         {   // merge in elements from _Right, both ordered by _Pred
  1741.         merge((_Myt&)_Right, _Pred);
  1742.         }
  1743.  
  1744.     void sort()
  1745.         {   // order sequence, using operator<
  1746.         if (2 <= this->_Mysize)
  1747.             {   // worth sorting, do it
  1748.             const size_t _MAXBINS = 25;
  1749.             _Myt _Templist(this->_Getal()), _Binlist[_MAXBINS + 1];
  1750.             size_t _Maxbin = 0;
  1751.  
  1752.             while (!empty())
  1753.                 {   // sort another element, using bins
  1754.                 _Templist._Splice_same(_Templist.begin(), *this, begin(),
  1755.                     ++begin(), 1);
  1756.  
  1757.                 size_t _Bin;
  1758.                 for (_Bin = 0; _Bin < _Maxbin && !_Binlist[_Bin].empty();
  1759.                     ++_Bin)
  1760.                     {   // merge into ever larger bins
  1761.                     _Binlist[_Bin].merge(_Templist);
  1762.                     _Binlist[_Bin].swap(_Templist);
  1763.                     }
  1764.  
  1765.                 if (_Bin == _MAXBINS)
  1766.                     _Binlist[_Bin - 1].merge(_Templist);
  1767.                 else
  1768.                     {   // spill to new bin, while they last
  1769.                     _Binlist[_Bin].swap(_Templist);
  1770.                     if (_Bin == _Maxbin)
  1771.                         ++_Maxbin;
  1772.                     }
  1773.                 }
  1774.  
  1775.             for (size_t _Bin = 1; _Bin < _Maxbin; ++_Bin)
  1776.                 _Binlist[_Bin].merge(_Binlist[_Bin - 1]);   // merge up
  1777.  
  1778.             _Analysis_assume_(0 < _Maxbin);
  1779.  
  1780.             splice(begin(), _Binlist[_Maxbin - 1]); // result in last bin
  1781.             }
  1782.         }
  1783.  
  1784.     template<class _Pr2>
  1785.         void sort(_Pr2 _Pred)
  1786.         {   // order sequence, using _Pred
  1787.         if (2 <= this->_Mysize)
  1788.             {   // worth sorting, do it
  1789.             const size_t _MAXBINS = 25;
  1790.             _Myt _Templist(this->_Getal()), _Binlist[_MAXBINS + 1];
  1791.             size_t _Maxbin = 0;
  1792.  
  1793.             while (!empty())
  1794.                 {   // sort another element, using bins
  1795.                 _Templist._Splice_same(_Templist.begin(), *this, begin(),
  1796.                     ++begin(), 1);
  1797.  
  1798.                 size_t _Bin;
  1799.                 for (_Bin = 0; _Bin < _Maxbin && !_Binlist[_Bin].empty();
  1800.                     ++_Bin)
  1801.                     {   // merge into ever larger bins
  1802.                     _Binlist[_Bin].merge(_Templist, _Pred);
  1803.                     _Binlist[_Bin].swap(_Templist);
  1804.                     }
  1805.  
  1806.                 if (_Bin == _MAXBINS)
  1807.                     _Binlist[_Bin - 1].merge(_Templist, _Pred);
  1808.                 else
  1809.                     {   // spill to new bin, while they last
  1810.                     _Binlist[_Bin].swap(_Templist);
  1811.                     if (_Bin == _Maxbin)
  1812.                         ++_Maxbin;
  1813.                     }
  1814.                 }
  1815.  
  1816.             for (size_t _Bin = 1; _Bin < _Maxbin; ++_Bin)
  1817.                 _Binlist[_Bin].merge(_Binlist[_Bin - 1],
  1818.                     _Pred); // merge up
  1819.  
  1820.             _Analysis_assume_(0 < _Maxbin);
  1821.  
  1822.             splice(begin(), _Binlist[_Maxbin - 1]); // result in last bin
  1823.             }
  1824.         }
  1825.  
  1826.     void reverse() _NOEXCEPT
  1827.         {   // reverse sequence
  1828.         const _Nodeptr _Phead = this->_Myhead;
  1829.         _Nodeptr _Pnode = _Phead;
  1830.  
  1831.         for (; ; )
  1832.             {   // flip pointers in a node
  1833.             const _Nodeptr _Pnext = this->_Nextnode(_Pnode);
  1834.             this->_Nextnode(_Pnode) = this->_Prevnode(_Pnode);
  1835.             this->_Prevnode(_Pnode) = _Pnext;
  1836.  
  1837.             if (_Pnext == _Phead)
  1838.                 break;
  1839.             _Pnode = _Pnext;
  1840.             }
  1841.         }
  1842.  
  1843.     void _Splice(const_iterator _Where,
  1844.         _Myt& _Right, const_iterator _First, const_iterator _Last,
  1845.         size_type _Count)
  1846.         {   // splice _Right [_First, _Last) before _Where
  1847.  #if _ITERATOR_DEBUG_LEVEL == 2
  1848.         if (_Where._Getcont() != this)
  1849.             _DEBUG_ERROR("list splice iterator outside range");
  1850.         if (this->_Getal() == _Right._Getal())
  1851.             {   // same allocator, just relink
  1852.             if (this != &_Right)
  1853.                 for (const_iterator _Next = _First; _Next != _Last; )
  1854.                     {   // transfer ownership
  1855.                     const_iterator _Iter = _Next++;
  1856.                     _Orphan_ptr(_Right, _Iter._Ptr);
  1857.                     _Iter._Adopt(this);
  1858.                     }
  1859.             _Splice_same(_Where, _Right, _First, _Last, _Count);
  1860.             }
  1861.  
  1862.  #else /* _ITERATOR_DEBUG_LEVEL == 2 */
  1863.         if (this->_Getal() == _Right._Getal())
  1864.             _Splice_same(_Where, _Right, _First, _Last, _Count);
  1865.  #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
  1866.  
  1867.         else
  1868.             {   // different allocator, copy nodes then erase source
  1869.             for (const_iterator _Next = _First; _Next != _Last; ++_Next)
  1870.                 insert(_Where, (_Ty&&)*_Next);
  1871.             _Right.erase(_First, _Last);
  1872.             }
  1873.         }
  1874.  
  1875.     void _Splice_same(const_iterator _Where,
  1876.         _Myt& _Right, const_iterator _First, const_iterator _Last,
  1877.         size_type _Count)
  1878.         {   // splice _Right [_First, _Last) before _Where
  1879.         if (this != &_Right)
  1880.             {   // splicing from another list, adjust counts
  1881.             _Incsize(_Count);
  1882.             _Right._Mysize -= _Count;
  1883.             }
  1884.         this->_Nextnode(this->_Prevnode(_First._Mynode())) =
  1885.             _Last._Mynode();
  1886.         this->_Nextnode(this->_Prevnode(_Last._Mynode())) =
  1887.             _Where._Mynode();
  1888.         this->_Nextnode(this->_Prevnode(_Where._Mynode())) =
  1889.             _First._Mynode();
  1890.  
  1891.         _Nodeptr _Pnode = this->_Prevnode(_Where._Mynode());
  1892.         this->_Prevnode(_Where._Mynode()) =
  1893.             this->_Prevnode(_Last._Mynode());
  1894.         this->_Prevnode(_Last._Mynode()) =
  1895.             this->_Prevnode(_First._Mynode());
  1896.         this->_Prevnode(_First._Mynode()) = _Pnode;
  1897.         }
  1898.  
  1899.     void _Unchecked_splice(_Unchecked_const_iterator _Where,
  1900.         _Unchecked_const_iterator _First,
  1901.         _Unchecked_const_iterator _Last)
  1902.         {   // splice [_First, _Last) before _Where
  1903.         this->_Nextnode(this->_Prevnode(_First._Mynode())) =
  1904.             _Last._Mynode();
  1905.         this->_Nextnode(this->_Prevnode(_Last._Mynode())) =
  1906.             _Where._Mynode();
  1907.         this->_Nextnode(this->_Prevnode(_Where._Mynode())) =
  1908.             _First._Mynode();
  1909.  
  1910.         _Nodeptr _Pnode = this->_Prevnode(_Where._Mynode());
  1911.         this->_Prevnode(_Where._Mynode()) =
  1912.             this->_Prevnode(_Last._Mynode());
  1913.         this->_Prevnode(_Last._Mynode()) =
  1914.             this->_Prevnode(_First._Mynode());
  1915.         this->_Prevnode(_First._Mynode()) = _Pnode;
  1916.         }
  1917.  
  1918.     void _Assign_n(size_type _Count, const _Ty& _Val)
  1919.         {   // assign _Count * _Val
  1920.         _Ty _Tmp = _Val;    // in case _Val is in sequence
  1921.         clear();
  1922.         _Insert_n(_Unchecked_begin(), _Count, _Tmp);
  1923.         }
  1924.  
  1925.     void _Tidy()
  1926.         {   // free all storage
  1927.         clear();
  1928.         }
  1929.  
  1930.     void _Insert_n(_Unchecked_const_iterator _Where,
  1931.         size_type _Count, const _Ty& _Val)
  1932.         {   // insert _Count * _Val at _Where
  1933.         size_type _Countsave = _Count;
  1934.  
  1935.         _TRY_BEGIN
  1936.         for (; 0 < _Count; --_Count)
  1937.             _Insert(_Where, _Val);
  1938.         _CATCH_ALL
  1939.         for (; _Count < _Countsave; ++_Count)
  1940.             {   // undo inserts
  1941.             _Unchecked_const_iterator _Before = _Where;
  1942.             _Unchecked_erase(--_Before);
  1943.             }
  1944.         _RERAISE;
  1945.         _CATCH_END
  1946.         }
  1947.  
  1948.     void _Incsize(size_type _Count)
  1949.         {   // alter element count, with checking
  1950.         if (max_size() - this->_Mysize - 1 < _Count)
  1951.             _Xlength_error("list<T> too long");
  1952.         this->_Mysize += _Count;
  1953.         }
  1954.  
  1955.  #if _ITERATOR_DEBUG_LEVEL == 2
  1956.     void _Orphan_ptr(_Myt& _Cont, _Nodeptr _Ptr) const
  1957.         {   // orphan iterators with specified node pointers
  1958.         _Lockit _Lock(_LOCK_DEBUG);
  1959.         const_iterator **_Pnext = (const_iterator **)_Cont._Getpfirst();
  1960.         if (_Pnext != 0)
  1961.             while (*_Pnext != 0)
  1962.                 if ((*_Pnext)->_Ptr == this->_Myhead
  1963.                     || _Ptr != 0 && (*_Pnext)->_Ptr != _Ptr)
  1964.                     _Pnext = (const_iterator **)(*_Pnext)->_Getpnext();
  1965.                 else
  1966.                     {   // orphan the iterator
  1967.                     (*_Pnext)->_Clrcont();
  1968.                     *_Pnext = *(const_iterator **)(*_Pnext)->_Getpnext();
  1969.                     }
  1970.         }
  1971.  #endif /* _ITERATOR_DEBUG_LEVEL == 2 */
  1972.     };
  1973.  
  1974.         // list TEMPLATE OPERATORS
  1975.  
  1976. template<class _Ty,
  1977.     class _Alloc> inline
  1978.     void swap(list<_Ty, _Alloc>& _Left, list<_Ty, _Alloc>& _Right)
  1979.     {   // swap _Left and _Right lists
  1980.     _Left.swap(_Right);
  1981.     }
  1982.  
  1983. template<class _Ty,
  1984.     class _Alloc> inline
  1985.     bool operator==(const list<_Ty, _Alloc>& _Left,
  1986.         const list<_Ty, _Alloc>& _Right)
  1987.     {   // test for list equality
  1988.     return (_Left.size() == _Right.size()
  1989.         && equal(_Left.begin(), _Left.end(), _Right.begin()));
  1990.     }
  1991.  
  1992. template<class _Ty,
  1993.     class _Alloc> inline
  1994.     bool operator!=(const list<_Ty, _Alloc>& _Left,
  1995.         const list<_Ty, _Alloc>& _Right)
  1996.     {   // test for list inequality
  1997.     return (!(_Left == _Right));
  1998.     }
  1999.  
  2000. template<class _Ty,
  2001.     class _Alloc> inline
  2002.     bool operator<(const list<_Ty, _Alloc>& _Left,
  2003.         const list<_Ty, _Alloc>& _Right)
  2004.     {   // test if _Left < _Right for lists
  2005.     return (lexicographical_compare(_Left.begin(), _Left.end(),
  2006.         _Right.begin(), _Right.end()));
  2007.     }
  2008.  
  2009. template<class _Ty,
  2010.     class _Alloc> inline
  2011.     bool operator>(const list<_Ty, _Alloc>& _Left,
  2012.         const list<_Ty, _Alloc>& _Right)
  2013.     {   // test if _Left > _Right for lists
  2014.     return (_Right < _Left);
  2015.     }
  2016.  
  2017. template<class _Ty,
  2018.     class _Alloc> inline
  2019.     bool operator<=(const list<_Ty, _Alloc>& _Left,
  2020.         const list<_Ty, _Alloc>& _Right)
  2021.     {   // test if _Left <= _Right for lists
  2022.     return (!(_Right < _Left));
  2023.     }
  2024.  
  2025. template<class _Ty,
  2026.     class _Alloc> inline
  2027.     bool operator>=(const list<_Ty, _Alloc>& _Left,
  2028.         const list<_Ty, _Alloc>& _Right)
  2029.     {   // test if _Left >= _Right for lists
  2030.     return (!(_Left < _Right));
  2031.     }
  2032. _STD_END
  2033.  #pragma pop_macro("new")
  2034.  #pragma warning(pop)
  2035.  #pragma pack(pop)
  2036. #endif /* RC_INVOKED */
  2037. #endif /* _LIST_ */
  2038.  
  2039. /*
  2040.  * This file is derived from software bearing the following
  2041.  * restrictions:
  2042.  *
  2043.  * Copyright (c) 1994
  2044.  * Hewlett-Packard Company
  2045.  *
  2046.  * Permission to use, copy, modify, distribute and sell this
  2047.  * software and its documentation for any purpose is hereby
  2048.  * granted without fee, provided that the above copyright notice
  2049.  * appear in all copies and that both that copyright notice and
  2050.  * this permission notice appear in supporting documentation.
  2051.  * Hewlett-Packard Company makes no representations about the
  2052.  * suitability of this software for any purpose. It is provided
  2053.  * "as is" without express or implied warranty.
  2054.  */
  2055.  
  2056. /*
  2057.  * Copyright (c) 1992-2012 by P.J. Plauger.  ALL RIGHTS RESERVED.
  2058.  * Consult your license regarding permissions and restrictions.
  2059. V6.00:0009 */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement