home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / deque.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  24.4 KB  |  777 lines

  1. #ifndef __DEQUE_H
  2. #define __DEQUE_H
  3. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  4. // -*- C++ -*-
  5. /***************************************************************************
  6.  *
  7.  * deque - Declaration and definition for the Standard Library deque class
  8.  *
  9.  ***************************************************************************
  10.  *
  11.  * Copyright (c) 1994
  12.  * Hewlett-Packard Company
  13.  *
  14.  * Permission to use, copy, modify, distribute and sell this software
  15.  * and its documentation for any purpose is hereby granted without fee,
  16.  * provided that the above copyright notice appear in all copies and
  17.  * that both that copyright notice and this permission notice appear
  18.  * in supporting documentation.  Hewlett-Packard Company makes no
  19.  * representations about the suitability of this software for any
  20.  * purpose.  It is provided "as is" without express or implied warranty.
  21.  *
  22.  *
  23.  ***************************************************************************
  24.  *
  25.  * Copyright (c) 1994-1999 Rogue Wave Software, Inc.  All Rights Reserved.
  26.  *
  27.  * This computer software is owned by Rogue Wave Software, Inc. and is
  28.  * protected by U.S. copyright laws and other laws and by international
  29.  * treaties.  This computer software is furnished by Rogue Wave Software,
  30.  * Inc. pursuant to a written license agreement and may be used, copied,
  31.  * transmitted, and stored only in accordance with the terms of such
  32.  * license and with the inclusion of the above copyright notice.  This
  33.  * computer software or any other copies thereof may not be provided or
  34.  * otherwise made available to any other person.
  35.  *
  36.  * U.S. Government Restricted Rights.  This computer software is provided
  37.  * with Restricted Rights.  Use, duplication, or disclosure by the
  38.  * Government is subject to restrictions as set forth in subparagraph (c)
  39.  * (1) (ii) of The Rights in Technical Data and Computer Software clause
  40.  * at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the
  41.  * Commercial Computer Software รป Restricted Rights at 48 CFR 52.227-19,
  42.  * as applicable.  Manufacturer is Rogue Wave Software, Inc., 5500
  43.  * Flatiron Parkway, Boulder, Colorado 80301 USA.
  44.  *
  45.  **************************************************************************/
  46.  
  47. #ifndef __STD_DEQUE__
  48. #define __STD_DEQUE__
  49.  
  50. #include <rw/stddefs.h> 
  51. #include <rw/rwdispatch.h> 
  52.  
  53. #include <stdcomp.h>
  54. #include <algorithm>
  55. #include <iterator>
  56. #include <memory>
  57. #include <stdexcept>
  58.  
  59. #ifndef deque 
  60. #define deque deque
  61. #endif
  62.  
  63. #ifndef _RWSTD_NO_NAMESPACE
  64. namespace std {
  65. #endif
  66.  
  67. //
  68. // Note that _RWSTD_COMPLEX_DEFAULT(x)
  69. // will expand to: ' = x', or nothing,
  70. // depending on your compiler's capabilities and/or
  71. // flag settings (see stdcomp.h).
  72. //
  73.   template <class T, class Allocator _RWSTD_COMPLEX_DEFAULT(allocator<T>) >
  74.   class  deque
  75.   {
  76.   protected:
  77. #ifdef _RWSTD_ALLOCATOR
  78.     typedef _TYPENAME Allocator::template rebind<T>::other __value_alloc_type;
  79. #else
  80.     typedef allocator_interface<Allocator,T>    __value_alloc_type;
  81. #endif
  82.  
  83.   public:
  84.  
  85.     //
  86.     // Types.
  87.     //
  88.     class  iterator;
  89.     class  const_iterator;
  90.     friend class iterator;
  91.     friend class const_iterator;
  92.     typedef T                                          value_type;
  93.     typedef Allocator                                  allocator_type;
  94.  
  95. #ifndef _RWSTD_NO_COMPLICATED_TYPEDEF
  96.     typedef _TYPENAME _RWSTD_ALLOC_SIZE_TYPE              size_type;
  97.     typedef _TYPENAME _RWSTD_ALLOC_DIFF_TYPE              difference_type;
  98.     typedef _TYPENAME __value_alloc_type::reference       reference;
  99.     typedef _TYPENAME __value_alloc_type::const_reference const_reference;
  100.     typedef _TYPENAME __value_alloc_type::pointer         pointer;
  101.     typedef _TYPENAME __value_alloc_type::const_pointer   const_pointer;
  102. #else
  103.     typedef size_t            size_type;
  104.     typedef ptrdiff_t         difference_type;
  105.     typedef T&                reference;
  106.     typedef const T&          const_reference;
  107.     typedef T*                pointer;
  108.     typedef const T*          const_pointer;
  109. #endif  //_RWSTD_NO_COMPLICATED_TYPEDEF
  110.  
  111.   protected:
  112. #ifdef _RWSTD_ALLOCATOR
  113.     typedef _TYPENAME Allocator::template rebind<pointer>::other __map_alloc_type;
  114. #else
  115.     typedef allocator_interface<allocator_type,pointer> __map_alloc_type;
  116. #endif
  117.     typedef _TYPENAME __map_alloc_type::pointer         __map_pointer;
  118.  
  119.     static size_type __buffer_size ();
  120.  
  121.     typedef _RW_STD::iterator<random_access_iterator_tag, value_type,
  122.                     difference_type, pointer,reference> __it;
  123.     typedef _RW_STD::iterator<random_access_iterator_tag, value_type, 
  124.                     difference_type, const_pointer, const_reference> __cit;
  125.  
  126.   public:
  127.     //
  128.     // Definition of our iterator.
  129.     //
  130.     class iterator : public __it
  131.     {
  132.       friend class deque<T,Allocator>;
  133.       friend class const_iterator;
  134.  
  135.     protected:
  136.  
  137.       pointer     current;
  138.       pointer     first;
  139.       pointer     last;
  140.       __map_pointer node;
  141.  
  142.       iterator (pointer x, __map_pointer y)
  143.         : current(x), first(*y), last(*y + __buffer_size()), node(y) {}
  144.  
  145.     public:
  146.  
  147.       iterator () : current(0), first(0), last(0), node(0) {}
  148.       iterator (const iterator& x) 
  149.         : current(x.current), first(x.first), 
  150.           last(x.last), node(x.node) {}     
  151.       reference operator* () const { return *current; }
  152. #ifndef _RWSTD_NO_NONCLASS_ARROW_RETURN
  153.       pointer operator-> () const { return current; }
  154. #endif
  155. #ifdef _HPACC_
  156.       void operator= (const iterator& x)
  157.       {
  158.     current = x.current;
  159.     first = x.first;
  160.     last = x.last;
  161.     node = x.node;
  162.       }
  163. #endif
  164.       difference_type operator- (const iterator& x) const
  165.       {
  166.         return node == x.node 
  167.         ? current - x.current 
  168.         : difference_type(__buffer_size() * (node - x.node - 1) +
  169.                           (current - first) + (x.last - x.current));
  170.       }
  171.       iterator& operator++ ()
  172.       {
  173.         if (++current == last)
  174.         {
  175.           first = *(++node);
  176.           current = first;
  177.           last = first + __buffer_size();
  178.         }
  179.         return *this; 
  180.       }
  181.       iterator operator++ (int)
  182.       {
  183.         iterator tmp = *this; ++*this; return tmp;
  184.       }
  185.       iterator& operator-- ()
  186.       {
  187.         if (current == first)
  188.         {
  189.           first = *(--node);
  190.           last = first + __buffer_size();
  191.           current = last;
  192.         }
  193.         --current;
  194.         return *this;
  195.       }
  196.       iterator operator-- (int)
  197.       {
  198.         iterator tmp = *this; --*this; return tmp;
  199.       }
  200.       iterator& operator+= (difference_type n)
  201.       {
  202.         difference_type offset = n + (current - first);
  203.         difference_type num_node_to_jump = offset >= 0
  204.         ? offset / __buffer_size()
  205.         : -(difference_type)((-offset + __buffer_size() - 1) / __buffer_size());
  206.         if (num_node_to_jump == 0)
  207.           current += n;
  208.         else
  209.         {
  210.           node = node + num_node_to_jump;
  211.           first = *node;
  212.           last = first + __buffer_size();
  213.           current = first + (offset - num_node_to_jump * __buffer_size());
  214.         }
  215.         return *this;
  216.       }
  217.       iterator& operator-= (difference_type n) { return *this += -n; }
  218.       iterator operator+ (difference_type n) const
  219.       {
  220.         iterator tmp = *this; return tmp += n;
  221.       }
  222.       iterator operator- (difference_type n) const
  223.       {
  224.         iterator tmp = *this; return tmp -= n;
  225.       }
  226.       reference operator[] (difference_type n) { return *(*this + n); }
  227.       bool operator== (const iterator& x) const
  228.       {
  229.         return current == x.current || 
  230.         ((current == first || x.current == x.first) && 
  231.          *this - x == 0);
  232.       }
  233.       bool operator!= (const iterator& x) const { return !(*this == x); } 
  234.       bool operator< (const iterator& x) const
  235.       {
  236.         return (node == x.node) ? (current < x.current) : (node < x.node);
  237.       } 
  238.       bool operator> (const iterator& x) const
  239.       {
  240.         return x < *this;
  241.       }
  242.       bool operator>= (const iterator& x) const
  243.       {
  244.         return !(*this < x);
  245.       }
  246.       bool operator<= (const iterator& x) const
  247.       {
  248.         return !(*this > x);
  249.       }
  250.     };  // End of nested definiton of iterator.
  251.  
  252.     //
  253.     // Definition of our constant iterator.
  254.     //
  255.     class const_iterator  : public __cit
  256.     {
  257.       friend class deque<T,Allocator>;
  258.  
  259.     protected:
  260.  
  261.       pointer     current;
  262.       pointer     first;
  263.       pointer     last;
  264.       __map_pointer node;
  265.  
  266.       const_iterator (pointer x, __map_pointer y) 
  267.         : current(x), first(*y), last(*y + __buffer_size()), node(y) {}
  268.  
  269.     public:
  270.        
  271.       const_iterator () : current(0), first(0), last(0), node(0) {}
  272. #if !defined(_MSC_VER) || defined(__BORLANDC__)
  273.       const_iterator (const _TYPENAME deque<T,Allocator>::iterator& x) 
  274. #else
  275.       const_iterator (const iterator& x) 
  276. #endif
  277.         : current(x.current), first(x.first), last(x.last), node(x.node) {}     
  278.       const_reference operator* () const { return *current; }
  279. #ifndef _RWSTD_NO_NONCLASS_ARROW_RETURN
  280.       const_pointer operator-> () const { return current; }
  281. #endif
  282.       difference_type operator- (const const_iterator& x) const
  283.       {
  284.         return node == x.node 
  285.         ? current - x.current 
  286.         : difference_type(__buffer_size() * (node - x.node - 1) +
  287.                           (current - first) + (x.last - x.current));
  288.       }
  289.       const_iterator& operator++ ()
  290.       {
  291.         if (++current == last)
  292.         {
  293.           first = *(++node);
  294.           current = first;
  295.           last = first + __buffer_size();
  296.         }
  297.         return *this; 
  298.       }
  299.       const_iterator operator++ (int)
  300.       {
  301.         const_iterator tmp = *this; ++*this; return tmp;
  302.       }
  303.       const_iterator& operator-- ()
  304.       {
  305.         if (current == first)
  306.         {
  307.           first = *(--node);
  308.           last = first + __buffer_size();
  309.           current = last;
  310.         }
  311.         --current;
  312.         return *this;
  313.       }
  314.       const_iterator operator-- (int)
  315.       {
  316.         const_iterator tmp = *this; --*this; return tmp;
  317.       }
  318.       const_iterator& operator+= (difference_type n)
  319.       {
  320.         difference_type offset = n + (current - first);
  321.         difference_type num_node_to_jump = offset >= 0
  322.         ? offset / __buffer_size()
  323.         : -(difference_type)((-offset + __buffer_size() - 1) / __buffer_size());
  324.         if (num_node_to_jump == 0)
  325.           current += n;
  326.         else
  327.         {
  328.           node = node + num_node_to_jump;
  329.           first = *node;
  330.           last = first + __buffer_size();
  331.           current = first + (offset - num_node_to_jump * __buffer_size());
  332.         }
  333.         return *this;
  334.       }
  335.       const_iterator& operator-= (difference_type n) { return *this += -n; }
  336.       const_iterator operator+ (difference_type n) const
  337.       {
  338.         const_iterator tmp = *this; return tmp += n;
  339.       }
  340.       const_iterator operator- (difference_type n) const
  341.       {
  342.         const_iterator tmp = *this; return tmp -= n;
  343.       }
  344.       const_reference operator[] (difference_type n)
  345.       { 
  346.         return *(*this + n); 
  347.       }
  348.       bool operator== (const const_iterator& x) const
  349.       {
  350.         return current == x.current || 
  351.         ((current == first || x.current == x.first) && 
  352.          *this - x == 0);
  353.       }
  354.       bool operator!= (const const_iterator& x) const { return !(*this == x); }
  355.       bool operator< (const const_iterator& x) const
  356.       {
  357.         return (node == x.node) ? (current < x.current) : (node < x.node);
  358.       } 
  359.       bool operator> (const const_iterator& x) const
  360.       {
  361.         return x < *this;
  362.       }
  363.       bool operator>= (const const_iterator& x) const
  364.       {
  365.         return !(*this < x);
  366.       }
  367.       bool operator<= (const const_iterator& x) const
  368.       {
  369.         return !(*this > x);
  370.       }
  371.     };  // End of nested definiton of const_iterator.
  372.  
  373. #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC 
  374.     typedef _RW_STD::reverse_iterator<const_iterator> const_reverse_iterator;
  375.     typedef _RW_STD::reverse_iterator<iterator>  reverse_iterator;
  376. #else
  377.     typedef _RW_STD::reverse_iterator<const_iterator, 
  378.       random_access_iterator_tag, value_type, 
  379.       const_reference, const_pointer, difference_type>
  380.       const_reverse_iterator;
  381.     typedef _RW_STD::reverse_iterator<iterator, 
  382.       random_access_iterator_tag, value_type,
  383.       reference, pointer, difference_type>
  384.       reverse_iterator;
  385. #endif
  386.  
  387.   protected:
  388.  
  389.     iterator      __start;
  390.     iterator      __finish;
  391.     size_type     __length;
  392.     __map_pointer __map;
  393.     __RWSTD::__rw_basis<size_type,allocator_type>     __map_size;
  394.  
  395.     void __allocate_at_begin   ();    
  396.     void __allocate_at_end     ();
  397.     void __deallocate_at_begin ();
  398.     void __deallocate_at_end   ();
  399.     void __insert_aux (iterator position, size_type n, const T& x);
  400. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  401.     template<class InputIterator>
  402.     void __insert_aux (iterator position, InputIterator first, InputIterator last, _RW_is_not_integer)
  403.     { __insert_aux2 (position, first, last); }
  404.     template<class InputIterator>
  405.     void __insert_aux (iterator position, InputIterator first, InputIterator last, _RW_is_integer)
  406.     { __insert_aux (position, (size_type)first, last); }
  407.     template<class InputIterator>
  408.     void __insert_aux2 (iterator position, InputIterator first, InputIterator last);
  409. #endif
  410.  
  411.   public:
  412.     //
  413.     // construct/copy/destroy
  414.     //
  415.     _EXPLICIT deque (const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator())) 
  416.       : __start(), __finish(), __length(0), __map(0), __map_size(0,alloc) 
  417.     { ; }
  418.  
  419. #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
  420.     deque (void) 
  421.       : __start(), __finish(), __length(0), __map(0), __map_size(0,Allocator()) 
  422.     { ; }
  423.  
  424.     deque (size_type n, const T& value)
  425.       : __start(), __finish(), __length(0), __map(0), __map_size(0,Allocator()) 
  426.     {
  427.       insert(begin(), n, value);
  428.     }
  429. #endif // _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
  430.  
  431.     _EXPLICIT deque (size_type n)
  432.       : __start(), __finish(), __length(0), __map(0), __map_size(0,Allocator()) 
  433.     {
  434.       insert(begin(), n, T());
  435.     }
  436.  
  437. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  438.  
  439.     template<class InputIterator>
  440.     deque (InputIterator first, InputIterator last, const Allocator& alloc = Allocator())
  441.       : __start(), __finish(), __length(0), __map(0), __map_size(0,alloc) 
  442.     {
  443.       typedef _TYPENAME _RWdispatch<InputIterator>::_RWtype _RWtype;
  444.       __insert_aux(begin(), first, last, _RWtype());
  445.     }
  446.  
  447.     deque (size_type n, const T& value,
  448.            const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  449.             : __start(), __finish(), __length(0), __map(0), __map_size(0,alloc) 
  450.     {
  451.         insert(begin(), n, value);
  452.     }
  453.  
  454. #else
  455.     //
  456.     // Build a deque of size n with each element set to copy of value.
  457.     //
  458.     deque (size_type n, const T& value,
  459.            const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  460.       : __start(), __finish(), __length(0), __map(0), __map_size(0,alloc) 
  461.     {
  462.       insert(begin(), n, value);
  463.     }
  464.     deque (const_iterator first, const_iterator last, const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  465.       : __start(), __finish(), __length(0), __map(0), __map_size(0,alloc) 
  466.     {
  467.       copy(first, last, back_inserter(*this));
  468.     }
  469.     
  470.     deque (const T* first, const T* last, const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  471.       : __start(), __finish(), __length(0), __map(0), __map_size(0,alloc) 
  472.     {
  473.       copy(first, last, back_inserter(*this));
  474.     }
  475.  
  476. #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
  477.     deque (const_iterator first, const_iterator last)
  478.       : __start(), __finish(), __length(0), __map(0), __map_size(0,Allocator()) 
  479.     {
  480.       copy(first, last, back_inserter(*this));
  481.     }
  482.     
  483.     deque (const T* first, const T* last)
  484.       : __start(), __finish(), __length(0), __map(0), __map_size(0,Allocator()) 
  485.     {
  486.       copy(first, last, back_inserter(*this));
  487.     }
  488. #endif // _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
  489. #endif // _RWSTD_NO_MEMBER_TEMPLATES
  490.  
  491.     deque (const deque<T,Allocator>& x)
  492.       : __start(), __finish(), __length(0), __map(0), __map_size(0,x.get_allocator())
  493.     {
  494.       copy(x.begin(), x.end(), back_inserter(*this));
  495.     }
  496.  
  497.     ~deque ();
  498.     deque<T,Allocator>& operator= (const deque<T,Allocator>& x)
  499.     {
  500.       if (!(this == &x))
  501.       {
  502.         if (size() >= x.size()) 
  503.           erase(copy(x.begin(), x.end(), begin()), end());
  504.         else 
  505.           copy(x.begin() + size(), x.end(),
  506.                inserter(*this,copy(x.begin(),x.begin()+size(),begin())));
  507.       }
  508.       return *this;
  509.     }
  510.  
  511. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  512.     template<class InputIterator>
  513.     void assign (InputIterator first, InputIterator last)
  514.     {
  515.         erase(begin(), end());
  516.         typedef _TYPENAME _RWdispatch<InputIterator>::_RWtype _RWtype;
  517.         __insert_aux(begin(), first, last, _RWtype());
  518.     }
  519.     void assign (size_type n, const T& t)
  520.     {
  521.         erase(begin(), end()); insert(begin(), n, t);
  522.     }
  523. #else
  524.     void assign (const_iterator first, const_iterator last)
  525.     {
  526.       erase(begin(), end()); insert(begin(), first, last);
  527.     }
  528.     void assign (const T* first, const T* last)
  529.     {
  530.       erase(begin(), end()); insert(begin(), first, last);
  531.     }
  532.     //
  533.     // Assign n copies of t to this vector.
  534.     //
  535.     void assign (size_type n, const T& t)
  536.     {
  537.       erase(begin(), end()); insert(begin(), n, t);
  538.     }
  539. #endif // _RWSTD_NO_MEMBER_TEMPLATES
  540.  
  541.     allocator_type get_allocator() const
  542.     {
  543.       return (allocator_type)__map_size;
  544.     }
  545.  
  546.     //
  547.     // Iterators.
  548.     //
  549.     iterator         begin  ()       { return __start;  }
  550.     const_iterator   begin  () const { return __start;  }
  551.     iterator         end    ()       { return __finish; }
  552.     const_iterator   end    () const { return __finish; }
  553.     reverse_iterator rbegin ()
  554.     { 
  555.       reverse_iterator tmp(end()); return tmp;
  556.     }
  557.     const_reverse_iterator rbegin () const
  558.     { 
  559.       const_reverse_iterator tmp(end()); return tmp;
  560.     }
  561.     reverse_iterator rend ()
  562.     { 
  563.       reverse_iterator tmp(begin()); return tmp;
  564.     }
  565.     const_reverse_iterator rend () const
  566.     { 
  567.       const_reverse_iterator tmp(begin()); return tmp;
  568.     }
  569.  
  570.     //
  571.     // Capacity.
  572.     //
  573.     bool      empty    () const { return __length == 0; }
  574.     size_type size     () const { return __length; }
  575.     size_type max_size () const 
  576.     { return __value_alloc_type(__map_size).max_size(); }
  577.     void      resize (size_type new_size);
  578.     void      resize (size_type new_size, T value);
  579.     //
  580.     // Element access.
  581.     //
  582.     reference       operator[] (size_type n)
  583.     {
  584. #ifdef _RWSTD_BOUNDS_CHECKING
  585.       _RWSTD_THROW(n >= size(), out_of_range,
  586.         __RWSTD::except_msg_string(__RWSTD::rwse_OutOfRange,
  587.           "deque::operator[](size_t)",n,size()).msgstr());
  588.       return *(begin() + n);
  589. #else
  590.       return *(begin() + n);
  591. #endif
  592.     }
  593.     const_reference operator[] (size_type n) const
  594.     {
  595. #ifdef _RWSTD_BOUNDS_CHECKING
  596.       _RWSTD_THROW(n >= size(), out_of_range,
  597.         __RWSTD::except_msg_string(__RWSTD::rwse_OutOfRange,
  598.           "deque::operator[](size_t) const",n,size()).msgstr());
  599.       return *(begin() + n);
  600. #else
  601.       return *(begin() + n);
  602. #endif
  603.     }
  604.     const_reference at (size_type n) const 
  605.     { 
  606.       _RWSTD_THROW(n >= size(), out_of_range,
  607.         __RWSTD::except_msg_string(__RWSTD::rwse_OutOfRange,
  608.           "deque:: at(size_t) const",n,size()).msgstr());
  609.       return *(begin() + n); 
  610.     }
  611.     reference       at (size_type n)
  612.     { 
  613.       _RWSTD_THROW(n >= size(), out_of_range,
  614.         __RWSTD::except_msg_string(__RWSTD::rwse_OutOfRange,
  615.           "deque:: at(size_t)",n,size()).msgstr());
  616.       return *(begin() + n); 
  617.     }
  618.     reference       front ()                       { return *begin();       }
  619.     const_reference front ()                 const { return *begin();       }
  620.     reference       back ()                        { return *(end() - 1);   }
  621.     const_reference back ()                  const { return *(end() - 1);   }
  622.  
  623.     //
  624.     // Modifiers.
  625.     //
  626.     void push_front (const T& x)
  627.     {
  628.       if (empty() || begin().current == begin().first) 
  629.         __allocate_at_begin();
  630.       __value_alloc_type(__map_size).construct(__start.current-1, x);
  631.       --__start.current;
  632.       ++__length;
  633.     }
  634.     void push_back (const T& x)
  635.     {
  636.       if (empty() || end().current == end().last) 
  637.         __allocate_at_end();
  638.       __value_alloc_type(__map_size).construct(__finish.current, x);
  639.       ++__finish.current;
  640.       ++__length;
  641.     }
  642.  
  643.     //
  644.     // Insert x at position.
  645.     //
  646.     iterator insert (iterator position, const T& x);
  647.  
  648. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  649.     template<class InputIterator>
  650.     void insert (iterator position, InputIterator first, 
  651.                  InputIterator last)
  652.     {
  653.         typedef _TYPENAME _RWdispatch<InputIterator>::_RWtype _RWtype;
  654.         __insert_aux(position, first, last, _RWtype());
  655.     }
  656.     void insert (iterator position, size_type n, const T& value)
  657.     { __insert_aux(position,n,value); }
  658. #else
  659.     void insert (iterator position, size_type n, const T& x)
  660.     { __insert_aux(position,n,x); }
  661.     void insert (iterator position, const T* first, const T* last);
  662.     void insert (iterator position, const_iterator first, const_iterator last);
  663. #endif // _RWSTD_NO_MEMBER_TEMPLATES
  664.  
  665.     void pop_front ()
  666.     {
  667.       iterator tmp = __start;
  668.       ++__start.current;
  669.       --__length; 
  670.       __value_alloc_type(__map_size).destroy(tmp.current);
  671.       if (empty() || begin().current == begin().last) 
  672.         __deallocate_at_begin();
  673.     }
  674.     void pop_back ()
  675.     {
  676.       --__finish.current;
  677.       --__length; 
  678.       __value_alloc_type(__map_size).destroy(__finish.current);
  679.       if (empty() || end().current == end().first) 
  680.         __deallocate_at_end();
  681.     }
  682.     iterator erase (iterator position);
  683.     iterator erase (iterator first, iterator last);    
  684.     void swap (deque<T,Allocator>& x)
  685.     {
  686.       if((allocator_type)__map_size== (allocator_type)x.__map_size)
  687.       {
  688. #ifndef _RWSTD_NO_NAMESPACE
  689.         std::swap(__start,          x.__start);
  690.         std::swap(__finish,         x.__finish);
  691.         std::swap(__length,         x.__length);
  692.         std::swap(__map,            x.__map);
  693.         std::swap(__map_size,       x.__map_size);
  694. #else
  695.         ::swap(__start,             x.__start);
  696.         ::swap(__finish,            x.__finish);
  697.         ::swap(__length,            x.__length);
  698.         ::swap(__map,               x.__map);
  699.         ::swap(__map_size,          x.__map_size);
  700. #endif // _RWSTD_NO_NAMESPACE
  701.       }
  702.       else
  703.       {
  704.         deque<T,Allocator> _x=*this;
  705.         *this=x;
  706.         x=_x;
  707.       }
  708.     }
  709.     void clear()
  710.     {
  711.       erase(begin(),end());
  712.     }
  713.   };
  714.  
  715.   template <class T, class Allocator>
  716.   inline bool operator== (const deque<T,Allocator>& x, const deque<T,Allocator>& y)
  717.   {
  718.     return x.size() == y.size() && equal(x.begin(), x.end(), y.begin());
  719.   }
  720.  
  721.   template <class T, class Allocator>
  722.   inline bool operator< (const deque<T,Allocator>& x, const deque<T,Allocator>& y)
  723.   {
  724.     return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end());
  725.   }
  726.  
  727. #if !defined(_RWSTD_NO_NAMESPACE) || !defined(_RWSTD_NO_PART_SPEC_OVERLOAD)
  728.   template <class T, class Allocator>
  729.   inline bool operator!= (const deque<T,Allocator>& x, const deque<T,Allocator>& y)
  730.   {
  731.     return !(x == y);
  732.   }
  733.  
  734.   template <class T, class Allocator>
  735.   inline bool operator> (const deque<T,Allocator>& x, const deque<T,Allocator>& y)
  736.   {
  737.     return y < x;
  738.   }
  739.  
  740.   template <class T, class Allocator>
  741.   inline bool operator>= (const deque<T,Allocator>& x, const deque<T,Allocator>& y)
  742.   {
  743.     return !(x < y);
  744.   }
  745.  
  746.   template <class T, class Allocator>
  747.   inline bool operator<= (const deque<T,Allocator>& x, const deque<T,Allocator>& y)
  748.   {
  749.     return !(y <  x);
  750.   }
  751.  
  752.   template <class T, class Allocator>
  753.   inline void swap(deque<T,Allocator>& a, deque<T,Allocator>& b)
  754.   {
  755.     a.swap(b);
  756.   }
  757. #endif // !defined(_RWSTD_NO_NAMESPACE) || !defined(_RWSTD_NO_PART_SPEC_OVERLOAD)
  758.  
  759. #ifndef _RWSTD_NO_NAMESPACE
  760. }
  761. #endif
  762.  
  763. #ifdef _RWSTD_NO_TEMPLATE_REPOSITORY
  764. #include <deque.cc>
  765. #endif
  766.  
  767. #undef deque
  768.  
  769. #endif /*__STD_DEQUE__*/
  770.  
  771. #ifndef __USING_STD_NAMES__
  772.   using namespace std;
  773. #endif
  774.  
  775. #pragma option pop
  776. #endif /* __DEQUE_H */
  777.